summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2006-11-28 01:53:57 +0000
committerStef Walter <stef@memberwebs.com>2006-11-28 01:53:57 +0000
commitfafb8142821a34311f55971674630b674b063495 (patch)
tree58aef24fc7ce8fc093d5e477dbacf8306b412859
parent9791f61c323d2769abfe0e9889b81c52ca1309af (diff)
Added SNMP v2 support.
-rw-r--r--ChangeLog4
-rw-r--r--common/config-parser.c24
-rw-r--r--common/config-parser.h3
-rw-r--r--daemon/config.c11
-rw-r--r--tools/rrdbot-get.c8
5 files changed, 38 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 6b39426..06a2dec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+0.5
+ - Added SNMP version 2c support for rrdbot-get [Stoned Elipot]
+
0.4
- Reduced memory usage of SNMP requests
- Added asynchronous DNS resolver
@@ -6,4 +9,3 @@
0.3
- Initial public release
-
diff --git a/common/config-parser.c b/common/config-parser.c
index 63c1bbb..c8f2155 100644
--- a/common/config-parser.c
+++ b/common/config-parser.c
@@ -42,6 +42,9 @@
#include <stdarg.h>
#include <dirent.h>
+#include <bsnmp/asn1.h>
+#include <bsnmp/snmp.h>
+
#include "config-parser.h"
static void
@@ -364,3 +367,24 @@ cfg_parse_uri (char *uri, char** scheme, char** host, char** user, char** path)
return NULL;
}
+
+#define CONFIG_SNMP "snmp"
+#define CONFIG_SNMP2 "snmp2"
+#define CONFIG_SNMP2C "snmp2c"
+
+/* Parsing snmp, snmp2 snmp2c etc... */
+const char*
+cfg_parse_scheme(const char *str, enum snmp_version *scheme)
+{
+ /* Currently we only support SNMP pollers */
+ if(strcmp(str, CONFIG_SNMP) == 0)
+ *scheme = SNMP_V1;
+ else if(strcmp(str, CONFIG_SNMP2) == 0)
+ *scheme = SNMP_V2c;
+ else if(strcmp(str, CONFIG_SNMP2C) == 0)
+ *scheme = SNMP_V2c;
+ else
+ return "invalid scheme";
+ return NULL;
+}
+
diff --git a/common/config-parser.h b/common/config-parser.h
index 11949a2..6af8c17 100644
--- a/common/config-parser.h
+++ b/common/config-parser.h
@@ -50,4 +50,7 @@ int cfg_parse_file(const char* filename, void* data, char** memory);
/* A helper for parsing URIs */
const char* cfg_parse_uri (char *uri, char** scheme, char** host, char** user, char** path);
+/* Parsing snmp, snmp2 snmp2c etc... */
+const char* cfg_parse_scheme (const char *input, enum snmp_version *scheme);
+
#endif /* __CONFIG_PARSER_H__ */
diff --git a/daemon/config.c b/daemon/config.c
index 34cecfb..49f8e0f 100644
--- a/daemon/config.c
+++ b/daemon/config.c
@@ -229,14 +229,9 @@ parse_item(const char* field, char* uri, config_ctx *ctx)
ASSERT(host && path);
/* Currently we only support SNMP pollers */
- if(strcmp(scheme, CONFIG_SNMP) == 0)
- version = SNMP_V1;
- else if(strcmp(scheme, CONFIG_SNMP2) == 0)
- version = SNMP_V2c;
- else if(strcmp(scheme, CONFIG_SNMP2C) == 0)
- version = SNMP_V2c;
- else
- errx(2, "%s: invalid poll scheme: %s", ctx->confname, scheme);
+ msg = cfg_parse_scheme(scheme, &version);
+ if(msg)
+ errx(2, "%s: %s", msg, scheme);
/*
* Build a lookup key. We can only combine requests for the same
diff --git a/tools/rrdbot-get.c b/tools/rrdbot-get.c
index e140eb1..0df7b84 100644
--- a/tools/rrdbot-get.c
+++ b/tools/rrdbot-get.c
@@ -121,6 +121,7 @@ send_req()
static void
setup_req(char* uri)
{
+ enum snmp_version version;
const char* msg;
char* scheme;
char* copy;
@@ -137,15 +138,16 @@ setup_req(char* uri)
ASSERT(ctx.hostname && path);
/* Currently we only support SNMP pollers */
- if(strcmp(scheme, "snmp") != 0)
- errx(2, "invalid scheme: %s", scheme);
+ msg = cfg_parse_scheme(scheme, &version);
+ if(msg)
+ errx(2, "%s: %s", msg, scheme);
if(sock_any_pton(ctx.hostname, &ctx.hostaddr,
SANY_OPT_DEFPORT(161) | SANY_OPT_DEFLOCAL) == -1)
err(1, "couldn't resolve host address (ignoring): %s", ctx.hostname);
memset(&ctx.pdu, 0, sizeof(ctx.pdu));
- ctx.pdu.version = 1;
+ ctx.pdu.version = version;
ctx.pdu.request_id = 0;
ctx.pdu.type = ctx.recursive ? SNMP_PDU_GETNEXT : SNMP_PDU_GET;
ctx.pdu.error_status = 0;