From: Vincent Bernat Date: Wed, 2 Dec 2015 09:55:39 +0000 (+0100) Subject: snmp: accept to use IpAddress for instances X-Git-Tag: collectd-5.6.0~532^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8376bd27d4e094f62f54f046314b27a76d5af23d;p=collectd.git 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 --- 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;