| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Getopt::Long qw(:config no_ignore_case); #bundling | ||
| 6 | use Pod::Usage; | ||
| 7 | |||
| 8 | use Cisco::SNMP::Line; | ||
| 9 | |||
| 10 | my %opt; | ||
| 11 | my ($opt_help, $opt_man); | ||
| 12 | |||
| 13 | GetOptions( | ||
| 14 | 'community=s' => \$opt{community}, | ||
| 15 | 'Clear!' => \$opt{clear}, | ||
| 16 | 'lines=s' => \$opt{lines}, | ||
| 17 | 'm|message=s' => \$opt{message}, | ||
| 18 | 'quantity!' => \$opt{quantity}, | ||
| 19 | 'help!' => \$opt_help, | ||
| 20 | 'man!' => \$opt_man | ||
| 21 | ) or pod2usage(-verbose => 0); | ||
| 22 | |||
| 23 | pod2usage(-verbose => 1) if defined $opt_help; | ||
| 24 | pod2usage(-verbose => 2) if defined $opt_man; | ||
| 25 | |||
| 26 | # Make sure at least one host was provided | ||
| 27 | if (!@ARGV) { | ||
| 28 | pod2usage(-verbose => 0, -message => "$0: host required\n") | ||
| 29 | } | ||
| 30 | |||
| 31 | $opt{community} = $opt{community} || 'private'; | ||
| 32 | |||
| 33 | for (@ARGV) { | ||
| 34 | print "\n-- $_ --\n"; | ||
| 35 | |||
| 36 | my $cm; | ||
| 37 | if (!defined($cm = Cisco::SNMP::Line->new( | ||
| 38 | hostname => $_, | ||
| 39 | community => $opt{community} | ||
| 40 | ))) { | ||
| 41 | printf "Error: %s\n", Cisco::SNMP::Line->error; | ||
| 42 | next | ||
| 43 | } | ||
| 44 | |||
| 45 | if (defined $opt{quantity}) { | ||
| 46 | if (defined(my $lines = $cm->line_numberof())) { | ||
| 47 | print "$_: Lines = $lines\n" | ||
| 48 | } else { | ||
| 49 | printf "Error: %s\n", Cisco::SNMP::Line->error | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | if (defined $opt{message}) { | ||
| 54 | my %params; | ||
| 55 | if (defined $opt{lines}) { $params{lines} = $opt{lines} } | ||
| 56 | if (defined $opt{message}) { $params{message} = $opt{message} } | ||
| 57 | if (defined(my $lines = $cm->line_message(%params))) { | ||
| 58 | print "$_: Messaged lines = @{$lines}\n" | ||
| 59 | } else { | ||
| 60 | printf "Error: %s\n", Cisco::SNMP::Line->error | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | if (defined $opt{clear}) { | ||
| 65 | my %params; | ||
| 66 | if (defined $opt{lines}) { $params{lines} = $opt{lines} } | ||
| 67 | if (defined(my $lines = $cm->line_clear(%params))) { | ||
| 68 | print "$_: Cleared lines = @{$lines}\n" | ||
| 69 | } else { | ||
| 70 | printf "Error: %s\n", Cisco::SNMP::Line->error | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | if ((!defined $opt{quantity}) && | ||
| 75 | (!defined $opt{message} ) && | ||
| 76 | (!defined $opt{clear} )) { | ||
| 77 | if (defined(my $lines = $cm->line_info())) { | ||
| 78 | my $sessions = $cm->line_sessions(); | ||
| 79 | print "Line Type Active\n"; | ||
| 80 | print "----------------\n"; | ||
| 81 | for my $line (sort {$a <=> $b} (keys(%{$lines}))) { | ||
| 82 | printf "%4i %-5s ", | ||
| 83 | $line, | ||
| 84 | $lines->lineType($line); | ||
| 85 | if ($lines->lineActive($line) == 1) { | ||
| 86 | print "YES"; | ||
| 87 | for (0..$lines->lineNses($line)-1) { | ||
| 88 | printf " [%s] %s://%s", $sessions->sessDirection($line, $_), $sessions->sessType($line, $_), $sessions->sessAddress($line, $_) | ||
| 89 | } | ||
| 90 | } else { | ||
| 91 | print " NO" | ||
| 92 | } | ||
| 93 | print "\n" | ||
| 94 | } | ||
| 95 | } else { | ||
| 96 | printf "Error: %s\n", Cisco::SNMP::Line->error | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | $cm->close() | ||
| 101 | } | ||
| 102 | |||
| 103 | __END__ |