summaryrefslogtreecommitdiff
path: root/scripts/vyatta-show-snmp.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/vyatta-show-snmp.pl')
-rwxr-xr-xscripts/vyatta-show-snmp.pl28
1 files changed, 23 insertions, 5 deletions
diff --git a/scripts/vyatta-show-snmp.pl b/scripts/vyatta-show-snmp.pl
index 2346a6c..634b3cc 100755
--- a/scripts/vyatta-show-snmp.pl
+++ b/scripts/vyatta-show-snmp.pl
@@ -27,11 +27,14 @@ use NetAddr::IP;
my $SNMPDCFG = '/etc/snmp/snmpd.conf';
my $SNMPSTATUS = '/usr/bin/snmpstatus';
+my $password_file = '/config/snmp/superuser_pass';
# generate list of communities in configuration file
sub read_config {
my %community;
+ die "Service SNMP does not configured.\n" if (! -e $SNMPDCFG);
+
open( my $cfg, '<', $SNMPDCFG )
or die "Can't open $SNMPDCFG : $!\n";
@@ -65,14 +68,29 @@ sub status_any {
my %community = %{$cref};
my $localhost = new NetAddr::IP('localhost');
- die "No SNMP community's configured\n"
- unless scalar(%community);
-
- foreach my $c ( keys %community ) {
+ if (scalar(%community)) {
+ foreach my $c ( keys %community ) {
my $addr = $community{$c};
status( $c, $localhost->addr() ) if ( $addr->contains($localhost) );
+ }
+ }
+ status_v3();
+
+}
+
+sub status_v3 {
+ open (my $file, '<' , $password_file) or die "Couldn't open $password_file - $!";
+ my $superuser_pass = do { local $/; <$file> };
+ close $file;
+ open ($file, '<', $SNMPDCFG) or die "Couldn't open $SNMPDCFG - $!";
+ my $superuser_login = '';
+ while (my $line = <$file>) {
+ if ($line =~ /^iquerySecName (.*)$/) {
+ $superuser_login = $1;
+ }
}
- die "No SNMP community's accessible from ", $localhost->addr(), "\n";
+ close $file;
+ exec $SNMPSTATUS, '-v3', '-l', 'authNoPriv', '-u', $superuser_login, '-A', $superuser_pass, 'localhost';
}
# check status of one community