From 5e2dd5cff1c2a321814c75ccdef8dc2a1f000812 Mon Sep 17 00:00:00 2001 From: Luiz Krol Date: Thu, 16 Jan 2025 09:47:09 -0300 Subject: [PATCH 1/3] m --- remotelog/loki.go | 5 ++++- sipparser/parser.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/remotelog/loki.go b/remotelog/loki.go index df34ba7..5617b60 100644 --- a/remotelog/loki.go +++ b/remotelog/loki.go @@ -136,13 +136,16 @@ func (l *Loki) start(hCh chan *decoder.HEP) { switch { case pkt.SIP != nil && pkt.ProtoType == 1: l.entry.labels["method"] = model.LabelValue(pkt.SIP.CseqMethod) + l.entry.labels["call_id"] = model.LabelValue(pkt.SIP.CallID) + l.entry.labels["from"] = model.LabelValue(pkt.SIP.From.Val) + l.entry.labels["to"] = model.LabelValue(pkt.SIP.To.Val) l.entry.labels["response"] = model.LabelValue(pkt.SIP.FirstMethod) protocol := "" if pkt.Protocol == 6 { protocol = "tcp" } else if pkt.Protocol == 17 { protocol = "udp" - } + } l.entry.labels["protocol"] = model.LabelValue(protocol) case pkt.ProtoType == 100: protocol := "udp" diff --git a/sipparser/parser.go b/sipparser/parser.go index 6ae7318..218c751 100644 --- a/sipparser/parser.go +++ b/sipparser/parser.go @@ -189,7 +189,7 @@ func (s *SipMsg) addHdr(str string) { s.parseVia(s.hdrv) case s.hdr == "From" || s.hdr == "FROM" || s.hdr == "from": s.parseFrom(s.hdrv) - case s.hdr == "Call-ID" || s.hdr == "CALL-ID" || s.hdr == "Call-Id" || s.hdr == "Call-id" || s.hdr == "call-id": + case s.hdr == "Call-ID" || s.hdr == "CALL-ID" || s.hdr == "Call-Id" || s.hdr == "Call-id" || s.hdr == "call-id" || s.hdr == "i": s.CallID = s.hdrv case s.hdr == "CSeq" || s.hdr == "CSEQ" || s.hdr == "Cseq" || s.hdr == "cseq": s.CseqVal = s.hdrv From 7a222c927fae365074eee951a3ab99900e1f14ee Mon Sep 17 00:00:00 2001 From: Luiz Krol Date: Sun, 19 Jan 2025 16:13:03 -0300 Subject: [PATCH 2/3] call_id on rtcp too --- remotelog/loki.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/remotelog/loki.go b/remotelog/loki.go index 5617b60..3195624 100644 --- a/remotelog/loki.go +++ b/remotelog/loki.go @@ -112,6 +112,8 @@ func (l *Loki) start(hCh chan *decoder.HEP) { pktMeta.Reset() + l.entry = entry{model.LabelSet{}, logproto.Entry{Timestamp: curPktTime}} + if pkt.ProtoString == "rtcp" { var document map[string]interface{} err := json.Unmarshal([]byte(pkt.Payload), &document) @@ -120,6 +122,7 @@ func (l *Loki) start(hCh chan *decoder.HEP) { pktMeta.WriteString(pkt.Payload) } else { document["cid"] = pkt.CID + l.entry.labels["call_id"] = model.LabelValue(pkt.CID) documentJson, err := json.Marshal(document) if err != nil { logp.Err("Unable to re-generate rtcp json: %v", err) @@ -131,7 +134,6 @@ func (l *Loki) start(hCh chan *decoder.HEP) { } else { pktMeta.WriteString(pkt.Payload) } - l.entry = entry{model.LabelSet{}, logproto.Entry{Timestamp: curPktTime}} switch { case pkt.SIP != nil && pkt.ProtoType == 1: From 1b66845bfa9b696d4a387664253452fe9f3535da Mon Sep 17 00:00:00 2001 From: Luiz Krol Date: Sun, 19 Jan 2025 16:45:17 -0300 Subject: [PATCH 3/3] Added config options for to, from and call_id labels on loki --- config/config.go | 2 ++ remotelog/loki.go | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 5635ca2..1eef3ba 100644 --- a/config/config.go +++ b/config/config.go @@ -20,6 +20,8 @@ type HeplifyServer struct { LokiBuffer int `default:"100000"` LokiHEPFilter []int `default:"1,5,100"` LokiIPPortLabels bool `default:"false"` + LokiFromToLabels bool `default:"false"` + LokiCallIDLabels bool `default:"false"` LokiAllowOutOfOrder bool `default:"false"` ForceHEPPayload []int `default:""` PromAddr string `default:":9096"` diff --git a/remotelog/loki.go b/remotelog/loki.go index 3195624..1d6be97 100644 --- a/remotelog/loki.go +++ b/remotelog/loki.go @@ -122,8 +122,10 @@ func (l *Loki) start(hCh chan *decoder.HEP) { pktMeta.WriteString(pkt.Payload) } else { document["cid"] = pkt.CID - l.entry.labels["call_id"] = model.LabelValue(pkt.CID) documentJson, err := json.Marshal(document) + if config.Setting.LokiCallIDLabels { + l.entry.labels["call_id"] = model.LabelValue(pkt.CID) + } if err != nil { logp.Err("Unable to re-generate rtcp json: %v", err) pktMeta.WriteString(pkt.Payload) @@ -138,9 +140,6 @@ func (l *Loki) start(hCh chan *decoder.HEP) { switch { case pkt.SIP != nil && pkt.ProtoType == 1: l.entry.labels["method"] = model.LabelValue(pkt.SIP.CseqMethod) - l.entry.labels["call_id"] = model.LabelValue(pkt.SIP.CallID) - l.entry.labels["from"] = model.LabelValue(pkt.SIP.From.Val) - l.entry.labels["to"] = model.LabelValue(pkt.SIP.To.Val) l.entry.labels["response"] = model.LabelValue(pkt.SIP.FirstMethod) protocol := "" if pkt.Protocol == 6 { @@ -149,6 +148,13 @@ func (l *Loki) start(hCh chan *decoder.HEP) { protocol = "udp" } l.entry.labels["protocol"] = model.LabelValue(protocol) + if config.Setting.LokiCallIDLabels { + l.entry.labels["call_id"] = model.LabelValue(pkt.SIP.CallID) + } + if config.Setting.LokiFromToLabels { + l.entry.labels["from"] = model.LabelValue(pkt.SIP.From.Val) + l.entry.labels["to"] = model.LabelValue(pkt.SIP.To.Val) + } case pkt.ProtoType == 100: protocol := "udp" if strings.Contains(pkt.Payload, "Fax") || strings.Contains(pkt.Payload, "T38") {