toni-moreno / snmpcollector

A full featured Generic SNMP data collector with Web Administration Interface for InfluxDB
MIT License
288 stars 53 forks source link

MAC format problem? #463

Closed robitmoh closed 3 years ago

robitmoh commented 3 years ago

I'm not have problem with index1 bit index0 is not good the snmpwalk res:


.1.3.6.1.2.1.10.127.1.3.3.1.2.87 = STRING: bc:c8:10:f3:a3:d1
.1.3.6.1.2.1.10.127.1.3.3.1.2.88 = STRING: 24:76:7d:4c:a7:24
.1.3.6.1.2.1.10.127.1.3.3.1.2.89 = STRING: 60:2a:d0:40:42:1a

the problem the index0 value is wrong format in influxdb I think is a convert problem from hwdata format to string

show tag values from cmts with key="cm";
name: cmts
key value
--- -----
cm  %.4�-
cm  %.4��
cm  %.9Z'
cm  %.PK�
cm  Y3;��
cm  Y3ty�
cm  Y3vr$
sbengo commented 3 years ago

Hi @robitmoh , thanks for submitting this

When we create the measurement tagvalue, we support the following types, according to gosnmp

https://github.com/toni-moreno/snmpcollector/blob/17ec957d5ab98b5ec5474d304a7312dfd0fc72f6/pkg/data/measurement/measurement.go#L802-L818

If I'm not wrong, the MAC address is returned as an OctetString, so the measurement is retrieving its value without any conversion, and, furthermore, we have no clue if its a MAC or not.

Actually, we support parsing a provided MAC, but only on metrics, with DataSrcType: HWADDRESS. Remember that you can check the field IsTag to send the metric as a Tag

So:

If you can't achieve your desired behaviour, it can be done defining as new type on Index Format Tag. We currently support STRING (default) or DEC2ASCII transformators.

Thanks, Regards!

robitmoh commented 3 years ago

Hi @sbengo yes te MAC is returned in OctetString but can't simple converted to string in python I can convert like this EUI(hexlify(value.val).decode('UTF-8'), dialect=mac_unix_expanded) (https://netaddr.readthedocs.io/en/latest/tutorial_02.html) I don't know how is in go I think the multi index is needed Expl: cable modem SNR in headend SNMPv2-SMI::enterprises.4491.2.1.20.1.4.1.4.1.721465 = INTEGER: 381 baseoid SNMPv2-SMI::enterprises.4491.2.1.20.1.4.1.4.[cable modem id].[upstream id] = INTEGER: 381

to identify the cable modem cablemodem id: (measurement index0) DOCS-IF-MIB::docsIfCmtsCmStatusMacAddress.[ 1 ] = STRING: 24:76:7d:48:30:0

the upstream frequency: (measurement index1) DOCS-IF-MIB::docsIfUpChannelFrequency.721465 = INTEGER: 42600000 hertz

the MAC address tag is require because this is a one identify glue with headend - cablemodem - management system

Thanks your help! Regards!

robitmoh commented 3 years ago

Hi @sbengo

I made a small patch (hope in january I can take a pull request )

git diff formatindextag.go
diff --git a/pkg/data/measurement/formatindextag.go b/pkg/data/measurement/formatindextag.go
index cd470a0..fb3f199 100644
--- a/pkg/data/measurement/formatindextag.go
+++ b/pkg/data/measurement/formatindextag.go
@@ -5,6 +5,7 @@ import (
        "regexp"
        "strconv"
        "strings"
+       "net"

        "github.com/sirupsen/logrus"
 )
@@ -195,6 +196,9 @@ func formatTag(l *logrus.Logger, format string, data map[string]string, def stri
                        switch {
                        case transformation == "STRING":
                                decoded = section
+                       case transformation == "MAC":
+                               decoded = net.HardwareAddr(section).String()
+                               l.Debugf("FormatTag[%s]: MAC : value %s : Decoded %s", format, v, decoded)
                        case strings.HasPrefix(transformation, "DEC2ASCII"):
                                decoded = formatDec2ASCII(section)
                                l.Debugf("FormatTag[%s]: DEC2ASCII : value %s : Decoded %s", format, v, decoded)

Usage: in the measurement index: The Index Tag Format :${VAL1|DOT[0:]|MAC}