Select Git revision
-
Martin Mareš authoredMartin Mareš authored
show-snmp 6.00 KiB
#!/usr/bin/perl
use strict;
use warnings;
use Net::SNMP;
my $host = $ARGV[0] or die "Usage: $0 <host>\n";
print "Scanning $host...\n";
my $sess = Net::SNMP->session(
-hostname => $host . '.kam.hide.ms.mff.cuni.cz',
-version => 1,
-community => 'public',
) or die;
my $prmib = '1.3.6.1.2.1.43';
sub parse_table($) {
my $raw = $sess->get_table(-baseoid => $_[0]) or return {};
my %tab = ();
for my $bb (keys %$raw) {
my $bk = substr($bb, length($_[0]) + 1);
$bk =~ /(.*)\.1\.(\d+)/ or die "OID parse error at $bk";
$tab{$2}{$1} = $raw->{$bb};
}
return \%tab;
}
sub media_unit($) {
my ($unit) = @_;
return unless defined $unit;
return 25.4 / 10000 if $unit == 3;
return 0.001 if $unit == 4;
return 1 if $unit == 0; # Some printers (Xerox 3300MFP) send unit 0 -- what does it mean?
die "Unknown media unit $unit\n";
}
sub subunit_status($) {
my ($s) = @_;
my @bases = ('Idle', 'OnReq', 'Standby', 'Broken', 'Active', 'Unknown', 'Busy', '??7??');
my $base = $bases[$s & 7];
if ($s & 8) { $base .= '/Alert'; }
if ($s & 16) { $base .= '/CritAlert'; }
if ($s & 32) { $base .= '/Offline'; }
if ($s & 64) { $base .= '/Transition'; }
return $base;
}
sub current($) {
my ($c) = @_;
return "other" if $c == -2;
return "unknown" if $c == -2;
return "OK" if $c == -3;
return "???" if $c < 0;
return $c;
}
print "\n### Inputs ###\n";
my $ins = parse_table("$prmib.8.2.1");
for my $i (sort keys %$ins) {
my $b = $ins->{$i};
printf "%-10s ", ($b->{13} // "Input #$i");
my $unit = media_unit($b->{3});
print join("x", map { (!defined($_) || $_ < 0) ? '?' : sprintf("%.0f", $_*$unit) } ($b->{4}, $b->{5}));
print " capa=", $b->{9};
print " cur=", current($b->{10});