Merge branch 'ent-8690-gestion-snmptraps-pandora_db' into 'develop'

Set new mode for manage properly the restarting of snmptrap process

See merge request artica/pandorafms!4905
This commit is contained in:
Daniel Rodriguez 2022-06-21 13:59:24 +00:00
commit be49005441
3 changed files with 39 additions and 13 deletions

View File

@ -40,6 +40,7 @@ use PandoraFMS::ProducerConsumerServer;
# Inherits from PandoraFMS::ProducerConsumerServer
our @ISA = qw(PandoraFMS::ProducerConsumerServer);
our @EXPORT = qw(start_snmptrapd);
# Global variables
my @TaskQueue :shared;
@ -442,12 +443,14 @@ sub start_snmptrapd ($) {
# 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);
my $noSNMPTrap = "No SNMP trap daemon configured. Start snmptrapd manually.";
logger ($config, $noSNMPTrap, 1);
print_message ($config, " [*] $noSNMPTrap", 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);
my $noLogFile = "SNMP log file " . $config->{'snmp_logfile'} . " not found.";
logger ($config, $noLogFile, 1);
print_message ($config, " [E] $noLogFile", 1);
return 1;
}
@ -460,8 +463,9 @@ sub start_snmptrapd ($) {
# 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);
my $alreadyRunning = "snmptrapd (pid $pid) is already running, attempting to kill it...";
logger ($config, $alreadyRunning, 1);
print_message ($config, " [*] $alreadyRunning ", 1);
kill (9, $pid);
}
}
@ -477,11 +481,14 @@ sub start_snmptrapd ($) {
$snmptrapd_args .= ' --format2=SNMPv2[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%b[**]%v\\\n';
if (system ($config->{'snmp_trapd'} . $snmptrapd_args . " >$DEVNULL 2>&1") != 0) {
logger ($config, " [E] Could not start snmptrapd.", 1);
print_message ($config, " [E] Could not start snmptrapd.", 1);
my $showError = "Could not start snmptrapd.";
logger ($config, $showError, 1);
print_message ($config, " [E] $showError ", 1);
return 1;
}
print_message ($config, " [*] snmptrapd started and running.", 1);
return 0;
}

View File

@ -49,11 +49,15 @@
}
/var/log/pandora/pandora_snmptrap.log {
su pandora apache
weekly
missingok
size 500000
rotate 1
maxage 30
notifempty
postrotate
pandora_manage /etc/pandora/pandora_server.conf --start_snmptrapd > /dev/null 2>/dev/null || true
endscript
copytruncate
}

View File

@ -231,6 +231,7 @@ sub help_screen{
print "\nTOOLS:\n\n" unless $param ne '';
help_screen_line('--exec_from_file', '<file_path> <option_to_execute> <option_params>', "Execute any CLI option \n\t with macros from CSV file");
help_screen_line('--create_snmp_trap', '<name> <oid> <description> <severity>', "Create a new trap definition. \n\tSeverity 0 (Maintenance), 1(Info) , 2 (Normal), 3 (Warning), 4 (Critical), 5 (Minor) and 6 (Major)");
help_screen_line('--start_snmptrapd', '[no parameters needed]', "Start the snmptrap process or restart if it is running");
print "\nSETUP:\n\n" unless $param ne '';
help_screen_line('--set_event_storm_protection', '<value>', "Enable (1) or disable (0) event \n\t storm protection");
@ -1188,6 +1189,16 @@ sub cli_enable_group() {
pandora_enable_group ($conf, $dbh, $id_group);
}
##############################################################################
# Start snmptrap process.
# Related option: --start_snmptrapd
##############################################################################
sub cli_start_snmptrapd() {
use PandoraFMS::SNMPServer;
print_log "[INFO] Starting snmptrap process. \n";
PandoraFMS::SNMPServer::start_snmptrapd(\%conf);
}
##############################################################################
# Create an agent.
# Related option: --created_agent
@ -7546,6 +7557,10 @@ sub pandora_manage_main ($$$) {
param_check($ltotal, 1);
cli_enable_group();
}
elsif ($param eq '--start_snmptrapd') {
#param_check($ltotal, 0);
cli_start_snmptrapd();
}
elsif ($param eq '--create_agent') {
param_check($ltotal, 8, 4);
cli_create_agent();