From 7fb8406bc075f8be9f4d0c07217b2d795a9b5c82 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Fri, 17 Nov 2017 14:50:23 +0100 Subject: [PATCH 1/5] Added several macros to events responses --- pandora_console/include/functions_events.php | 335 ++++++++++++------- 1 file changed, 208 insertions(+), 127 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 763f246bdf..e676a09b48 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1570,18 +1570,6 @@ function events_check_event_filter_group ($id_filter) { return false; } -/** - * Return an array with all the possible macros in event responses - * - * @return array - */ -function events_get_macros() { - return array('_agent_address_' => __('Agent address'), - '_agent_id_' => __('Agent id'), - '_event_id_' => __('Event id'), - '_module_address_' => __('Module Agent address'),); -} - /** * Get a event filter. * @@ -1853,46 +1841,144 @@ function events_get_response_target($event_id, $response_id, $server_id, $histor $target = io_safe_output($event_response['target']); - foreach($macros as $macro) { - $subst = ''; - switch($macro) { - case '_agent_address_': - if ($meta) { - $server = metaconsole_get_connection_by_id ($server_id); - metaconsole_connect($server); - } - - $subst = agents_get_address($event['id_agente']); - - if($meta) { - metaconsole_restore_db_force(); - } - break; - case '_agent_id_': - $subst = $event['id_agente']; - break; - case '_event_id_': - $subst = $event['id_evento']; - break; - case '_module_address_': - if($meta) { - $server = metaconsole_get_connection_by_id ($server_id); - metaconsole_connect($server); - } - - $module = db_get_row("tagente_modulo",'id_agente_modulo', $event['id_agentmodule']); - if ($module['ip_target'] != false) - $subst = $module['ip_target']; - - if($meta) { - metaconsole_restore_db_force(); - } - break; + // Substitute each macro + if (strpos($target, '_agent_address_') !== false) { + if ($meta) { + $server = metaconsole_get_connection_by_id ($server_id); + metaconsole_connect($server); } - $target = str_replace($macro,$subst,$target); + $target = str_replace('_agent_address_', $event['id_agente'], $target); + + if($meta) { + metaconsole_restore_db_force(); + } } + if (strpos($target, '_agent_id_') !== false) { + $target = str_replace('_agent_id_', $event['id_agente'], $target); + } + if ((strpos($target, '_module_address_') !== false) || + (strpos($target, '_module_name_') !== false)) + { + if ($event['id_agentmodule'] !== 0) { + if($meta) { + $server = metaconsole_get_connection_by_id ($server_id); + metaconsole_connect($server); + } + $module = db_get_row("tagente_modulo",'id_agente_modulo', $event['id_agentmodule']); + if (empty($module['ip_target'])) $module['ip_target'] = __('N/A'); + $target = str_replace('_module_address_', $module['ip_target'], $target); + if (empty($module['nombre'])) $module['nombre'] = __('N/A'); + $target = str_replace( + '_module_name_', + io_safe_output($module['nombre']), + $target + ); + + if($meta) { + metaconsole_restore_db_force(); + } + } else { + $target = str_replace('_module_address_', __('N/A'), $target); + $target = str_replace('_module_name_', __('N/A'), $target); + } + } + if (strpos($target, '_event_id_') !== false) { + $target = str_replace('_event_id_', $event['id_evento'], $target); + } + if (strpos($target, '_user_id_') !== false) { + if (!empty($event['id_usuario'])) { + $target = str_replace('_user_id_', $event['id_usuario'], $target); + } else { + $target = str_replace('_user_id_', __('N/A'), $target); + } + } + if (strpos($target, '_group_id_') !== false) { + $target = str_replace('_group_id_', $event['id_grupo'], $target); + } + if (strpos($target, '_group_name_') !== false) { + $target = str_replace( + '_group_name_', + groups_get_name($event['id_grupo'], true), + $target + ); + } + if (strpos($target, '_event_utimestamp_') !== false) { + $target = str_replace('_event_utimestamp_', $event['utimestamp'], $target); + } + if (strpos($target, '_event_date_') !== false) { + $target = str_replace( + '_event_date_', + date ($config["date_format"], strtotime($event["timestamp"])), + $target + ); + } + if (strpos($target, '_event_text_') !== false) { + $target = str_replace( + '_event_text_', + events_display_name($event['evento']), + $target + ); + } + if (strpos($target, '_event_type_') !== false) { + $target = str_replace( + '_event_type_', + events_print_type_description($event['event_type'], true), + $target + ); + } + if (strpos($target, '_alert_id_') !== false) { + $target = str_replace( + '_alert_id_', + empty($event['is_alert_am']) ? __('N/A') : $event['is_alert_am'], + $target + ); + } + if (strpos($target, '_event_severity_id_') !== false) { + $target = str_replace('_event_severity_id_', $event['criticity'], $target); + } + if (strpos($target, '_event_severity_text_') !== false) { + $target = str_replace( + '_event_severity_text_', + get_priority_name($event['criticity']), + $target + ); + } + if (strpos($target, '_module_id_') !== false) { + $target = str_replace('_module_id_', $event['id_agentmodule'], $target); + } + if (strpos($target, '_event_tags_') !== false) { + $target = str_replace('_event_tags_', $event['tags'], $target); + } + if (strpos($target, '_event_extra_id_') !== false) { + if (empty($event['id_extra'])) { + $target = str_replace('_event_extra_id_', __('N/A'), $target); + } else { + $target = str_replace('_event_extra_id_', $event['id_extra'], $target); + } + } + if (strpos($target, '_event_source_') !== false) { + $target = str_replace('_event_source_', $event['source'], $target); + } + if (strpos($target, '_event_instruction_') !== false) { + $target = str_replace( + '_event_instruction_', + events_display_instructions($event['event_type'], $event, false), + $target + ); + } + if (strpos($target, '_owner_user_') !== false) { + if (empty($event['owner_user'])) { + $target = str_replace('_owner_user_', __('N/A'), $target); + } else { + $target = str_replace('_owner_user_', $event['owner_user'], $target); + } + } + if (strpos($target, '_event_status_') !== false) { + $event_st = events_display_status($event['estado']); + $target = str_replace('_event_status_', $event_st["title"], $target); + } return $target; } @@ -2185,69 +2271,12 @@ function events_page_details ($event, $server = "") { $table_details->data[] = $data; } - switch($event['event_type']) { - case 'going_unknown': - $data = array(); - $data[0] = __('Instructions'); - if ($event["unknown_instructions"] != '') { - $data[1] = str_replace("\n","
", io_safe_output($event["unknown_instructions"])); - } - else { - $data[1] = '' . __('N/A') . ''; - } - $table_details->data[] = $data; - break; - case 'going_up_warning': - case 'going_down_warning': - $data = array(); - $data[0] = __('Instructions'); - if ($event["warning_instructions"] != '') { - $data[1] = str_replace("\n","
", io_safe_output($event["warning_instructions"])); - } - else { - $data[1] = '' . __('N/A') . ''; - } - $table_details->data[] = $data; - break; - case 'going_up_critical': - case 'going_down_critical': - $data = array(); - $data[0] = __('Instructions'); - if ($event["critical_instructions"] != '') { - $data[1] = str_replace("\n","
", io_safe_output($event["critical_instructions"])); - } - else { - $data[1] = '' . __('N/A') . ''; - } - $table_details->data[] = $data; - break; - case 'system': - $data = array(); - if ($event["critical_instructions"] != '') { - $data[0] = __('Instructions'); - $data[1] = str_replace("\n","
", io_safe_output($event["critical_instructions"])); - } - else { - if ($event["warning_instructions"] != '') { - $data[0] = __('Instructions'); - $data[1] = str_replace("\n","
", io_safe_output($event["warning_instructions"])); - } - else { - if ($event["unknown_instructions"] != '') { - $data[0] = __('Instructions'); - $data[1] = str_replace("\n","
", io_safe_output($event["unknown_instructions"])); - } - else { - $data[0] = __('Instructions'); - $data[1] = '' . __('N/A') . ''; - - } - } - } - $table_details->data[] = $data; - break; - } + $data = array(); + $data[0] = __('Instructions'); + $data[1] = events_display_instructions ($event['event_type'], $events, true); + $table_details->data[] = $data; + $data = array(); $data[0] = __('Extra id'); if ($event["id_extra"] != '') { @@ -2311,6 +2340,72 @@ function events_page_custom_data ($event) { return $custom_data; } +// Get the event name from tevento and display it in console +function events_display_name ($db_name = '') { + return io_safe_output(str_replace ( ' ' , '
' , $db_name)); +} + +// Get the image and status value of event +function events_display_status ($status) { + switch($status) { + case 0: + return array( + "img" => "images/star.png", + "title" => __('New event') + ); + case 1: + return array( + "img" => "images/tick.png", + "title" => __('Event validated') + ); + case 2: + return array( + "img" => "images/hourglass.png", + "title" => __('Event in process') + ); + } +} + +// Get the instruction of an event +// $event_type: Type of event +// $inst: Array with unknown warning and critical instructions +// $italic: Display N/A between italic html marks if instruction is not found +function events_display_instructions ($event_type = '', $inst, $italic = true) { + switch($event_type) { + case 'going_unknown': + if ($inst["unknown_instructions"] != '') { + return str_replace("\n","
", io_safe_output($inst["unknown_instructions"])); + } + break; + case 'going_up_warning': + case 'going_down_warning': + if ($inst["warning_instructions"] != '') { + return str_replace("\n","
", io_safe_output($inst["warning_instructions"])); + } + break; + case 'going_up_critical': + case 'going_down_critical': + if ($inst["critical_instructions"] != '') { + return str_replace("\n","
", io_safe_output($inst["critical_instructions"])); + } + break; + case 'system': + $data = array(); + if ($inst["critical_instructions"] != '') { + return str_replace("\n","
", io_safe_output($inst["critical_instructions"])); + } + if ($inst["warning_instructions"] != '') { + return str_replace("\n","
", io_safe_output($inst["warning_instructions"])); + } + if ($inst["unknown_instructions"] != '') { + return str_replace("\n","
", io_safe_output($inst["unknown_instructions"])); + } + break; + } + $na_return = $italic ? '' . __('N/A') . '' : __('N/A'); + return $na_return; +} + function events_page_general ($event) { global $img_sev; global $config; @@ -2337,8 +2432,7 @@ function events_page_general ($event) { $data = array(); $data[0] = __('Event name'); - $event["evento"] = str_replace ( ' ' , '
' , $event["evento"]); - $data[1] = io_safe_output($event["evento"]); + $data[1] = events_display_name ($event["evento"]); $table_general->data[] = $data; $data = array(); @@ -2400,24 +2494,11 @@ function events_page_general ($event) { $table_general->data[] = $data; // Get Status - switch($event['estado']) { - case 0: - $img_st = "images/star.png"; - $title_st = __('New event'); - break; - case 1: - $img_st = "images/tick.png"; - $title_st = __('Event validated'); - break; - case 2: - $img_st = "images/hourglass.png"; - $title_st = __('Event in process'); - break; - } + $event_st = events_display_status ($event['estado']); $data = array(); $data[0] = __('Status'); - $data[1] = html_print_image($img_st,true).' '.$title_st; + $data[1] = html_print_image($event_st["img"],true).' '.$event_st["title"]; $table_general->data[] = $data; // If event is validated, show who and when acknowleded it From 492b55a713dd029bb1257da068137b0ce20d6606 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Fri, 17 Nov 2017 15:17:08 +0100 Subject: [PATCH 2/5] Added custom_data to events responeses macros --- pandora_console/include/functions_events.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index e676a09b48..a3094b19e0 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1979,6 +1979,13 @@ function events_get_response_target($event_id, $response_id, $server_id, $histor $event_st = events_display_status($event['estado']); $target = str_replace('_event_status_', $event_st["title"], $target); } + // Parse the event custom data + if (!empty($event['custom_data'])){ + $custom_data = json_decode (base64_decode ($event['custom_data'])); + foreach ($custom_data as $key => $value) { + $target = str_replace('_customdata_' . $key . '_', $value, $target); + } + } return $target; } From 2ef9d884ee7c6a08d6693b10b8790b389806b3a9 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Mon, 20 Nov 2017 11:14:26 +0100 Subject: [PATCH 3/5] Added spanish event responses new macros documentation --- pandora_console/include/functions_events.php | 2 -- .../include/help/es/help_response_macros.php | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index a3094b19e0..826aa26c74 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1837,8 +1837,6 @@ function events_get_response_target($event_id, $response_id, $server_id, $histor $event = db_get_row($event_table,'id_evento', $event_id); - $macros = array_keys(events_get_macros()); - $target = io_safe_output($event_response['target']); // Substitute each macro diff --git a/pandora_console/include/help/es/help_response_macros.php b/pandora_console/include/help/es/help_response_macros.php index a8c3556ba8..6644208c13 100644 --- a/pandora_console/include/help/es/help_response_macros.php +++ b/pandora_console/include/help/es/help_response_macros.php @@ -13,9 +13,34 @@ Las macros aceptadas son las siguientes:
  • Dirección del agente: _agent_address_
  • Id del agente: _agent_id_
  • +
  • Id de la alerta asociada al evento: _alert_id_
  • +
  • Fecha en la que se produjo el evento: _event_date_
  • +
  • Id extra: _event_extra_id_
  • Id del evento: _event_id_
  • +
  • Instrucciones del evento: _event_instruction_
  • +
  • Id de la criticidad del evento: _event_severity_id_
  • +
  • Gravedad del evento (traducido por la consola de Pandora): _event_severity_text_
  • +
  • Procedencia del evento: _event_source_
  • +
  • Estado del evento (Nuevo, validado o evento en proceso : _event_status_
  • +
  • Etiquetas del evento separadas por comas: _event_tags_
  • +
  • Texto completo del evento: _event_text_
  • +
  • Tipo del evento (Sistema, Cambiando a estado desconocido...): _event_type_
  • +
  • Fecha en la que se produjo el evento en formato utimestamp: _event_utimestamp_
  • +
  • Id del grupo: _group_id_
  • +
  • Nombre del grupo en base de datos: _group_name_
  • +
  • Dirección del módulo asociado al evento: _module_address_
  • +
  • Id del módulo asociado al evento: _module_id_
  • +
  • Nombre del módulo asociado al evento: _module_name_
  • +
  • Usuario propietario del evento: _owner_user_
  • +
  • Id del usuario: _user_id_
+

Campos personalizados

+Los campos personalizados del evento también están disponibles en las macros de +respuestas de eventos. Tendrían la forma de _customdata_*_ donde habría +que sustituir el asterisco (*) por la clave del campo personalizado que se desee +utilizar. +

Uso básico

Por ejemplo, para hacer un ping al agente asociado al evento:

From 2425d19dddae579e89c5c0bec321caf55b12f80f Mon Sep 17 00:00:00 2001 From: fermin831 Date: Mon, 20 Nov 2017 11:16:18 +0100 Subject: [PATCH 4/5] Fixed typo --- pandora_console/include/help/es/help_response_macros.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/help/es/help_response_macros.php b/pandora_console/include/help/es/help_response_macros.php index 6644208c13..a32f99c8e1 100644 --- a/pandora_console/include/help/es/help_response_macros.php +++ b/pandora_console/include/help/es/help_response_macros.php @@ -21,7 +21,7 @@ Las macros aceptadas son las siguientes:
  • Id de la criticidad del evento: _event_severity_id_
  • Gravedad del evento (traducido por la consola de Pandora): _event_severity_text_
  • Procedencia del evento: _event_source_
  • -
  • Estado del evento (Nuevo, validado o evento en proceso : _event_status_
  • +
  • Estado del evento (Nuevo, validado o evento en proceso): _event_status_
  • Etiquetas del evento separadas por comas: _event_tags_
  • Texto completo del evento: _event_text_
  • Tipo del evento (Sistema, Cambiando a estado desconocido...): _event_type_
  • From f02166433670b8d162fc645ea47ca3eb185a18da Mon Sep 17 00:00:00 2001 From: fermin831 Date: Mon, 20 Nov 2017 15:06:20 +0100 Subject: [PATCH 5/5] Added new events response macros documentation --- .../include/help/en/help_response_macros.php | 45 ++++++++++++++----- .../include/help/ja/help_response_macros.php | 25 +++++++++++ 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/help/en/help_response_macros.php b/pandora_console/include/help/en/help_response_macros.php index 95650884d9..78098d8c0b 100644 --- a/pandora_console/include/help/en/help_response_macros.php +++ b/pandora_console/include/help/en/help_response_macros.php @@ -5,27 +5,52 @@ ?>Event responses macros

    -The response target (command or URL) accepts macros to custom it. +The response target (command or URL) accepts macros to customize it.

    -The macros accepted are the following: +The accepted macros are:

    • Agent address: _agent_address_
    • -
    • Agent id: _agent_id_
    • -
    • Event id: _event_id_
    • +
    • Agent ID: _agent_id_
    • +
    • Event related alert ID: _alert_id_
    • +
    • Date on which the event occurred: _event_date_
    • +
    • Extra ID: _event_extra_id_
    • +
    • Event ID: _event_id_
    • +
    • Event instructions: _event_instruction_
    • +
    • Event severity ID: _event_severity_id_
    • +
    • Event severity (translated by Pandora console): _event_severity_text_
    • +
    • Event source: _event_source_
    • +
    • Event status (new, validated or event in process): _event_status_
    • +
    • Event tags separated by commas: _event_tags_
    • +
    • Full text of the event: _event_text_
    • +
    • Event type (System, going into Unknown Status...): _event_type_
    • +
    • Date on which the event occurred in utimestamp format: _event_utimestamp_
    • +
    • Group ID: _group_id_
    • +
    • Group name in database: _group_name_
    • +
    • Event associated module address: _module_address_
    • +
    • Event associated module ID: _module_id_
    • +
    • Event associated module name: _module_name_
    • +
    • Event owner user: _owner_user_
    • +
    • User ID: _user_id_
    +

    Custom fields

    + +Custom event fields are also available in event response macros. They would +have _customdata_*_ form where the asterisk (*) would have to be +replaced by the custom field key you want to use. +

    Basic use

    -In example, to ping the agent associated to the event: +For example, to ping the agent associated with the event:

    -Configure command like: ping -c 5 _agent_address_ +Configure the command as follows: ping -c 5 _agent_address_

    -If there are configured parameters, is possible use it as macros too. +If there are configured parameters, it is possible to use them as macros, too.

    Parameters macros

    -In example, to custom a URL with parameters: +For example, to customize a URL with parameters:

    -Configure parameters like: User,Section +Configure the parameters as follows: User,Section

    -And configure the URL like: http://example.com/index.php?user=_User_&section=_Section_ +And configure the URL like this: http://example.com/index.php?user=_User_&section=_Section_

    diff --git a/pandora_console/include/help/ja/help_response_macros.php b/pandora_console/include/help/ja/help_response_macros.php index ed8b16fa01..68603876e9 100644 --- a/pandora_console/include/help/ja/help_response_macros.php +++ b/pandora_console/include/help/ja/help_response_macros.php @@ -12,9 +12,34 @@
    • エージェントアドレス: _agent_address_
    • エージェントID: _agent_id_
    • +
    • Event related alert ID: _alert_id_
    • +
    • Date on which the event occurred: _event_date_
    • +
    • Extra ID: _event_extra_id_
    • イベントID: _event_id_
    • +
    • Event instructions: _event_instruction_
    • +
    • Event severity ID: _event_severity_id_
    • +
    • Event severity (translated by Pandora console): _event_severity_text_
    • +
    • Event source: _event_source_
    • +
    • Event status (new, validated or event in process): _event_status_
    • +
    • Event tags separated by commas: _event_tags_
    • +
    • Full text of the event: _event_text_
    • +
    • Event type (System, going into Unknown Status...): _event_type_
    • +
    • Date on which the event occurred in utimestamp format: _event_utimestamp_
    • +
    • Group ID: _group_id_
    • +
    • Group name in database: _group_name_
    • +
    • Event associated module address: _module_address_
    • +
    • Event associated module ID: _module_id_
    • +
    • Event associated module name: _module_name_
    • +
    • Event owner user: _owner_user_
    • +
    • User ID: _user_id_
    +

    Custom fields

    + +Custom event fields are also available in event response macros. They would +have _customdata_*_ form where the asterisk (*) would have to be +replaced by the custom field key you want to use. +

    基本的な利用方法

    例として、イベントに関連付けしたエージェントへの ping を示します。