Skip to content

Commit 919aabd

Browse files
authored
Merge pull request #562 from htmluz/master
Adding call_id, from and to labels to loki logs
2 parents 76eb19b + dc551ef commit 919aabd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type HeplifyServer struct {
2020
LokiBuffer int `default:"100000"`
2121
LokiHEPFilter []int `default:"1,5,100"`
2222
LokiIPPortLabels bool `default:"false"`
23+
LokiFromToLabels bool `default:"false"`
24+
LokiCallIDLabels bool `default:"false"`
2325
LokiAllowOutOfOrder bool `default:"false"`
2426
LineprotoURL string `default:""`
2527
LineprotoBulk int `default:"400"`

remotelog/loki.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
112112

113113
pktMeta.Reset()
114114

115+
l.entry = entry{model.LabelSet{}, logproto.Entry{Timestamp: curPktTime}}
116+
115117
if pkt.ProtoString == "rtcp" {
116118
var document map[string]interface{}
117119
err := json.Unmarshal([]byte(pkt.Payload), &document)
@@ -121,6 +123,9 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
121123
} else {
122124
document["cid"] = pkt.CID
123125
documentJson, err := json.Marshal(document)
126+
if config.Setting.LokiCallIDLabels {
127+
l.entry.labels["call_id"] = model.LabelValue(pkt.CID)
128+
}
124129
if err != nil {
125130
logp.Err("Unable to re-generate rtcp json: %v", err)
126131
pktMeta.WriteString(pkt.Payload)
@@ -131,7 +136,6 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
131136
} else {
132137
pktMeta.WriteString(pkt.Payload)
133138
}
134-
l.entry = entry{model.LabelSet{}, logproto.Entry{Timestamp: curPktTime}}
135139

136140
switch {
137141
case pkt.SIP != nil && pkt.ProtoType == 1:
@@ -142,8 +146,15 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
142146
protocol = "tcp"
143147
} else if pkt.Protocol == 17 {
144148
protocol = "udp"
145-
}
149+
}
146150
l.entry.labels["protocol"] = model.LabelValue(protocol)
151+
if config.Setting.LokiCallIDLabels {
152+
l.entry.labels["call_id"] = model.LabelValue(pkt.SIP.CallID)
153+
}
154+
if config.Setting.LokiFromToLabels {
155+
l.entry.labels["from"] = model.LabelValue(pkt.SIP.From.Val)
156+
l.entry.labels["to"] = model.LabelValue(pkt.SIP.To.Val)
157+
}
147158
case pkt.ProtoType == 100:
148159
protocol := "udp"
149160
if strings.Contains(pkt.Payload, "Fax") || strings.Contains(pkt.Payload, "T38") {

sipparser/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (s *SipMsg) addHdr(str string) {
189189
s.parseVia(s.hdrv)
190190
case s.hdr == "From" || s.hdr == "FROM" || s.hdr == "from":
191191
s.parseFrom(s.hdrv)
192-
case s.hdr == "Call-ID" || s.hdr == "CALL-ID" || s.hdr == "Call-Id" || s.hdr == "Call-id" || s.hdr == "call-id":
192+
case s.hdr == "Call-ID" || s.hdr == "CALL-ID" || s.hdr == "Call-Id" || s.hdr == "Call-id" || s.hdr == "call-id" || s.hdr == "i":
193193
s.CallID = s.hdrv
194194
case s.hdr == "CSeq" || s.hdr == "CSEQ" || s.hdr == "Cseq" || s.hdr == "cseq":
195195
s.CseqVal = s.hdrv

0 commit comments

Comments
 (0)