2013-07-01 Ramon Novoa <rnovoa@artica.es>

* 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
This commit is contained in:
ramonn 2013-07-01 14:05:44 +00:00
parent a3bdcd0466
commit 23d4b3fd8a
4 changed files with 41 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2013-07-01 Ramon Novoa <rnovoa@artica.es>
* 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 <slerena@artica.es> 2013-06-26 Sancho Lerena <slerena@artica.es>
* util/plugin/pandora_loadgen.pl, * util/plugin/pandora_loadgen.pl,

View File

@ -412,3 +412,6 @@ event_replication 0
event_auto_validation 1 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

View File

@ -300,7 +300,10 @@ sub pandora_load_config {
# Event auto-validation # Event auto-validation
$pa_config->{"event_auto_validation"} = 1; # 5.0 $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 are not stored in .conf files.
# This values should be stored in database, not 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) { elsif ($parametro =~ m/^event_auto_validation\s+([0-1])/i) {
$pa_config->{'event_auto_validation'}= clean_blank($1); $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 # } # end of loop for parameter #
# Set to RDBMS' standard port # Set to RDBMS' standard port

View File

@ -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) 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); 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);
} }
########################################################################## ##########################################################################