diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 70a0018f20..e239d3f806 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2013-11-11 Sergio Martin + + * lib/PandoraFMS/Core.pm: Change the format of the comments when + create event from server to adapt it to new json format + 2013-11-08 Ramon Novoa * pandora_server.spec: Copy the new pandora_server.conf.new to /etc/pandora/. diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index f1cd20b65d..c32e6327f8 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -108,7 +108,7 @@ use Time::Local; use POSIX qw(strftime); use threads; use threads::shared; -use JSON qw(decode_json); +use JSON qw(decode_json encode_json); use MIME::Base64; # Debugging @@ -918,14 +918,6 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Field 8 (comments); my $comment = $field8; - if($comment ne '') { - # Get datetime for the comment of the event - my $datetime = strftime( "%F, %H:%M:%S %p", localtime(time)); - - # This format is necessary for the ugly parser of event comments. Will be changed in the future to json - $comment = "-- Added comment by an alert [" . $datetime . "] --
" . $comment . "
"; - } - pandora_event ($pa_config, $event_text, (defined ($agent) ? $agent->{'id_grupo'} : 0), (defined ($fullagent) ? $fullagent->{'id_agente'} : 0), $priority, 0, 0, $event_type, 0, $dbh, $source, '', $comment, $id_extra, $tags); # Validate event (field1: agent name; field2: module name) } elsif ($clean_name eq "Validate Event") { @@ -2587,13 +2579,18 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) { my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); $id_agentmodule = 0 unless defined ($id_agentmodule); + if($comment ne '') { + my @comment_data = ({ comment => $comment, action => "Added comment", id_user => "an alert", utimestamp => $utimestamp}); + $comment = encode_json \@comment_data; + } + # Validate events with the same event id if (defined ($id_extra) && $id_extra ne '') { logger($pa_config, "Updating events with extended id '$id_extra'.", 10); db_do ($dbh, 'UPDATE tevento SET estado = 1, ack_utimestamp = ? WHERE estado = 0 AND id_extra=?', $utimestamp, $id_extra); } - # Update or create the event + # Create the event logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); 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, custom_data) 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, $custom_data);