I belong to the generation of "wild networkers" who at the beginning of the century began to build networks of various sizes in the post-Soviet space. There was not enough of everything - money, education, specialists, equipment ... But enthusiasm and self-confidence was immeasurable. They sculpted nets from just about anything, or from whatever there was enough money for. I still remember the day when I bought my first L2 switch - the famous DES-3526 .
Naturally, at some point there is a qualitative growth, and it becomes necessary to monitor this entire network zoo. There are so many methods and software for monitoring that even just listing them and brief characteristics will take more than one article.
About 5 years ago I undertook to rewrite a self-written NMS module in ABillS . Billing was written in Perl, and at that time I was "nimble" in it. The billing API documentation was enough for me to transfer the webcam from PHP to Perl. At first, I used the Perl analogue of fping to periodically poll the hardware and separately took SNMP statistics. What is most annoying when working with SNMP is the terrible lags, and as the number of devices being polled increases, they also increase. They are struggling with this with different methods: parallelization, increasing timeouts, and so on.
Actually, here I would like to share my implementation of SNMP polling for network equipment. The SNMP library is used , which is part of the Net-SNMP project . To be honest, the code works on the principle "newbies are lucky" (the tolerant version is "fools are lucky"). I copied the code in some kind of soap sheet (I won't give a link - I didn't find it), finished it a little for my needs, launched it and at the first moment did not even believe my eyes. The Observium I was using at that time polled my, not so large grid (less than 300 switches), for more than a minute, and in four streams (I note right away that a minimum of sensors were used when polling, otherwise the poll could take 5 minutes). And my script did the same thing in 8-10 seconds.
Well, and then the code itself with comments:
use SNMP;
# , @obj_list.
my @obj_list = ('10.0.0.100', '10.0.0.101', '10.0.0.102');
# , .
my %snmpparms;
$snmpparms{Version} = 2;
$snmpparms{Retries} = 1;
$snmpparms{UseSprintValue} = 0;
$snmpparms{Community} = 'public';# :)
# OID.
my @mibs;
push @mibs, SNMP::Varbind->new( [ 'sysObjectID', 0 ] );
push @mibs, SNMP::Varbind->new( [ 'sysName', 0 ] );
push @mibs, SNMP::Varbind->new( [ 'sysLocation', 0 ] );
#
my $vb = SNMP::VarList->new(@mibs);
sub nms_poll {
foreach my $obj (@obj_list) {
my $sess = SNMP::Session->new(
%snmpparms,
DestHost => $obj,
);
$sess->get( $vb, [ \&nms_clb, $obj ] );
&SNMP::MainLoop(2);
}
return 1 if $status;
return undef;
}
# ,
sub nms_clb {
my ( $obj, $vl ) = @_;
# ,
if ( defined $vl->[0] ) {
&SNMP::finish();
}
else {
}
return ();
}
, . SNMP::MainLoop:
to be used with async SNMP::Session calls. MainLoop must be called after initial async calls so return packets from the agent will not be processed. If no args suplied this function enters an infinite loop so program must be exited in a callback or externally interupted.
5.04. "" SNMP, . .
What is written clearly does not attract an article, but rather a note. I wrote it because I feel sorry for the missing developments, which are now becoming unnecessary. Time goes by, the world is changing. Small providers go bankrupt, are absorbed by large players, and switch to agency models. As a result, a lot of accumulated experience simply becomes redundant. I think this is not correct :)