Re: Sending traps using Perl

Bart Van Assche <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <CAO+b5-oT4WbhK4-s9mHpSv_sqFhODTXp4RiJ2NQVkwc76kWnNw@mail.gmail.com>
On Thu, Sep 29, 2011 at 5:41 PM, <[email protected]> wrote:
> I don't believe that is the problem. The actual amount that the timeticks increases between sending commands is correct, it's
> as if it's just not been initialised correctly. It doesn't seem to be a case of dividing the value by ten. Also, even rebooting my
> PC doesn't seem to have reset the value.
>
> The odd thing is that if I do an snmp Get request on my Agent on sysUpTime the correct time ticks value is returned i.e how
> long my Master Agent has been running. The unusual timeticks value seems to be only occurring when sending Traps. I'm a
> bit confused that the two values are so different.

I'll have a closer look at this.

> Also, Do you know why when sending an SNMPv2 trap without any additional var-binds it fails but  as an  SNMPv1 trap it works.

Does the attached patch help ?

Bart.

diff --git a/perl/SNMP/SNMP.xs b/perl/SNMP/SNMP.xs
index a0cfe69..459ac87 100644
--- a/perl/SNMP/SNMP.xs
+++ b/perl/SNMP/SNMP.xs
@@ -4437,7 +4437,7 @@ snmp_trapV2(sess_ref,uptime,trap_oid,varlist_ref)
 	
            New (0, oid_arr, MAX_OID_LEN, oid);

-           if (oid_arr && SvROK(sess_ref) && SvROK(varlist_ref)) {
+           if (oid_arr && SvROK(sess_ref)) {

               sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1);
 	      ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv));
@@ -4451,8 +4451,13 @@ snmp_trapV2(sess_ref,uptime,trap_oid,varlist_ref)
 	
               pdu = snmp_pdu_create(SNMP_MSG_TRAP2);

-              varlist = (AV*) SvRV(varlist_ref);
-              varlist_len = av_len(varlist);
+              if (SvROK(varlist_ref)) {
+                  varlist = (AV*) SvRV(varlist_ref);
+                  varlist_len = av_len(varlist);
+              } else {
+                  varlist = NULL;
+                  varlist_len = -1;
+              }
 	      /************************************************/
               res = __add_var_val_str(pdu, sysUpTime, SYS_UPTIME_OID_LEN,
 				uptime, strlen(uptime), TYPE_TIMETICKS);

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1

_______________________________________________
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
0001-CHANGES-perl-Support-sending-SNMPv2-traps-with-an-em.patch (text/plain, 1.6 KB)
From a12a18bf389835b058557ce6f30ed7363dc231be Mon Sep 17 00:00:00 2001
From: Bart Van Assche <[email protected]>
Date: Thu, 29 Sep 2011 19:03:02 +0200
Subject: [PATCH] CHANGES: perl: Support sending SNMPv2 traps with an empty varbind list

An example:
perl -e 'use SNMP; my $session = new SNMP::TrapSession(Version => "2c"); $session->trap(oid => "warmStart")'
---
 perl/SNMP/SNMP.xs |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/perl/SNMP/SNMP.xs b/perl/SNMP/SNMP.xs
index a0cfe69..459ac87 100644
--- a/perl/SNMP/SNMP.xs
+++ b/perl/SNMP/SNMP.xs
@@ -4437,7 +4437,7 @@ snmp_trapV2(sess_ref,uptime,trap_oid,varlist_ref)
 	   
            New (0, oid_arr, MAX_OID_LEN, oid);
 
-           if (oid_arr && SvROK(sess_ref) && SvROK(varlist_ref)) {
+           if (oid_arr && SvROK(sess_ref)) {
 
               sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1);
 	      ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv));
@@ -4451,8 +4451,13 @@ snmp_trapV2(sess_ref,uptime,trap_oid,varlist_ref)
 	      
               pdu = snmp_pdu_create(SNMP_MSG_TRAP2);
 
-              varlist = (AV*) SvRV(varlist_ref);
-              varlist_len = av_len(varlist);
+              if (SvROK(varlist_ref)) {
+                  varlist = (AV*) SvRV(varlist_ref);
+                  varlist_len = av_len(varlist);
+              } else {
+                  varlist = NULL;
+                  varlist_len = -1;
+              }
 	      /************************************************/
               res = __add_var_val_str(pdu, sysUpTime, SYS_UPTIME_OID_LEN,
 				uptime, strlen(uptime), TYPE_TIMETICKS);
-- 
1.7.3.4
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.