Re: using monitor to trap (extend vs proxy)

Dave Shield <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <CAKoMtGYqTia33JNWzuwVkv2iXixkMKJVZbKytcxVDbgBsSgXeA@mail.gmail.com>
On 12 January 2012 14:59, Greg Oliver <[email protected]> wrote:
> Is there any way to use monitor to compare strings versus integers?

No - I don't think so.
The DisMan Event MIB is designed to work with integer values only.

   (Well, strictly speaking the mteTriggerExistance tests
    should work with any type of object, so you could monitor
    for *changes* in a string value.   But the Boolean and
    Threshold tests are definitely integer only).


>  I think I could make that work if so.

Hmmmm...   Are you feeling adventurous?
The attached patch is completely untested, but feel to give it a whirl
and see whether it helps you at all....

Dave

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
disman-string.patch (text/x-patch, 1.6 KB)
--- mteTrigger.c.cln	2012-01-12 15:07:45.740833000 +0000
+++ mteTrigger.c	2012-01-12 15:24:13.320896000 +0000
@@ -204,7 +204,7 @@
     netsnmp_variable_list *dvar = NULL;
     netsnmp_variable_list *dv1  = NULL, *dv2 = NULL;
     netsnmp_variable_list sysUT_var;
-    int  cmp = 0, n, n2;
+    int  cmp = 0, n, n2, ival;
     long value;
     const char *reason;
 
@@ -549,6 +549,29 @@
          *  instances of a given object should have the same syntax.
          */
         switch (var->type) {
+        case ASN_OCTET_STR:
+             /*
+              *  Let's see if this string can be interpreted as an integer....
+              */
+             ival = atoi( (const char *)var->val.string );
+             if (( ival == 0 ) &&
+                 ( var->val.string[0] != '0' )) {
+                 /* No?  Oh well, it was worth a try.
+                  * Report the error exactly as below.  */
+                DEBUGMSGTL(( "disman:event:trigger:fire",
+                             "Returned non-integer string result(s): "));
+                DEBUGMSGOID(("disman:event:trigger:fire",
+                             var->name, var->name_length));
+                DEBUGMSG((   "disman:event:trigger:fire",
+                             " (boolean/threshold) %d\n", var->type));;
+                snmp_free_varbind( entry->old_results );
+                entry->old_results = var;
+                return;
+             }
+             /* Yes - so let's pretend that this is what was returned */
+             snmp_set_var_typed_integer( var, ASN_INTEGER, ival );
+             /* Fallthrough */
+
         case ASN_INTEGER:
         case ASN_COUNTER:
         case ASN_GAUGE:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.