| •1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Ping a host via the CISCO-PING-MIB. For more information about the |
| 4 |
# CISCO-PING-MIB, see also |
| 5 |
# http://tools.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&mibName=CISCO-PING-MIB. |
| 6 |
|
| 7 |
use strict; |
| 8 |
use SNMP; |
| 9 |
|
| 10 |
my $target = shift || die "no ping target supplied\n"; # numeric ip address |
| 11 |
my $host = shift || 'localhost'; |
| 12 |
my $community = shift || 'private'; |
| 13 |
|
| 14 |
{ |
| 15 |
my $sess = new SNMP::Session (DestHost => $host, |
| 16 |
Community => $community, |
| 17 |
Retries => 1); |
| 18 |
|
| 19 |
my $dec = pack("C*",split /\./, $target); |
| 20 |
my $oid = ".1.3.6.1.4.1.9.9.16.1.1.1"; |
| 21 |
my $row = "300"; |
| 22 |
my $res; |
| 23 |
|
| 24 |
$res = $sess->set([ |
| 25 |
["$oid.16", $row, 6, "INTEGER"], |
| 26 |
["$oid.16", $row, 5, "INTEGER"], |
| 27 |
["$oid.15", $row, "MoNDS", "OCTETSTR"], |
| 28 |
["$oid.2", $row, 1, "INTEGER"], |
| 29 |
["$oid.4", $row, 20, "INTEGER"], |
| 30 |
["$oid.5", $row, 150, "INTEGER"], |
| 31 |
["$oid.3", $row, $dec, "OCTETSTR"]]); |
| 32 |
defined($res) || die "row creation failed"; |
| 33 |
|
| 34 |
$res = $sess->set([["$oid.16", $row, 1, "INTEGER"]]); |
| 35 |
defined($res) || die "row activation failed"; |
| 36 |
|
| 37 |
sleep 30; |
| 38 |
my ($sent, $received, $low, $avg, $high, $completed) = $sess->get([ |
| 39 |
["$oid.9", $row], ["$oid.10", $row], ["$oid.11", $row], |
| 40 |
["$oid.12", $row], ["$oid.13", $row], ["$oid.14", $row]]); |
| 41 |
|
| 42 |
printf "Packet loss: %d% (%d/%d)\n", (100 * ($sent-$received)) / $sent, |
| 43 |
$received, $sent; |
| 44 |
print "Average delay $avg (low: $low high: $high)\n"; |
| 45 |
$sess->set(["$oid.16", $row, 6, "INTEGER"]); |
| 46 |
} |