From 8376bd27d4e094f62f54f046314b27a76d5af23d Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 2 Dec 2015 10:55:39 +0100 Subject: [PATCH] snmp: accept to use IpAddress for instances Some interesting MIB are indexed with an IP address (for example, BGP4-MIB). Make collectd able to use those indexes as instances. Format the IP as string. IPv6 are usually encoded as Octet String, so, they should be already supported. Signed-off-by: Vincent Bernat --- src/snmp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/snmp.c b/src/snmp.c index 9f4714d3..23aefd51 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -1106,6 +1106,14 @@ static int csnmp_strvbcopy (char *dst, /* {{{ */ src = (char *) vb->val.string; else if (vb->type == ASN_BIT_STR) src = (char *) vb->val.bitstring; + else if (vb->type == ASN_IPADDRESS) + { + return ssnprintf (dst, dst_size, "%d.%d.%d.%d", + (uint8_t)vb->val.string[0], + (uint8_t)vb->val.string[1], + (uint8_t)vb->val.string[2], + (uint8_t)vb->val.string[3]); + } else { dst[0] = 0; @@ -1171,7 +1179,7 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, } /* Get instance name */ - if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR)) + if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR) || (vb->type == ASN_IPADDRESS)) { char *ptr; -- 2.30.2