I must have missed something.
I've been working with SNMP with Cisco switches lately. Out of sheer curiosity, I used scli to tell me about one of the printers. Two days later, I'm determined to make a printer status page for the college.
So I'm futzing around with SNMP and doing things in what appears to be The Standard Way. And it's disgusting, just glance at it:
# console information
my $vars = new SNMP::VarList( ['prtConsoleDisplayBufferText'] );
my ($msg) = $s->getnext($vars);
die $s->{ErrorStr} if $s->{ErrorStr};
while ( !$s->{ErrorStr} and $$vars[0]->tag eq "prtConsoleDisplayBufferText" ) {
push @{ $data{consoletext} }, $msg;
($msg) = $s->getnext($vars);
}
# status lights
$vars = new SNMP::VarList(
['prtConsoleOnTime'],
['prtConsoleColor'],
['prtConsoleDescription'],
);
my ($light_status, $light_color, $light_desc) = $s->getnext($vars);
die $s->{ErrorStr} if $s->{ErrorStr};
while ( !$s->{ErrorStr} and $$vars[0]->tag eq "prtConsoleOnTime" ) {
push @{ $data{lights} }, {
status => ($light_status ? 0 : 1),
color => &SNMP::mapEnum($$vars[1]->tag, $light_color),
description => $light_desc,
};
($light_status, $light_color, $light_desc) = $s->getnext($vars);
}
# trays and capacity
$vars = new SNMP::VarList(
['prtInputName'],
['prtInputMediaName'],
['prtInputStatus'],
['prtInputCurrentLevel'],
['prtInputMaxCapacity'],
);
my ($light_status, $light_color, $light_desc) = $s->getnext($vars);
die $s->{ErrorStr} if $s->{ErrorStr};
while ( !$s->{ErrorStr} and $$vars[0]->tag eq "prtConsoleOnTime" ) {
push @{ $data{lights} }, {
status => ($light_status ? 0 : 1),
color => &SNMP::mapEnum($$vars[1]->tag, $light_color),
description => $light_desc,
};
($light_status, $light_color, $light_desc) = $s->getnext($vars);
}
So I quickly wrote up SNMP::Simple, which turns the above into this:
$data{name} = $s->get('sysName');
$data{location} = $s->get('sysLocation');
$data{consoletext} = $s->get_list('prtConsoleDisplayBufferText');
$data{lights} = $s->get_named_table(
status => 'prtConsoleOnTime',
color => 'prtConsoleColor',
name => 'prtConsoleDescription',
);
$data{trays} = $s->get_named_table(
name => 'prtInputName',
media => 'prtInputMediaName',
status => 'prtInputStatus',
level => 'prtInputCurrentLevel',
max => 'prtInputMaxCapacity',
);
Why hasn't anyone else done this already? I really must be missing the Big Picture. All in all, I'd like to release this, but fear excommunication by releasing a
Why not? (Score:1)
Re:Why not? (Score:1)
qw(Ian Langworth)
simple is good (Score:2)
chances are your code will be useful to somebody else, too.
Its always worth getting the ball rolling, thatway people can contribute, rather than writing then forgetting handy code snippets.
@JAPH = qw(Hacker Perl Another Just);
print reverse @JAPH;