mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
2013-03-05 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm: Added an option to start the snmptrapd daemon manually. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7788 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
2aef529f1d
commit
b31630b986
@ -1,3 +1,8 @@
|
|||||||
|
2013-03-05 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* lib/PandoraFMS/SNMPServer.pm: Added an option to start the snmptrapd
|
||||||
|
daemon manually.
|
||||||
|
|
||||||
2013-03-05 Sergio Martin <sergio.martin@artica.es>
|
2013-03-05 Sergio Martin <sergio.martin@artica.es>
|
||||||
|
|
||||||
* lib/PandoraFMS/Core.pm: Add the new fields on snmp alerts
|
* lib/PandoraFMS/Core.pm: Add the new fields on snmp alerts
|
||||||
|
@ -47,42 +47,16 @@ sub new ($$;$) {
|
|||||||
return undef unless $config->{'snmpconsole'} == 1;
|
return undef unless $config->{'snmpconsole'} == 1;
|
||||||
|
|
||||||
# Start snmptrapd
|
# Start snmptrapd
|
||||||
|
if (start_snmptrapd ($config) != 0) {
|
||||||
my $pid_file = '/var/run/pandora_snmptrapd.pid';
|
|
||||||
|
|
||||||
my $snmptrapd_running = 0;
|
|
||||||
|
|
||||||
if ( -e $pid_file && open (PIDFILE, $pid_file)) {
|
|
||||||
my $pid = <PIDFILE> + 0;
|
|
||||||
close PIDFILE;
|
|
||||||
|
|
||||||
# Check if snmptrapd is running
|
|
||||||
if ($snmptrapd_running = kill (0, $pid)) {
|
|
||||||
logger ($config, "snmptrapd (pid $pid) is already running, attempting to kill it...", 1);
|
|
||||||
print_message ($config, "snmptrapd (pid $pid) is already running, attempting to kill it...", 1);
|
|
||||||
kill (9, $pid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Ignore auth failure traps
|
|
||||||
my $snmp_ignore_authfailure = ($config->{'snmp_ignore_authfailure'} eq '1' ? ' -a' : '');
|
|
||||||
|
|
||||||
# Select agent-addr field of the PDU or PDU source address for V1 traps
|
|
||||||
my $address_format = ($config->{'snmp_pdu_address'} eq '0' ? '%a' : '%b');
|
|
||||||
|
|
||||||
my $snmptrapd_args = ' -t -On -n' . $snmp_ignore_authfailure . ' -Lf ' . $config->{'snmp_logfile'} . ' -p ' . $pid_file;
|
|
||||||
$snmptrapd_args .= ' --format1=SNMPv1[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]' . $address_format . '[**]%N[**]%w[**]%W[**]%q[**]%v\\\n';
|
|
||||||
$snmptrapd_args .= ' --format2=SNMPv2[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%b[**]%v\\\n';
|
|
||||||
|
|
||||||
if (system ($config->{'snmp_trapd'} . $snmptrapd_args . ' >/dev/null 2>&1') != 0) {
|
|
||||||
logger ($config, " [E] Could not start snmptrapd.", 1);
|
|
||||||
print_message ($config, " [E] Could not start snmptrapd.", 1);
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Call the constructor of the parent class
|
# Call the constructor of the parent class
|
||||||
my $self = $class->SUPER::new($config, 2, $dbh);
|
my $self = $class->SUPER::new($config, 2, $dbh);
|
||||||
|
|
||||||
|
# Save the path of snmptrapd
|
||||||
|
$self->{'snmp_trapd'} = $config->{'snmp_trapd'};
|
||||||
|
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
@ -223,8 +197,10 @@ sub pandora_snmptrapd {
|
|||||||
sub stop () {
|
sub stop () {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
system ('kill -9 `cat /var/run/pandora_snmptrapd.pid 2> /dev/null`');
|
if ($self->{'snmp_trapd'} ne 'manual') {
|
||||||
unlink ('/var/run/pandora_snmptrapd.pid');
|
system ('kill -9 `cat /var/run/pandora_snmptrapd.pid 2> /dev/null`');
|
||||||
|
unlink ('/var/run/pandora_snmptrapd.pid');
|
||||||
|
}
|
||||||
|
|
||||||
$self->SUPER::stop ();
|
$self->SUPER::stop ();
|
||||||
}
|
}
|
||||||
@ -256,5 +232,60 @@ sub matches_filter ($$$) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
# Start snmptrapd, attempting to kill it if it is already running. Returns 0 if
|
||||||
|
# successful, 1 otherwise.
|
||||||
|
########################################################################################
|
||||||
|
sub start_snmptrapd ($) {
|
||||||
|
my ($config) = @_;
|
||||||
|
|
||||||
|
my $pid_file = '/var/run/pandora_snmptrapd.pid';
|
||||||
|
my $snmptrapd_running = 0;
|
||||||
|
|
||||||
|
# Manual start of snmptrapd
|
||||||
|
if ($config->{'snmp_trapd'} eq 'manual') {
|
||||||
|
logger ($config, "No SNMP trap daemon configured. Start snmptrapd manually.", 1);
|
||||||
|
print_message ($config, " [*] No SNMP trap daemon configured. Start snmptrapd manually.", 1);
|
||||||
|
|
||||||
|
if (! -f $config->{'snmp_logfile'}) {
|
||||||
|
logger ($config, "SNMP log file " . $config->{'snmp_logfile'} . " not found.", 1);
|
||||||
|
print_message ($config, " [E] SNMP log file " . $config->{'snmp_logfile'} . " not found.", 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( -e $pid_file && open (PIDFILE, $pid_file)) {
|
||||||
|
my $pid = <PIDFILE> + 0;
|
||||||
|
close PIDFILE;
|
||||||
|
|
||||||
|
# Check if snmptrapd is running
|
||||||
|
if ($snmptrapd_running = kill (0, $pid)) {
|
||||||
|
logger ($config, "snmptrapd (pid $pid) is already running, attempting to kill it...", 1);
|
||||||
|
print_message ($config, "snmptrapd (pid $pid) is already running, attempting to kill it...", 1);
|
||||||
|
kill (9, $pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ignore auth failure traps
|
||||||
|
my $snmp_ignore_authfailure = ($config->{'snmp_ignore_authfailure'} eq '1' ? ' -a' : '');
|
||||||
|
|
||||||
|
# Select agent-addr field of the PDU or PDU source address for V1 traps
|
||||||
|
my $address_format = ($config->{'snmp_pdu_address'} eq '0' ? '%a' : '%b');
|
||||||
|
|
||||||
|
my $snmptrapd_args = ' -t -On -n' . $snmp_ignore_authfailure . ' -Lf ' . $config->{'snmp_logfile'} . ' -p ' . $pid_file;
|
||||||
|
$snmptrapd_args .= ' --format1=SNMPv1[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]' . $address_format . '[**]%N[**]%w[**]%W[**]%q[**]%v\\\n';
|
||||||
|
$snmptrapd_args .= ' --format2=SNMPv2[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%b[**]%v\\\n';
|
||||||
|
|
||||||
|
if (system ($config->{'snmp_trapd'} . $snmptrapd_args . ' >/dev/null 2>&1') != 0) {
|
||||||
|
logger ($config, " [E] Could not start snmptrapd.", 1);
|
||||||
|
print_message ($config, " [E] Could not start snmptrapd.", 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
__END__
|
__END__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user