summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--mib/mib-parser.c51
-rw-r--r--mib/mib-parser.h2
-rw-r--r--tools/rrdbot-get.c6
4 files changed, 54 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index a6b60ca..d7e4ea6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+0.9.3 [2009-01-16]
+ - Add support for printing out MIB name in rrdbot-get
+
0.9.2 [2008-09-25]
- Add parameter to specify bind address.
diff --git a/mib/mib-parser.c b/mib/mib-parser.c
index ffdb151..dcc755b 100644
--- a/mib/mib-parser.c
+++ b/mib/mib-parser.c
@@ -380,15 +380,55 @@ mib_parse(const char* mib, struct asn_oid* oid)
}
int
-mib_format(struct asn_oid* oid, FILE* f)
+mib_format(struct asn_oid* oid, FILE* f, int verbose)
{
+ extern struct module *module_head;
extern struct tree *tree_head;
+ struct module *mp = NULL;
struct tree *tp = NULL;
asn_subid_t subid;
- int i;
+ int module;
+ int i, start = 0;
mib_init();
+ if(!verbose)
+ {
+ module = -1;
+
+ /* Search for the last module the OID is part of */
+ 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;
+
+ if(module == -1 || tp->modid != module) {
+ module = tp->modid;
+ start = i + 1;
+ }
+ }
+
+ /* Print out the last module found */
+ if(module != -1) {
+ for (mp = module_head; mp; mp = mp->next) {
+ if (mp->modid == module && mp->name) {
+ fprintf(f, "%s::", mp->name);
+ module = -1;
+ break;
+ }
+ }
+
+ if(module != -1)
+ start = 0;
+ }
+ }
+
for(i = 0, tp = tree_head; tp && i < oid->len;
i++, tp = tp ? tp->child_list : NULL)
{
@@ -400,11 +440,14 @@ mib_format(struct asn_oid* oid, FILE* f)
if(!tp)
break;
- fprintf(f, ".%s", tp->label);
+ /* Skip until the module we found above */
+ if(i >= start)
+ fprintf(f, "%s%s", i > start ? "." : "", tp->label);
}
+ /* Print out anything not in the mib */
for( ; i < oid->len; i++)
- fprintf(f, ".%d", (int)(oid->subs[i]));
+ fprintf(f, "%s%d", i > start ? "." : "", (int)(oid->subs[i]));
return 0;
}
diff --git a/mib/mib-parser.h b/mib/mib-parser.h
index a586f8b..194d6d4 100644
--- a/mib/mib-parser.h
+++ b/mib/mib-parser.h
@@ -53,6 +53,6 @@ void mib_init();
void mib_uninit();
int mib_parse(const char* mib, struct asn_oid* oid);
-int mib_format(struct asn_oid* oid, FILE* f);
+int mib_format(struct asn_oid* oid, FILE* f, int verbose);
#endif /* __MIB_PARSER_H__ */
diff --git a/tools/rrdbot-get.c b/tools/rrdbot-get.c
index 9b038dd..c6be921 100644
--- a/tools/rrdbot-get.c
+++ b/tools/rrdbot-get.c
@@ -199,7 +199,7 @@ print_result (struct snmp_value* value)
if (ctx.numeric)
printf ("%s", asn_oid2str (&value->var));
else
- mib_format (&value->var, stdout);
+ mib_format (&value->var, stdout, ctx.verbose);
printf(": ");
@@ -398,8 +398,8 @@ process_simple (void)
static void
usage()
{
- fprintf(stderr, "usage: rrdbot-get [-Mnrv] [-t timeout] [-m mibdir] snmp://community@host/oid\n");
- fprintf(stderr, " rrdbot-get -V\n");
+ fprintf(stderr, "usage: rrdbot-get -V\n");
+ fprintf(stderr, " rrdbot-get [-Mnrv] [-t timeout] [-m mibdir] [-s srcaddr] snmp://community@host/oid\n");
exit(2);
}