summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--daemon/config.c4
-rw-r--r--mib/mib-parser.c50
-rw-r--r--mib/mib-parser.h9
-rw-r--r--tools/rrdbot-get.c13
4 files changed, 57 insertions, 19 deletions
diff --git a/daemon/config.c b/daemon/config.c
index d95de8a..89ac6f9 100644
--- a/daemon/config.c
+++ b/daemon/config.c
@@ -260,7 +260,9 @@ parse_item(const char* field, char* uri, config_ctx *ctx)
ritem->vtype = VALUE_UNSET;
/* And parse the OID */
- if(mib_parse(path, &(ritem->snmpfield)) == -1)
+ ritem->snmpfield.syntax = SNMP_SYNTAX_NULL;
+ memset(&(ritem->snmpfield.v), 0, sizeof(ritem->snmpfield.v));
+ if(mib_parse(path, &(ritem->snmpfield.var)) == -1)
errx(2, "%s: invalid MIB: %s", ctx->confname, path);
rb_messagex(LOG_DEBUG, "parsed MIB into oid: %s -> %s", path,
diff --git a/mib/mib-parser.c b/mib/mib-parser.c
index f4b8c9d..7d17973 100644
--- a/mib/mib-parser.c
+++ b/mib/mib-parser.c
@@ -141,6 +141,17 @@ snmp_log_perror(const char* file)
#define SNMP_FREE(s) do { if (s) { free((void *)s); s=NULL; } } while(0)
/* -----------------------------------------------------------------------------
+ * PRIVATE DECLARATIONS
+ */
+
+typedef void* mib_node;
+
+mib_node mib_lookup(const char* match);
+int mib_subid(mib_node n, const char* name);
+void mib_oid(mib_node n, struct asn_oid* oid);
+mib_node mib_get_node(struct asn_oid* oid);
+
+/* -----------------------------------------------------------------------------
* RRDBOT GLUE CODE
*/
@@ -343,14 +354,11 @@ parse_mixed_mib(const char* mib, struct asn_oid* oid)
}
int
-mib_parse(const char* mib, struct snmp_value* value)
+mib_parse(const char* mib, struct asn_oid* oid)
{
int ret;
mib_node n;
- value->syntax = SNMP_SYNTAX_NULL;
- memset(&(value->v), 0, sizeof(value->v));
-
/* An initial dot */
if(*mib == '.')
mib++;
@@ -362,7 +370,7 @@ mib_parse(const char* mib, struct snmp_value* value)
* necessary
*/
- ret = parse_mixed_mib(mib, &(value->var));
+ ret = parse_mixed_mib(mib, oid);
/* Next try a symolic search */
if(ret == -1)
@@ -373,9 +381,39 @@ mib_parse(const char* mib, struct snmp_value* value)
if(n == NULL)
return -1;
- mib_oid(n, &(value->var));
+ mib_oid(n, oid);
return 0;
}
return ret;
}
+
+int
+mib_format(struct asn_oid* oid, FILE* f)
+{
+ extern struct tree *tree_head;
+ struct tree *tp = NULL;
+ asn_subid_t subid;
+ int i;
+
+ mib_init();
+
+ for(i = 0, tp = tree_head; tp && i < oid->len;
+ i++, tp = tp ? tp->child_list : NULL)
+ {
+ subid = oid->subs[i];
+
+ while(tp && tp->subid != subid)
+ tp = tp->next_peer;
+
+ if(!tp)
+ break;
+
+ fprintf(f, ".%s", tp->label);
+ }
+
+ for( ; i < oid->len; i++)
+ fprintf(f, ".%d", (int)(oid->subs[i]));
+
+ return 0;
+}
diff --git a/mib/mib-parser.h b/mib/mib-parser.h
index 0c4fc61..4f86ee2 100644
--- a/mib/mib-parser.h
+++ b/mib/mib-parser.h
@@ -49,15 +49,10 @@
extern const char* mib_directory;
extern int mib_warnings;
-typedef void* mib_node;
-
void mib_init();
-mib_node mib_lookup(const char* match);
-int mib_subid(mib_node n, const char* name);
-void mib_oid(mib_node n, struct asn_oid* oid);
-mib_node mib_get_node(struct asn_oid* oid);
void mib_uninit();
-int mib_parse(const char* oid, struct snmp_value* value);
+int mib_parse(const char* mib, struct asn_oid* oid);
+int mib_format(struct asn_oid* oid, FILE* f);
#endif /* __MIB_PARSER_H__ */
diff --git a/tools/rrdbot-get.c b/tools/rrdbot-get.c
index 3abdc77..a6cc0bc 100644
--- a/tools/rrdbot-get.c
+++ b/tools/rrdbot-get.c
@@ -68,8 +68,8 @@ static char* snmp_hostname = NULL;
static int retries = 0;
-/* Whether we're going recursive or not */
-static int recursive = 0;
+static int recursive = 0; /* Whether we're going recursive or not */
+static int numeric = 0; /* Print raw data */
/* -----------------------------------------------------------------------------
* DUMMY CONFIG FUNCTIONS
@@ -149,7 +149,8 @@ setup_req(char* uri)
/* And parse the OID */
snmp_data.bindings[0].syntax = 0;
- if(mib_parse(path, &(snmp_data.bindings[0])) == -1)
+ memset(&(snmp_data.bindings[0].v), 0, sizeof(snmp_data.bindings[0].v));
+ if(mib_parse(path, &(snmp_data.bindings[0].var)) == -1)
errx(2, "invalid MIB: %s", path);
/* Add an item to this request */
@@ -186,7 +187,10 @@ print_resp(struct snmp_pdu* pdu, uint64_t when)
{
value = &(pdu->bindings[i]);
- printf("%s: ", asn_oid2str(&(value->var)));
+ if(numeric)
+ printf("%s: ", asn_oid2str(&(value->var)));
+ else
+ mib_format(&(value->var), stdout);
switch(value->syntax)
{
@@ -334,7 +338,6 @@ int
main(int argc, char* argv[])
{
struct sockaddr_in addr;
- int numeric = 0;
char ch;
/* Parse the arguments nicely */