[Reconnoiter-devel] [reconnoiter commit] Reconnoiter branch, master, updated. a5df09d25bd13bf1f726673e2b03f59b6066bf59

git at labs.omniti.com git at labs.omniti.com
Thu Feb 2 17:32:22 EST 2012


Pushed by: jesus
The branch, master has been updated
       via  a5df09d25bd13bf1f726673e2b03f59b6066bf59 (commit)
      from  a64139dcd7cce8a609a80ee6827795c4ee240da5 (commit)

Summary of changes:
 docs/config/modules/snmp.xml |   28 ++++++++++++++++++++++++++++
 src/modules/snmp.c           |   28 +++++++++++++++++++++-------
 src/modules/snmp.xml         |    4 ++++
 3 files changed, 53 insertions(+), 7 deletions(-)

Log:
commit a5df09d25bd13bf1f726673e2b03f59b6066bf59
Author: Theo Schlossnagle <jesus at omniti.com>
Date:   Thu Feb 2 17:32:36 2012 -0500

    support v1 of SNMP. Perhaps support v3 (untested)

diff --git a/docs/config/modules/snmp.xml b/docs/config/modules/snmp.xml
index cdd50ef..6718744 100644
--- a/docs/config/modules/snmp.xml
+++ b/docs/config/modules/snmp.xml
@@ -79,6 +79,34 @@
     </variablelist>
     <variablelist>
       <varlistentry>
+        <term>version</term>
+        <listitem>
+          <variablelist>
+            <varlistentry>
+              <term>required</term>
+              <listitem>
+                <para>optional</para>
+              </listitem>
+            </varlistentry>
+            <varlistentry>
+              <term>default</term>
+              <listitem>
+                <para>2c</para>
+              </listitem>
+            </varlistentry>
+            <varlistentry>
+              <term>allowed</term>
+              <listitem>
+                <para>(1|2c|3)</para>
+              </listitem>
+            </varlistentry>
+          </variablelist>
+          <para>The SNMP version used for queries.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+    <variablelist>
+      <varlistentry>
         <term>oid_.+</term>
         <listitem>
           <variablelist>
diff --git a/src/modules/snmp.c b/src/modules/snmp.c
index 6241d16..6fc6b51 100644
--- a/src/modules/snmp.c
+++ b/src/modules/snmp.c
@@ -123,6 +123,7 @@ typedef struct _mod_config {
 struct target_session {
   void *sess_handle;
   noit_module_t *self;
+  char *key;
   char *target;
   eventer_t timeoutevent;
   int fd;
@@ -152,6 +153,7 @@ struct check_info {
   noit_module_t *self;
   noit_check_t *check;
   struct target_session *ts;
+  int version;
 };
 
 /* We hold struct check_info's in there key's by their reqid.
@@ -177,21 +179,24 @@ static void remove_check(struct check_info *c) {
 }
 
 struct target_session *
-_get_target_session(noit_module_t *self, char *target) {
+_get_target_session(noit_module_t *self, char *target, int version) {
+  char key[128];
   void *vts;
   struct target_session *ts;
   snmp_mod_config_t *conf;
   conf = noit_module_get_userdata(self);
+  snprintf(key, sizeof(key), "%s:v%d", target, version);
   if(!noit_hash_retrieve(&conf->target_sessions,
-                         target, strlen(target), &vts)) {
+                         key, strlen(key), &vts)) {
     ts = calloc(1, sizeof(*ts));
     ts->self = self;
     ts->fd = -1;
     ts->refcnt = 0;
     ts->target = strdup(target);
+    ts->key = strdup(key);
     ts->in_table = 1;
     noit_hash_store(&conf->target_sessions,
-                    ts->target, strlen(ts->target), ts);
+                    ts->key, strlen(ts->key), ts);
     vts = ts;
   }
   return (struct target_session *)vts;
@@ -817,8 +822,9 @@ static void noit_snmp_sess_open(struct target_session *ts,
                                 noit_check_t *check) {
   const char *community;
   struct snmp_session sess;
+  struct check_info *info = check->closure;
   snmp_sess_init(&sess);
-  sess.version = SNMP_VERSION_2c;
+  sess.version = info->version;
   sess.peername = ts->target;
   if(!noit_hash_retr_str(check->config, "community", strlen("community"),
                          &community)) {
@@ -924,9 +930,10 @@ static int noit_snmp_send(noit_module_t *self, noit_check_t *check,
   struct target_session *ts;
   struct check_info *info = check->closure;
   int port = 161;
-  const char *portstr;
+  const char *portstr, *versstr;
   char target_port[64];
 
+  info->version = SNMP_VERSION_2c;
   info->self = self;
   info->check = check;
   info->timedout = 0;
@@ -937,8 +944,14 @@ static int noit_snmp_send(noit_module_t *self, noit_check_t *check,
                         &portstr)) {
     port = atoi(portstr);
   }
+  if(noit_hash_retr_str(check->config, "version", strlen("version"),
+                        &versstr)) {
+    /* We don't care about 2c or others... as they all default to 2c */
+    if(!strcmp(versstr, "1")) info->version = SNMP_VERSION_1;
+    if(!strcmp(versstr, "3")) info->version = SNMP_VERSION_3;
+  }
   snprintf(target_port, sizeof(target_port), "%s:%d", check->target_ip, port);
-  ts = _get_target_session(self, target_port);
+  ts = _get_target_session(self, target_port, info->version);
   gettimeofday(&check->last_fire_time, NULL);
   if(!ts->refcnt) {
     eventer_t newe;
@@ -967,6 +980,7 @@ static int noit_snmp_send(noit_module_t *self, noit_check_t *check,
 
   req = snmp_pdu_create(SNMP_MSG_GET);
   if(req) noit_snmp_fill_req(req, check);
+  req->version = info->version;
   /* Setup out snmp requests */
   if(ts->sess_handle && req &&
      (info->reqid = snmp_sess_send(ts->sess_handle, req)) != 0) {
@@ -1134,7 +1148,7 @@ static int noit_snmp_init(noit_module_t *self) {
       noitL(nlerr, "cannot open netsnmp transport for trap daemon\n");
       return -1;
     }
-    ts = _get_target_session(self, "snmptrapd");
+    ts = _get_target_session(self, "snmptrapd", SNMP_DEFAULT_VERSION);
     snmp_sess_init(session);
     session->peername = SNMP_DEFAULT_PEERNAME;
     session->version = SNMP_DEFAULT_VERSION;
diff --git a/src/modules/snmp.xml b/src/modules/snmp.xml
index 2be774f..7e409a2 100644
--- a/src/modules/snmp.xml
+++ b/src/modules/snmp.xml
@@ -13,6 +13,10 @@
                required="optional"
                default="161"
                allowed="\d+">The UDP port to which SNMP queries will be sent.</parameter>
+    <parameter name="version"
+               required="optional"
+               default="2c"
+               allowed="(1|2c|3)">The SNMP version used for queries.</parameter>
     <parameter name="oid_.+"
                required="optional"
                allowed=".+">Defines a metric to query.  Key oid_foo will establish a metric called foo.  The value of the parameter should be an OID either in decimal notation or MIB name.</parameter>




hooks/post-receive
-- 
Reconnoiter


More information about the Reconnoiter-devel mailing list