summaryrefslogtreecommitdiff
path: root/mib
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2009-01-16 19:58:16 +0000
committerStef Walter <stef@memberwebs.com>2009-01-16 19:58:16 +0000
commitf2151e0693150b94009aa77d68a1294f53f79dd3 (patch)
tree491672637f4e24fb38e7d710309f96e5976c826c /mib
parent3ad6ae1b3929440ac88cd01b6636702c97be38df (diff)
- Add support for printing out MIB name in rrdbot-get
Diffstat (limited to 'mib')
-rw-r--r--mib/mib-parser.c51
-rw-r--r--mib/mib-parser.h2
2 files changed, 48 insertions, 5 deletions
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__ */