Question about snmp monitors

Meshuggah

13-04-2004 11:04:40

Hi,

I would do this operation one one graph
ifAdminHack.1&ifOperHack.1

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

Thanx

Meshuggah

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).

[code1460c1230c9]

#!/usr/bin/perl

# we need at least a host and community string
if (scalar(@ARGV) < 2)
{
print "U\n";
exit();
} # 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 .1.3.6.1.2.1.2.2.1.7.$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 .1.3.6.1.2.1.2.2.1.8.$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";
exit();
}# 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

[/code1460c1230c9]

balleman

14-04-2004 08:37:27

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

makis

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.
[code144fd6aaf6e]
$ snmpwalk -Ov -c public 192.168.22.1 .1.3.6.1.2.1.2.2.1.7.3
1
[/code144fd6aaf6e]

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

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

Meshuggah

06-05-2004 09:07:22

Hi,
No, my version of snmp returns

up(1)

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

makis

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?

Cheers,

Mark