Jump to content
Калькуляторы

Мониторинг сети

Доброго времени суток. Подскажите нормальную прогу для снятие трапов со свичей D-Link DGS-3420-26SС?

Share this post


Link to post
Share on other sites

Можно стандартный 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;
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.