From 23d4b3fd8a842596c879dafc8faa4f1ab0d95c17 Mon Sep 17 00:00:00 2001 From: ramonn Date: Mon, 1 Jul 2013 14:05:44 +0000 Subject: [PATCH] 2013-07-01 Ramon Novoa * lib/PandoraFMS/Config.pm, lib/PandoraFMS/Core.pm, conf/pandora_server.conf.new: Added support for writing events to an external log file. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8442 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 ++++++ pandora_server/conf/pandora_server.conf.new | 3 +++ pandora_server/lib/PandoraFMS/Config.pm | 8 ++++++- pandora_server/lib/PandoraFMS/Core.pm | 24 +++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index b02e1feefc..90fb981149 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2013-07-01 Ramon Novoa + + * lib/PandoraFMS/Config.pm, + lib/PandoraFMS/Core.pm, + conf/pandora_server.conf.new: Added support for writing events to an + external log file. + 2013-06-26 Sancho Lerena * util/plugin/pandora_loadgen.pl, diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index a312857a4b..2602ad9804 100755 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -412,3 +412,6 @@ event_replication 0 event_auto_validation 1 +# If defined, events generated by Pandora FMS will be written to the specified text file. +#event_file /var/log/pandora/pandora_events.txt + diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 2f3273106c..5243e62301 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -300,7 +300,10 @@ sub pandora_load_config { # Event auto-validation $pa_config->{"event_auto_validation"} = 1; # 5.0 - + + # Export events to a text file + $pa_config->{"event_file"} = ''; # 5.0 + # ------------------------------------------------------------------------- # This values are not stored in .conf files. # This values should be stored in database, not in .conf files! @@ -657,6 +660,9 @@ sub pandora_load_config { elsif ($parametro =~ m/^event_auto_validation\s+([0-1])/i) { $pa_config->{'event_auto_validation'}= clean_blank($1); } + elsif ($parametro =~ m/^event_file\s+(.*)/i) { + $pa_config->{'event_file'}= clean_blank($1); + } } # end of loop for parameter # # Set to RDBMS' standard port diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 5237c1b428..c6f9487ed2 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -2569,6 +2569,30 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) { db_do ($dbh, 'INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp); + + # Do not write to the event file + return if ($pa_config->{'event_file'} eq ''); + + # Add a header when the event file is created + my $header = undef; + if (! -f $pa_config->{'event_file'}) { + $header = "id_agente,id_grupo,evento,timestamp,estado,utimestamp,event_type,id_agentmodule,id_alert_am,criticity,user_comment,tags,source,id_extra,id_usuario,critical_instructions,warning_instructions,unknown_instructions,ack_utimestamp"; + } + + # Open the event file for writing + if (! open (EVENT_FILE, '>>' . $pa_config->{'event_file'})) { + logger($pa_config, "Error opening event file " . $pa_config->{'event_file'} . ": $!", 10); + return; + } + + # Get an exclusive lock on the file (LOCK_EX) + flock (EVENT_FILE, 2); + + # Write the event + print EVENT_FILE "$header\n" if (defined ($header)); + print EVENT_FILE "$id_agente,$id_grupo," . safe_input ($evento) . ",$timestamp,$event_status,$utimestamp,$event_type,$id_agentmodule,$id_alert_am,$severity,$comment,$module_tags,$source,$id_extra,$user_name,$critical_instructions,$warning_instructions,$unknown_instructions,$ack_utimestamp\n"; + + close (EVENT_FILE); } ##########################################################################