From c99b288ae66e97ae59ac65c82d98c42d7b63c355 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sun, 16 Mar 2008 14:55:46 +0000 Subject: Use GETNEXT for table queries in the rrdbot-get tool --- tools/rrdbot-get.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tools/rrdbot-get.c b/tools/rrdbot-get.c index 6cbc687..e6f52c5 100644 --- a/tools/rrdbot-get.c +++ b/tools/rrdbot-get.c @@ -312,30 +312,35 @@ process_query (void) memset (&value, 0, sizeof (value)); memset (&match, 0, sizeof (match)); - /* Loop looking for the value */ - for (sub = 0; ; ++sub) { + /* Build up the query OID we're going for */ + memcpy (&value.var, &ctx.query_oid, sizeof (value.var)); + ASSERT (value.var.len < ASN_MAXOIDLEN); - /* Build up the query OID we're going for */ - memcpy (&value.var, &ctx.query_oid, sizeof (value.var)); - ASSERT (value.var.len < ASN_MAXOIDLEN); - value.var.subs[value.var.len] = sub; - value.var.len++; + /* Loop looking for the value */ + for (;;) { /* Do the request */ ret = snmp_engine_sync (ctx.host, ctx.community, ctx.version, - 0, ctx.timeout, SNMP_PDU_GET, &value); + 0, ctx.timeout, SNMP_PDU_GETNEXT, &value); - /* Try and see if its not zero based */ - if (ret == SNMP_ERR_NOSUCHNAME && sub == 0) - continue; + /* Convert these result codes into 'not found' */ + if (ret == SNMP_ERR_NOERROR) { + switch (value.syntax) { + case SNMP_SYNTAX_NOSUCHOBJECT: + case SNMP_SYNTAX_NOSUCHINSTANCE: + case SNMP_SYNTAX_ENDOFMIBVIEW: + ret = SNMP_ERR_NOSUCHNAME; + break; + default: + break; + } + } if (ret != SNMP_ERR_NOERROR) { had_failure (ret); return; } - matched = 0; - /* Match the results */ if (ctx.query_match) matched = snmp_engine_match (&value, ctx.query_match); @@ -344,12 +349,14 @@ process_query (void) else matched = 1; - snmp_value_clear (&value); - if (matched) break; } + /* The last one is the table index */ + sub = value.var.subs[value.var.len]; + + /* Build up the field OID */ memcpy (&value.var, &ctx.request_oid, sizeof (value.var)); ASSERT (value.var.len < ASN_MAXOIDLEN); value.var.subs[value.var.len] = sub; -- cgit v1.2.3