Антоха Р. Posted May 3, 2016 · Report post Доброго времени суток. Подскажите нормальную прогу для снятие трапов со свичей D-Link DGS-3420-26SС? Вставить ник Quote Ответить с цитированием Share this post Link to post Share on other sites More sharing options...
pppoetest Posted May 3, 2016 · Report post Можно стандартный net-snmp. Мне же хватает этого: #!/usr/bin/perl -w use strict; use threads; use Net::SNMPTrapd; use constant THREADS_COUNT => 4; use constant DEBUG => 0; my $server_ip = "X.X.X.X"; my $log_filename = "/var/log/snmptraps.log"; open(STDIN, "+>/dev/null") or die "Can't open STDIN: $!\n"; open(STDOUT, "+>/dev/null") or die "Can't open STDOUT: $!\n"; open(STDERR, "+>>$log_filename") or die "Can't open STDERR: $!\n"; my $obj = Net::SNMPTrapd->new(Family=>'ipv4', LocalAddr=>$server_ip, LocalPort=>162, timeout=>3) or die "Error: ", Net::SNMPTrapd->error; for my $i (1..(THREADS_COUNT - 1)) { threads->create(\&request_loop, $obj); } request_loop($obj); sub request_loop { my $snmptrapd = shift; my $tid = threads->tid(); # thread ID logg($tid, 'START'); my ($ip, $p, $trap); while (1) { $trap = $snmptrapd->get_trap(); unless (defined($trap)) { logg($tid, Net::SNMPTrapd->error); next; } next if ($trap == 0); unless (defined($trap->process_trap())) { logg($tid, Net::SNMPTrapd->error); } else { $ip = $trap->remoteaddr; $p = ""; for my $vals (@{$trap->varbinds}) { for (keys(%{$vals})) { $p .= sprintf "%s: %s; ", $_, $vals->{$_}; } } logg($tid, "[$ip] $p") if (DEBUG == 1); } } } sub logg { my ($tid, $msg) = @_; my $now = POSIX::strftime("%d.%m.%Y %H:%M:%S", localtime); open hFile, ">>", $log_filename; print hFile "$now Thread ($tid): $msg\n"; close hFile; } Вставить ник Quote Ответить с цитированием Share this post Link to post Share on other sites More sharing options...