Question about snmp monitors


13-04-2004 11:04:40


I would do this operation one one graph

if the result is 1 the graph is up and if it's down the graph is 0. How can I do that ?



14-04-2004 03:26:28

As I didn't find how to do it directly in Netmrg, I did a script. Here is the code if someone is interested ! This script permits to know the status of a router interface (for example).



# we need at least a host and community string
if (scalar(@ARGV) < 2)
print "U\n";
} # end if only one argument

# some variables to be used later
my $host = $ARGV[0];
my $community = $ARGV[1];
my $devicenumber = 1;
my $cmdoutput;
my $ifAdminHack;
my $ifOperHack;
my $result;

if (defined($ARGV[2]))
$devicenumber = $ARGV[2];
} # end if device number specified

# ifAdminHack is UP or Down ?
# execute snmpwalk and store output
$cmdoutput = `snmpwalk -Ov -c $community $host .$devicenumber 2> /dev/null`;
$ifAdminHack = substr($cmdoutput, 3, 1);

# ifOperHack is UP or Down ?
# execute snmpwalk and store output
$cmdoutput = `snmpwalk -Ov -c $community $host .$devicenumber 2> /dev/null`;
$ifOperHack = substr($cmdoutput, 3, 1);

# Logical AND between ifAdminHack and ifOperHack
$result = $ifAdminHack & $ifOperHack;

if(($result != 0)&&($result != 1)){
print "U\n";
}# if the result is not up or down (1 or 0)
# then the result is defined as U

print "$result\n";
# else we return the result



14-04-2004 08:37:27

Yeah, that's the best way to do that in NetMRG at this point.


05-05-2004 14:38:14

I tested the above perl code on my machine running net-snmp 5.0.9 and it always returned nothing, which isn't really an option.
$ snmpwalk -Ov -c public .

As you can see, the snmpwalk() returns a single value, not 3 as implied by the code segment
$ifOperHack = substr($cmdoutput, 3, 1);

Is this an error in the code or is my net-snmp incompatible with other versions of snmp?


06-05-2004 09:07:22

No, my version of snmp returns


It's for that reason that I cut the string returned.
You, you don't have to do this !


06-05-2004 09:47:27

Hi Meshuggah,

Ok, that's basically what I wanted to know. I'm having problems getting netmrg-gatherer() to read from my snmpd(), even though snmpwalk() works just fine. It won't get past the uptime read.

Now, I need to find out where the hack is that will either force the net-snmp v.5.0.9 snmpd() daemon to return whatever it is that netmrg-gatherer expects or one that will force netmrg to recognise the value that snmpd() returns.

Do you know of such a beast?