Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / perl / SNMP / examples / pingmib.pl
1 use strict;
2 use SNMP;
3
4 my $target = shift || die "no ping target supplied\n"; # numeric ip address
5 my $host = shift || 'localhost';
6 my $community = shift || 'private';
7
8 {
9         my $sess = new SNMP::Session (DestHost => $host,
10                                       Community => $community,
11                                       Retries => 1);
12
13         my $dec = pack("C*",split /\./, $target);
14         my $oid = ".1.3.6.1.4.1.9.9.16.1.1.1";
15         my $row = "300";
16
17         $sess->set([
18                 ["$oid.16", $row, 6, "INTEGER"],
19                 ["$oid.16", $row, 5, "INTEGER"],
20                 ["$oid.15", $row, "MoNDS", "OCTETSTR"],
21                 ["$oid.2", $row, 1, "INTEGER"],
22                 ["$oid.4", $row, 20, "INTEGER"],
23                 ["$oid.5", $row, 150, "INTEGER"],
24                 ["$oid.3", $row, $dec, "OCTETSTR"]]);
25
26         $sess->set([["$oid.16", $row, 1, "INTEGER"]]);
27         sleep 30;
28         my ($sent, $received, $low, $avg, $high, $completed) = $sess->get([
29                 ["$oid.9", $row], ["$oid.10", $row], ["$oid.11", $row],
30                 ["$oid.12", $row], ["$oid.13", $row], ["$oid.14", $row]]);
31
32         printf "Packet loss: %d% (%d/%d)\n", (100 * ($sent-$received)) / $sent,
33                 $received, $sent;
34         print "Average delay $avg (low: $low high: $high)\n";
35         $sess->set(["$oid.16", $row, 6, "INTEGER"]);
36 }