Modul SNMP::Multi: Accessing SNMP responses 
Author Message
 Modul SNMP::Multi: Accessing SNMP responses

Hello together,

My aim:
-------

I will use the SNMP::Multi module from CPAN (Author Karl Schilke) to get  
SNMP status responses from similiar devices. From each device I will  
compare two response values. Regarding to the result of the compare  
process different messages should printed to a log. The script is a  
modified version of the example script.

The description of SNMP::Multi can be found at:

http://www.*-*-*.com/

--> Chapter Accessing SNMP Data from Agent Responses

My problem:
-----------

I'm fairly new in using perl, so I don't know the right way how to access  
the SNMP response data from the objects in a way that I can compare SNMP  
response. (see '#Problem getting data from object's' below.

As far as I can see now, the idea to generate a hash with
 %value = ($result->values())
in the script is no good idea because this method only leads to
the values of the SNMP-get request - and as far as I can see in Multi.pm
the data stored in the object is an array...

My idea now:
-------------

Using the method ->fmt() from the module SNMP on which SNMP::Multi
is based it's possible to generate OID/result strings, as in the
original script example from SNMP::Multi:

 for my $varlist ($result-->varlists()) {

offers the following output:

fbLink1.2 = "0" (INTEGER)
fbLInk2.2 = "o" (INTEGER)

How can I put this into a hash key/value pair (e.g. Link1.2/0)
and then make the compare process:

 if (($hash{'key'}==0) && ($hash{'key'}==0))
   print "the wanted log message

Or this idea non-smart and it's better to compare the dedicated
SNMP response objects in annother way?

Many thanks for help and hints in advance.

Jens

A: The modified script 04.pl (trial, not working properly at the end):

----------------------------------start script 04.pl----------------------

use strict;
use diagnostics;
use Carp;
use SNMP;
use SNMP::Multi;

chomp (my $datum =`date '+%d.%m.%Y %T'`);
my $verzeichnis = "/var/log";
my $logdatei = "log_ms";
my $logdatei2 = "log_ms2";
my $permissions = 0777;
chdir $verzeichnis;
`touch $logdatei`;
`touch $logdatei2`;
chmod ($permissions, $logdatei);
chmod ($permissions, $logdatei2);
         my $req = SNMP::Multi::VarReq->new (
         nonrepeaters => 2,
         hosts => [ qw/ 192.168.0.8 192.168.0.5/ ],
         vars  =>  [ [ '.1.3.6.1.4.1.3181.3.4.5.1.6.1' ], [
 '.1.3.6.1.4.1.3181.3.4.5.1.8.1' ], [
 '.1.3.6.1.4.1.3181.3.4.5.1.6.2' ], [
 '.1.3.6.1.4.1.3181.3.4.5.1.8.2' ] ],
     );
     die "VarReq: $SNMP::Multi::VarReq::error\n" unless $req;

     my $sm = SNMP::Multi->new (
         Method      => 'get',
         MaxSessions => 32,
         PduPacking  => 16,
         Community   => 'public',
         Version     => '1',
         Timeout     => 5,
         Retries     => 3,
     )
     or die "$SNMP::Multi::error\n";

     $sm->request($req) or die $sm->error;
     my $resp = $sm->execute() or die "Execute: $SNMP::Multi::error\n";

 chdir $verzeichnis;
 open (LOG,">>$logdatei") or die "Kann $logdatei nicht ?ffnen: $!\n";
 open (STDOUT, "| tee -a $logdatei >/dev/ttyS0") or die "Fehler bei  
tee:$!\n";
 open (EXLOG,">>$logdatei2") or die "Kann die $logdatei2 nicht
 ?ffnen:$!\n";
 for my $host ($resp->hosts()) {
 print EXLOG "$datum Server: $host:\n";
 for my $result ($host->results()) {
            if ($result->error()) {
                print "Error with $host: ", $result->error(), "\n";
                next;
            }
                print EXLOG (join ' ', $result->values());

# Problem getting data from object's
#
# The following code results to an errormessage (see error
# message below):
#
 my %value = ($result->values()) or die "Kann hash nicht anlegen: $!\n";
  if (($value{'1.3.6.1.4.1.3181.3.4.5.1.6.2'}==0) &&
     ($value{'1.3.6.1.4.1.3181.3.4.5.1.8.2'}==0)) {
             print "$datum $host Konverter 1 shelf 1 totally down\n";
             }
             elsif (($value{'1.3.6.1.4.1.3181.3.4.5.1.6.2'}==1)
             && ($value{'1.3.6.1.4.1.3181.3.4.5.1.8.2'}==0)) {
             print "$datum $host Konverter 1 shelf 1 LSZ XXX down!\n";
             }
             elsif (($value{'1.3.6.1.4.1.3181.3.4.5.1.6.2'}==0)
             && ($value{'1.3.6.1.4.1.3181.3.4.5.1.8.2'}==1)) {
             print "$datum $host Konverter 1 shelf 1 local loop down\n";
    }
   }
  }

-----------------------------end skript 04.pl----------------------------

Trying to use the create hash "%value" above causes the following error
message:

B: error message

--------------------------START error message snippet---------------------

syntax error at ./04.pl line 70, near "elsif"
Global symbol "%value" requires explicit package name at ./04.pl line 70.
Execution of ./04.pl aborted due to compilation errors (#1)
Uncaught exception from user code:
        syntax error at ./04.pl line 70, near "elsif"
Global symbol "%value" requires explicit package name at ./04.pl line 70.
Execution of ./04.pl aborted due to compilation errors.
scotty:/test/PERLcreate # ./04.pl
Use of uninitialized value in numeric eq (==) at ./04.pl line 68  (#1)
(W uninitialized) An undefined value was used as if it> were already
defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.

------------------------END error message snippet-------------------------



Sun, 24 Apr 2005 13:21:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Using SNMP::Multi Modul: putt responses to hash?!

2. Help with SNMP and SNMP traps

3. SNMP:: Session, SNMP::Varbind

4. Net-SNMP Perl 5 SNMP install problem

5. SNMP 3.1.0, ucd-snmp-4.1.2, gcc-2.95.2

6. Has SNMP replaced Net:SNMP ?

7. Perl SNMP and UCD SNMP 4.0.1

8. SNMP table walking with SNMP PERL module?

9. Has SNMP replaced Net:SNMP ?

10. SNMP module (SNMP Perl) ?

11. SNMP::Multi: Dereferer syntax to create hash?

12. Problem executing sample script in POD of SNMP::Multi

 

 
Powered by phpBB® Forum Software