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

* lib/PandoraFMS/Core.pm: Resolve numeric ids to strings before writing
	  events to an external log file.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8444 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2013-07-01 17:03:36 +00:00
parent 3ff6dc86f1
commit 3851224d18
2 changed files with 27 additions and 11 deletions

View File

@ -1,3 +1,8 @@
2013-07-01 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Core.pm: Resolve numeric ids to strings before writing
events to an external log file.
2013-07-01 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Config.pm,

View File

@ -2518,21 +2518,20 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) {
my ($pa_config, $evento, $id_grupo, $id_agente, $severity,
$id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra, $tags, $critical_instructions, $warning_instructions, $unknown_instructions) = @_;
my $agent = undef;
if ($id_agente != 0) {
my $agent = get_db_single_row ($dbh, 'SELECT *
FROM tagente WHERE id_agente = ?', $id_agente);
if ($agent->{'quiet'} == 1) {
$agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $id_agente);
if (defined ($agent) && $agent->{'quiet'} == 1) {
logger($pa_config, "Generate Event. The agent '" . $agent->{'nombre'} . "' is in quiet mode.", 10);
return;
}
}
if ($id_agentmodule != 0) {
my $module = get_db_single_row ($dbh, 'SELECT *
FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agentmodule);
if ($module->{'quiet'} == 1) {
logger($pa_config, "Generate Event. The module '" . $module->{'nombre'} . "' is in quiet mode.", 10);
my $module = undef;
if ($id_agentmodule != 0) {
$module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agentmodule);
if (defined ($module) && $module->{'quiet'} == 1) {
logger($pa_config, "Generate Event. The module '" . $module->{'nombre'} . "' is in quiet mode.", 10);
return;
}
}
@ -2576,7 +2575,7 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) {
# 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";
$header = "agent_name,group_name,evento,timestamp,estado,utimestamp,event_type,module_name,alert_name,criticity,user_comment,tags,source,id_extra,id_usuario,critical_instructions,warning_instructions,unknown_instructions,ack_utimestamp";
}
# Open the event file for writing
@ -2585,12 +2584,24 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) {
return;
}
# Resolve ids
my $group_name = get_group_name ($dbh, $id_grupo);
$group_name = '' unless defined ($group_name);
my $agent_name = defined ($agent) ? safe_output ($agent->{'nombre'}) : '';
my $module_name = defined ($module) ? safe_output ($module->{'nombre'}) : '';
my $alert_name = get_db_value ($dbh, 'SELECT name FROM talert_templates, talert_template_modules WHERE talert_templates.id = talert_template_modules.id_alert_template AND talert_template_modules.id = ?', $id_alert_am);
if (defined ($alert_name)) {
$alert_name = safe_output ($alert_name);
} else {
$alert_name = '';
}
# 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";
print EVENT_FILE "$agent_name,$group_name," . safe_output ($evento) . ",$timestamp,$event_status,$utimestamp,$event_type,$module_name,$alert_name,$severity,$comment,$module_tags,$source,$id_extra,$user_name,$critical_instructions,$warning_instructions,$unknown_instructions,$ack_utimestamp\n";
close (EVENT_FILE);
}