diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index b875382a85..b46c5eb194 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -1,5 +1,4 @@ START TRANSACTION; -<<<<<<< HEAD ALTER TABLE `tncm_queue` ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`; @@ -1049,7 +1048,8 @@ SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE ` -- Try to insert INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version); -======= +ALTER TABLE `tevento` +ADD COLUMN `event_custom_id` TEXT NULL AFTER `module_status`; -- Telegram and vonage default alerts UPDATE talert_actions SET field2='[PANDORA] Alert FIRED on _agent_ / _module_ / _timestamp_ / _data_' @@ -1057,10 +1057,12 @@ UPDATE talert_actions UPDATE talert_actions SET field2='[PANDORA] Alert FIRED on _agent_ / _module_ / _timestamp_ / _data_' WHERE id=11; ->>>>>>> develop -- Delete table tagent_access DROP TABLE tagent_access; +ALTER TABLE `tevent_rule` DROP COLUMN `user_comment`; +ALTER TABLE `tevent_rule` DROP COLUMN `operator_user_comment`; + ALTER TABLE treport_content ADD check_unknowns_graph tinyint DEFAULT 0 NULL; -- Update macros for plugin oracle @@ -1075,5 +1077,9 @@ INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` (`id_task`, `macro`, `type`, ` INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` (`id_task`, `macro`, `type`, `value`, `temp_conf`) SELECT id_rt, '_clientPath_', 'custom', '', 0 FROM `trecon_task` WHERE `id_app` = @id_app; UPDATE `trecon_task` SET `setup_complete` = 1 WHERE `id_app` = @id_app; +ALTER TABLE `tdashboard` +ADD COLUMN `date_range` TINYINT NOT NULL DEFAULT 0 AFTER `cells_slideshow`, +ADD COLUMN `date_from` INT NOT NULL DEFAULT 0 AFTER `date_range`, +ADD COLUMN `date_to` INT NOT NULL DEFAULT 0 AFTER `date_from`; COMMIT; diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 5c21fa71a0..c3772c00d3 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -38,6 +38,7 @@ $isFunctionPolicies = enterprise_include_once('include/functions_policies.php'); require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_servers.php'; +require_once $config['homedir'].'/include/functions_macros.php'; $search_string = get_parameter('search_string'); @@ -949,7 +950,23 @@ if ($modules !== false) { ); if (strlen($module['ip_target']) !== 0) { - $title .= '
IP: '.$module['ip_target']; + // Check if value is custom field. + if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') { + $custom_field_name = substr($module['ip_target'], 1, -1); + $custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name); + if (isset($custom_value) && $custom_value !== false) { + $title .= '
IP: '.$custom_value; + } else { + $array_macros = return_agent_macros($id_agente); + if (isset($array_macros[$module['ip_target']])) { + $title .= '
IP: '.$array_macros[$module['ip_target']]; + } else { + $title .= '
IP: '.$module['ip_target']; + } + } + } else { + $title .= '
IP: '.$module['ip_target']; + } } // This module is initialized ? (has real data). diff --git a/pandora_console/godmode/events/custom_events.php b/pandora_console/godmode/events/custom_events.php index c91a2df8fe..4ab84fa76b 100644 --- a/pandora_console/godmode/events/custom_events.php +++ b/pandora_console/godmode/events/custom_events.php @@ -115,6 +115,7 @@ $fields_available['module_status'] = __('Module Status'); $fields_available['mini_severity'] = __('Severity mini'); $fields_available['module_custom_id'] = __('Module custom ID'); $fields_available['custom_data'] = __('Custom data'); +$fields_available['event_custom_id'] = __('Event Custom ID'); // Remove fields already selected. diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 47c78d8a18..7aa0c5d66d 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -733,7 +733,7 @@ $table->data[$i++][] = html_print_label_input_block( ); $help_tip = ui_print_help_tip( - __('If there are any "In process" events with a specific Extra ID and a New event with that Extra ID is received, it will be created as "In process" instead.'), + __('If there are any "In process" events with a specific Extra ID and a New event with that Extra ID is received, it will be created as "In process" instead. The new events also inherit Event Custom ID'), true ); diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 881ef22f39..efb3e0deb4 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -92,6 +92,7 @@ $get_id_source_event = get_parameter('get_id_source_event'); $node_id = (int) get_parameter('node_id', 0); $settings_modal = get_parameter('settings', 0); $parameters_modal = get_parameter('parameters', 0); +$update_event_custom_id = get_parameter('update_event_custom_id', 0); $draw_events_graph = get_parameter('drawEventsGraph', false); // User private filter. @@ -2754,6 +2755,52 @@ if ($draw_row_response_info === true) { return; } +if ($update_event_custom_id) { + $event_custom_id = get_parameter('event_custom_id'); + $event_id = get_parameter('event_id'); + $server_id = 0; + if (is_metaconsole() === true) { + $server_id = (int) get_parameter('server_id'); + } + + // Safe custom fields for hacks. + if (preg_match('/script/i', io_safe_output($event_custom_id))) { + $return = false; + } else { + try { + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node = new Node($server_id); + $node->connect(); + } + + $return = events_event_custom_id( + $event_id, + $event_custom_id + ); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node->disconnect(); + } + + $return = false; + } finally { + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node->disconnect(); + } + } + } + + echo ($return === true) ? 'update_ok' : 'update_error'; + return; +} + if ((bool) $draw_events_graph === true) { $filter = get_parameter('filter'); $output = event_print_graph($filter); diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index f3e6627388..e4eba79858 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -35,6 +35,7 @@ if (check_login()) { include_once $config['homedir'].'/include/functions_agents.php'; include_once $config['homedir'].'/include/functions_modules.php'; include_once $config['homedir'].'/include/functions_ui.php'; + include_once $config['homedir'].'/include/functions_macros.php'; enterprise_include_once('include/functions_metaconsole.php'); $get_plugin_macros = get_parameter('get_plugin_macros'); @@ -1206,7 +1207,23 @@ if (check_login()) { ); if (strlen($module['ip_target']) !== 0) { - $title .= '
IP: '.$module['ip_target']; + // Check if value is custom field. + if ($module['ip_target'][0] == '_' && $module['ip_target'][(strlen($module['ip_target']) - 1)] == '_') { + $custom_field_name = substr($module['ip_target'], 1, -1); + $custom_value = agents_get_agent_custom_field($id_agente, $custom_field_name); + if (isset($custom_value) && $custom_value !== false) { + $title .= '
IP: '.$custom_value; + } else { + $array_macros = return_agent_macros($id_agente); + if (isset($array_macros[$module['ip_target']])) { + $title .= '
IP: '.$array_macros[$module['ip_target']]; + } else { + $title .= '
IP: '.$module['ip_target']; + } + } + } else { + $title .= '
IP: '.$module['ip_target']; + } } $last_status_change_text = __('Time elapsed since last status change: '); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index d03b8d7412..855083dac5 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -990,6 +990,70 @@ function get_parameter($name, $default='') } +function get_parameter_date($name, $default='', $date_format='Y/m/d') +{ + $date_end = get_parameter('date_end', 0); + $time_end = get_parameter('time_end'); + $datetime_end = strtotime($date_end.' '.$time_end); + + $custom_date = get_parameter('custom_date', 0); + $range = get_parameter('range', SECONDS_1DAY); + $date_text = get_parameter('range_text', SECONDS_1DAY); + $date_init_less = (strtotime(date('Y/m/d')) - SECONDS_1DAY); + $date_init = get_parameter('date_init', date(DATE_FORMAT, $date_init_less)); + $time_init = get_parameter('time_init', date(TIME_FORMAT, $date_init_less)); + $datetime_init = strtotime($date_init.' '.$time_init); + if ($custom_date === '1') { + if ($datetime_init >= $datetime_end) { + $datetime_init = $date_init_less; + } + + $date_init = date('Y/m/d H:i:s', $datetime_init); + $date_end = date('Y/m/d H:i:s', $datetime_end); + $period = ($datetime_end - $datetime_init); + } else if ($custom_date === '2') { + $date_units = get_parameter('range_units'); + $date_end = date('Y/m/d H:i:s'); + $date_init = date('Y/m/d H:i:s', (strtotime($date_end) - ((int) $date_text * (int) $date_units))); + $period = (strtotime($date_end) - strtotime($date_init)); + } else if (in_array($range, ['this_week', 'this_month', 'past_week', 'past_month'])) { + if ($range === 'this_week') { + $monday = date('Y/m/d', strtotime('last monday')); + + $sunday = date('Y/m/d', strtotime($monday.' +6 days')); + $period = (strtotime($sunday) - strtotime($monday)); + $date_init = $monday; + $date_end = $sunday; + } else if ($range === 'this_month') { + $date_end = date('Y/m/d', strtotime('last day of this month')); + $first_of_month = date('Y/m/d', strtotime('first day of this month')); + $date_init = $first_of_month; + $period = (strtotime($date_end) - strtotime($first_of_month)); + } else if ($range === 'past_month') { + $date_end = date('Y/m/d', strtotime('last day of previous month')); + $first_of_month = date('Y/m/d', strtotime('first day of previous month')); + $date_init = $first_of_month; + $period = (strtotime($date_end) - strtotime($first_of_month)); + } else if ($range === 'past_week') { + $date_end = date('Y/m/d', strtotime('sunday', strtotime('last week'))); + $first_of_week = date('Y/m/d', strtotime('monday', strtotime('last week'))); + $date_init = $first_of_week; + $period = (strtotime($date_end) - strtotime($first_of_week)); + } + } else { + $date_end = date('Y/m/d H:i:s'); + $date_init = date('Y/m/d H:i:s', (strtotime($date_end) - $range)); + $period = (strtotime($date_end) - strtotime($date_init)); + } + + return [ + 'date_init' => date($date_format, strtotime($date_init)), + 'date_end' => date($date_format, strtotime($date_end)), + 'period' => $period, + ]; +} + + /** * Get a parameter from a get request. * diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 210b933328..2381d51ad6 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -13132,7 +13132,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) if ($other['data'][18] != '') { $values['id_extra'] = $other['data'][18]; - $sql_validation = 'SELECT id_evento,estado,ack_utimestamp,id_usuario + $sql_validation = 'SELECT id_evento,estado,ack_utimestamp,id_usuario,event_custom_id FROM tevento WHERE estado IN (0,2) AND id_extra ="'.$other['data'][18].'";'; @@ -13147,6 +13147,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) $values['status'] = 2; $ack_utimestamp = $val['ack_utimestamp']; $values['id_usuario'] = $val['id_usuario']; + $values['event_custom_id'] = $val['event_custom_id']; } api_set_validate_event_by_id($val['id_evento']); @@ -13177,7 +13178,8 @@ function api_set_create_event($id, $trash1, $other, $returnType) $custom_data, $values['server_id'], $values['id_extra'], - $ack_utimestamp + $ack_utimestamp, + $values['event_custom_id'] ?? null ); if ($other['data'][12] != '') { @@ -17787,6 +17789,48 @@ function api_token_check(string $token) } +/** + * Set custom field value in tevento + * + * @param mixed $id_event Event id. + * @param mixed $custom_field Custom field to set. + * @return void + */ +function api_set_event_custom_id($id, $value) +{ + // Get the event + $event = events_get_event($id, false, is_metaconsole()); + // If event not exists, end the execution. + if ($event === false) { + returnError( + 'event_not_exists', + 'Event not exists' + ); + $result = false; + } + + // Safe custom fields for hacks. + if (preg_match('/script/i', io_safe_output($value))) { + $result = false; + } + + $result = events_event_custom_id( + $id, + $value + ); + + // If update results failed + if (empty($result) === true || $result === false) { + returnError( + 'The event could not be updated' + ); + return false; + } else { + returnData('string', ['data' => 'Event updated.']); + } +} + + /** * Extract info Agents for inventories ITSM. * diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 2a91641315..74ff4cc6fc 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -219,6 +219,7 @@ function events_get_all_fields() $columns['module_status'] = __('Module status'); $columns['module_custom_id'] = __('Module custom id'); $columns['custom_data'] = __('Custom data'); + $columns['event_custom_id'] = __('Event Custom ID'); return $columns; } @@ -322,6 +323,9 @@ function events_get_column_name($field, $table_alias=false) case 'custom_data': return __('Custom data'); + case 'event_custom_id': + return __('Event Custom ID'); + default: return __($field); } @@ -2356,7 +2360,8 @@ function events_create_event( $custom_data='', $server_id=0, $id_extra='', - $ack_utimestamp=0 + $ack_utimestamp=0, + $event_custom_id=null ) { if ($source === false) { $source = get_product_name(); @@ -2388,6 +2393,7 @@ function events_create_event( 'custom_data' => $custom_data, 'data' => '', 'module_status' => 0, + 'event_custom_id' => $event_custom_id, ]; return (int) db_process_sql_insert('tevento', $values); @@ -4658,6 +4664,30 @@ function events_page_details($event, $server_id=0) $data[1] = ''.__('N/A').''; } + $table_details->data[] = $data; + $readonly = true; + if (check_acl($config['id_user'], 0, 'EW')) { + $readonly = false; + } + + $data = []; + $data[0] = __('Event Custom ID'); + $data[1] = '
'.html_print_input_text('event_custom_id', $event['event_custom_id'], '', false, 255, true, $readonly, false, '', 'w60p'); + if ($readonly === false) { + $data[1] .= html_print_button( + __('Update'), + 'update_event_custom_id', + false, + 'update_event_custom_id('.$event['id_evento'].', '.$event['server_id'].');', + [ + 'icon' => 'next', + 'mode' => 'link', + ], + true + ); + } + + $data[1] .= '
'; $table_details->data[] = $data; $details = '
'.html_print_table($table_details, true).'
'; @@ -6260,6 +6290,63 @@ function event_get_counter_extraId(array $event, ?array $filters) } +/** + * Update event detail custom field + * + * @param mixed $id_event Event ID or array of events. + * @param string $event_custom_id Event custom ID to be update. + * + * @return boolean Whether or not it was successful + */ +function events_event_custom_id( + $id_event, + $event_custom_id, +) { + global $config; + // Cleans up the selection for all unwanted values also casts any single + // values as an array. + if (![$id_event]) { + $id_event = (array) safe_int($id_event, 1); + } + + // Check ACL. + foreach ($id_event as $k => $id) { + $event_group = events_get_group($id); + if (check_acl($config['id_user'], $event_group, 'EW') == 0) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Attempted updating event #'.$id + ); + + unset($id_event[$k]); + } + } + + if (empty($id_event) === true) { + return false; + } + + // Get the current event comments. + $first_event = $id_event; + if (is_array($id_event) === true) { + $first_event = reset($id_event); + } + + // Update comment. + $ret = db_process_sql_update( + 'tevento', + ['event_custom_id' => $event_custom_id], + ['id_evento' => $first_event] + ); + + if (($ret === false) || ($ret === 0)) { + return false; + } + + return true; +} + + function event_print_graph( $filter, $graph_height=100, diff --git a/pandora_console/include/functions_macros.php b/pandora_console/include/functions_macros.php new file mode 100644 index 0000000000..bba0bd1898 --- /dev/null +++ b/pandora_console/include/functions_macros.php @@ -0,0 +1,61 @@ + ($agente['nombre']) ?: '', + '_agentalias_' => ($agente['alias']) ?: '', + '_agent_' => ($agente['alias']) ?: (($agente['nombre']) ?: ''), + '_agentcustomid_' => ($agente['custom_id']) ?: '', + '_agentdescription_' => ($agente['comentarios']) ?: '', + '_agentgroup_' => ($grupo['nombre']) ?: '', + '_agentos_' => ($agente['id_os']) ?: '', + '_address_' => ($agente['direccion']) ?: '', + '_homeurl_' => ($config['public_url']) ?: '', + '_groupcontact_' => ($agente['contact']) ?: '', + '_groupcustomid_' => ($agente['custom_id']) ?: '', + '_groupother_' => ($agente['other']) ?: '', + '_server_ip_' => ($server_ip) ?: '', + '_server_name_' => ($agente['server_name']) ?: '', + ]; + + return $array_macros; +} diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index ed6adf6301..5e676b2ea5 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -492,6 +492,37 @@ function event_comment(current_event) { return false; } +// Save custom_field into an event. +function update_event_custom_id(event_id, server_id) { + var event_custom_id = $("#text-event_custom_id").val(); + + var params = { + page: "include/ajax/events", + update_event_custom_id: 1, + event_custom_id: event_custom_id, + event_id: event_id, + server_id: server_id + }; + + $("#button-update_custom_field").attr("disabled", "disabled"); + $("#response_loading").show(); + + jQuery.ajax({ + data: params, + type: "POST", + url: getUrlAjax(), + dataType: "html", + success: function(data) { + if (data === "update_error") { + alert("Event Custom ID not valid"); + } + $("#button-update_custom_field").removeAttr("disabled"); + $("#response_loading").hide(); + $("#button-events_form_search_bt").trigger("click"); + } + }); +} + var processed = 0; function update_event(table, id_evento, type, event_rep, row, server_id) { var inputs = $("#events_form :input"); diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index dfcdfe0238..4430bfa253 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -458,6 +458,12 @@ class Manager implements PublicLogin $this->publicLink ); + if ((bool) $this->dashboardFields['date_range'] === true) { + $dateFrom = $this->dashboardFields['date_from']; + $dateTo = $this->dashboardFields['date_to']; + $instance->setDateRange($dateFrom, $dateTo); + } + return $instance; } @@ -1041,6 +1047,8 @@ class Manager implements PublicLogin $id_group = \get_parameter('id_group'); $slideshow = \get_parameter_switch('slideshow'); $favourite = \get_parameter_switch('favourite'); + $dateRange = \get_parameter_switch('date_range'); + $dateData = \get_parameter_date('range', '', 'U'); $id_user = (empty($private) === false) ? $config['id_user'] : ''; @@ -1050,6 +1058,9 @@ class Manager implements PublicLogin 'id_group' => $id_group, 'cells_slideshow' => $slideshow, 'active' => $favourite, + 'date_range' => $dateRange, + 'date_from' => $dateData['date_init'], + 'date_to' => $dateData['date_end'], ]; if ($this->dashboardId === 0) { diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 82fc7cbda5..ca48e6d61a 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -51,6 +51,20 @@ class Widget */ private $showSelectNodeMeta; + /** + * Date from init for filter widget. + * + * @var integer + */ + private $dateFrom; + + /** + * Date from end for filter widget. + * + * @var integer + */ + private $dateTo; + /** * Contructor widget. @@ -824,4 +838,41 @@ class Widget } + /** + * Set the date range of parent configuration. + * + * @param integer $dateFrom Date from init for filter widget. + * @param integer $dateTo Date from end for filter widget. + * + * @return void + */ + public function setDateRange(int $dateFrom, int $dateTo) + { + $this->dateFrom = $dateFrom; + $this->dateTo = $dateTo; + } + + + public function getDateFrom() + { + return $this->dateFrom; + } + + + public function getDateTo() + { + return $this->dateTo; + } + + + public function getPeriod():mixed + { + if (empty($this->dateFrom) === false && empty($this->dateTo) === false) { + return ($this->dateTo - $this->dateFrom); + } else { + return null; + } + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php b/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php index c3b9ddf9ad..a140d7fcb4 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php +++ b/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php @@ -637,6 +637,10 @@ class BasicChart extends Widget $color_status = $this->values['colorValue']; } + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + $params = [ 'agent_module_id' => $this->values['moduleId'], 'period' => $this->values['period'], diff --git a/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php b/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php index a3ff215c76..1484823518 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php +++ b/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php @@ -520,6 +520,9 @@ class BlockHistogram extends Widget global $config; $size = parent::getSize(); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } // Desactive scroll bars only this item. $id_agent = $data['agent_id']; diff --git a/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php b/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php index be38c31bb4..770a3152fe 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php +++ b/pandora_console/include/lib/Dashboard/Widgets/DataMatrix.php @@ -473,6 +473,10 @@ class DataMatrix extends Widget return $output; } + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + if (is_metaconsole() === true) { $modules_nodes = array_reduce( $this->values['moduleDataMatrix'], diff --git a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php index 377ca145a0..4cb4734105 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php @@ -472,6 +472,10 @@ class CustomGraphWidget extends Widget $size = parent::getSize(); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + switch ($this->values['type']) { case CUSTOM_GRAPH_STACKED_LINE: case CUSTOM_GRAPH_STACKED_AREA: diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index 3706c33d5e..8af253242e 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -838,6 +838,7 @@ class EventsListWidget extends Widget 'mini_severity' => __('Severity mini'), 'module_custom_id' => __('Module custom ID'), 'custom_data' => __('Custom data'), + 'event_custom_id' => __('Event Custom ID'), ]; } diff --git a/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php b/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php index b0382ba273..38967c2e47 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php +++ b/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php @@ -302,6 +302,10 @@ class GraphModuleHistogramWidget extends Widget $values['period'] = SECONDS_1DAY; } + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + if (isset($values['sizeLabel']) === false) { $values['sizeLabel'] = 30; } diff --git a/pandora_console/include/lib/Dashboard/Widgets/netflow.php b/pandora_console/include/lib/Dashboard/Widgets/netflow.php index 13a15bf6a0..6c0aa76eca 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/netflow.php +++ b/pandora_console/include/lib/Dashboard/Widgets/netflow.php @@ -309,6 +309,12 @@ class Netflow extends Widget $start_date = (time() - $this->values['period']); $end_date = time(); + + if (empty(parent::getPeriod()) === false) { + $start_date = parent::getDateFrom(); + $end_date = parent::getDateTo(); + } + if ($this->values['chart_type'] === 'usage_map') { $map_data = netflow_build_map_data( $start_date, diff --git a/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php b/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php index c77d343ea3..b3c124f039 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php +++ b/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php @@ -135,8 +135,6 @@ class SecurityHardening extends Widget // Includes. include_once ENTERPRISE_DIR.'/include/functions_security_hardening.php'; include_once $config['homedir'].'/include/graphs/fgraph.php'; - include_once $config['homedir'].'/include/functions_graph.php'; - // WARNING: Do not edit. This chunk must be in the constructor. parent::__construct( $cellId, @@ -328,6 +326,11 @@ class SecurityHardening extends Widget $id_groups = $this->checkAcl($values['group']); $output .= ''.$this->elements[$data_type].''; + if (empty(parent::getPeriod()) === false) { + $values['date_init'] = parent::getDateFrom(); + $values['date_end'] = parent::getDateTo(); + } + switch ($data_type) { case 'top_n_agents_sh': $output .= $this->loadTopNAgentsSh($id_groups, $values['limit']); diff --git a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php index dbca9fa5f0..a718217a57 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php @@ -440,6 +440,10 @@ class SingleGraphWidget extends Widget $module_name = \modules_get_agentmodule_name($this->values['moduleId']); $units_name = \modules_get_unit($this->values['moduleId']); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + $trickHight = 0; if ($this->values['showLegend'] === 1) { // Needed for legend. diff --git a/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php b/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php index 4dfefbf292..f3c7fb826e 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php +++ b/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php @@ -459,6 +459,9 @@ class SLAPercentWidget extends Widget global $config; $size = parent::getSize(); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } $output .= ''; $id_agent = $this->values['agentId']; diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n.php b/pandora_console/include/lib/Dashboard/Widgets/top_n.php index 3ab2f922a3..5e885927db 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/top_n.php +++ b/pandora_console/include/lib/Dashboard/Widgets/top_n.php @@ -374,6 +374,10 @@ class TopNWidget extends Widget $size = parent::getSize(); + if (empty(parent::getPeriod()) === false) { + $this->values['period'] = parent::getPeriod(); + } + $quantity = $this->values['quantity']; $period = $this->values['period']; diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 4bddd880c5..08c3740276 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -378,6 +378,7 @@ if (is_ajax() === true) { 'te.owner_user', 'if(te.ack_utimestamp > 0, te.ack_utimestamp,"") as ack_utimestamp', 'te.custom_data', + 'te.event_custom_id', 'te.data', 'te.module_status', 'ta.alias as agent_name', diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 5ff5e4257b..61334b092d 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -726,6 +726,7 @@ CREATE TABLE IF NOT EXISTS `tevento` ( `custom_data` TEXT, `data` TINYTEXT, `module_status` INT NOT NULL DEFAULT 0, + `event_custom_id` TEXT, PRIMARY KEY (`id_evento`), KEY `idx_agente` (`id_agente`), KEY `idx_agentmodule` (`id_agentmodule`), @@ -2641,6 +2642,9 @@ CREATE TABLE IF NOT EXISTS `tdashboard` ( `active` TINYINT NOT NULL DEFAULT 0, `cells` INT UNSIGNED DEFAULT 0, `cells_slideshow` TINYINT NOT NULL DEFAULT 0, + `date_range` TINYINT NOT NULL DEFAULT 0, + `date_from` INT NOT NULL DEFAULT 0, + `date_to` INT NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; @@ -3032,7 +3036,6 @@ CREATE TABLE IF NOT EXISTS `tevent_rule` ( `module` TEXT, `alert` TEXT, `criticity` TEXT, - `user_comment` TEXT, `id_tag` TEXT, `name` TEXT, `group_recursion` TEXT, @@ -3047,7 +3050,6 @@ CREATE TABLE IF NOT EXISTS `tevent_rule` ( `operator_module` TEXT COMMENT 'Operator for module', `operator_alert` TEXT COMMENT 'Operator for alert', `operator_criticity` TEXT COMMENT 'Operator for criticity', - `operator_user_comment` TEXT COMMENT 'Operator for user_comment', `operator_id_tag` TEXT COMMENT 'Operator for id_tag', `operator_log_content` TEXT COMMENT 'Operator for log_content', `operator_log_source` TEXT COMMENT 'Operator for log_source', diff --git a/pandora_console/views/dashboard/formDashboard.php b/pandora_console/views/dashboard/formDashboard.php index c36df6cf06..be21a3142e 100644 --- a/pandora_console/views/dashboard/formDashboard.php +++ b/pandora_console/views/dashboard/formDashboard.php @@ -102,6 +102,31 @@ $inputs = [ ], ], ], + [ + 'label' => __('Date range'), + 'arguments' => [ + 'name' => 'date_range', + 'id' => 'date_range', + 'type' => 'switch', + 'value' => $arrayDashboard['date_range'], + 'onchange' => 'handle_date_range(this)', + ], + ], + [ + 'label' => __('Select range'), + 'style' => 'display: none;', + 'class' => 'row_date_range', + 'arguments' => [ + 'name' => 'range', + 'id' => 'range', + 'selected' => ($arrayDashboard['date_from'] === '0' && $arrayDashboard['date_to'] === '0') ? 300 : 'chose_range', + 'type' => 'date_range', + 'date_init' => date('Y/m/d', $arrayDashboard['date_from']), + 'time_init' => date('H:i:s', $arrayDashboard['date_from']), + 'date_end' => date('Y/m/d', $arrayDashboard['date_to']), + 'time_end' => date('H:i:s', $arrayDashboard['date_to']), + ], + ], [ 'block_id' => 'private', 'direct' => 1, @@ -135,3 +160,30 @@ HTML::printForm( 'inputs' => $inputs, ] ); + +?> + + \ No newline at end of file diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index baabc7d047..14544ae1c0 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4304,6 +4304,7 @@ sub pandora_event { my $utimestamp = time (); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); + my $event_custom_id = undef; $id_agentmodule = 0 unless defined ($id_agentmodule); # Validate events with the same event id @@ -4321,6 +4322,7 @@ sub pandora_event { logger($pa_config, "Keeping In process status from last event with extended id '$id_extra'.", 10); $ack_utimestamp = get_db_value ($dbh, 'SELECT ack_utimestamp FROM tevento WHERE id_extra=? AND estado=2', $id_extra); $event_status = 2; + $event_custom_id = get_db_value ($dbh, 'SELECT event_custom_id FROM tevento WHERE id_extra=? AND estado=2', $id_extra); } } @@ -4332,8 +4334,8 @@ sub pandora_event { # Create the event logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); - $event_id = db_insert ($dbh, 'id_evento','INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status); + $event_id = db_insert ($dbh, 'id_evento','INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status, event_custom_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status, $event_custom_id); if(defined($event_id) && $comment ne '') { my $comment_id = db_insert ($dbh, 'id','INSERT INTO tevent_comment (id_event, utimestamp, comment, id_user, action) diff --git a/pandora_server/lib/PandoraFMS/InventoryServer.pm b/pandora_server/lib/PandoraFMS/InventoryServer.pm index 5f0f90e95d..e6b070f4d8 100644 --- a/pandora_server/lib/PandoraFMS/InventoryServer.pm +++ b/pandora_server/lib/PandoraFMS/InventoryServer.pm @@ -181,17 +181,21 @@ sub data_consumer ($$) { AND tagent_module_inventory.id_module_inventory = tmodule_inventory.id_module_inventory', $module_id); - # No code to run - return if ($module->{'interpreter'} eq ''); - - # Save script in a temporary file + my $command; my ($fh, $temp_file) = tempfile(); - $fh->print (decode_base64($module->{'code'})); - close ($fh); - set_file_permissions($pa_config, $temp_file, "0777"); - # Run the script - my $command = $module->{'interpreter'} . ' ' . $temp_file . ' "' . $module->{'target'} . '"'; + if ($module->{'script_mode'} == '1') { + my $script_file = $module->{'script_path'}; + $command = $module->{'interpreter'} . ' ' . $script_file . ' "' . $module->{'target'} . '"'; + } else { + # Save script in a temporary file + $fh->print (decode_base64($module->{'code'})); + close ($fh); + set_file_permissions($pa_config, $temp_file, "0777"); + + # Run the script + $command = $module->{'interpreter'} . ' ' . $temp_file . ' "' . $module->{'target'} . '"'; + } # Try to read the custom fields to use them as arguments into the command if (defined($module->{'custom_fields'}) && $module->{'custom_fields'} ne '') { @@ -206,7 +210,11 @@ sub data_consumer ($$) { if (!defined ($decoded_cfields)) { logger ($pa_config, "Remote inventory module ".$module->{'name'}." has failed because the custom fields can't be read", 6); - unlink ($temp_file); + + if ($module->{'script_mode'} == '2') { + unlink ($temp_file); + } + return; } @@ -237,11 +245,18 @@ sub data_consumer ($$) { # Check for errors if ($? != 0) { logger ($pa_config, "Remote inventory module ".$module->{'name'}." has failed with error level $?", 6); - unlink ($temp_file); + + if ($module->{'script_mode'} == '2') { + unlink ($temp_file); + } + return; } - unlink ($temp_file); + if ($module->{'script_mode'} == '2') { + unlink ($temp_file); + } + my $utimestamp = time (); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); eval { diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 3885288718..cae8a81f8b 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -201,6 +201,7 @@ sub help_screen{ help_screen_line('--disable_double_auth', '', 'Disable the double authentication for the specified user'); print "\nEVENTS:\n\n" unless $param ne ''; help_screen_line('--create_event', " [ \n\t \n\t \n\t ]", 'Add event'); + help_screen_line('--update_event_custom_id', " ", 'Update Event Custom ID'); help_screen_line('--validate_event', " \n\t []", 'Validate events'); help_screen_line('--validate_event_id', '', 'Validate event given a event id'); help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); @@ -4549,6 +4550,17 @@ sub cli_create_event() { } } +############################################################################## +# Update event custom id +# Related option: --update_event_custom_id +############################################################################## + +sub cli_update_event_custom_id() { + my ($id_event, $event_custom_id) = @ARGV[2..3]; + my $result = api_call(\%conf, 'set', 'event_custom_id', $id_event, $event_custom_id); + print "\n$result\n"; +} + ############################################################################## # Validate event. # Related option: --validate_event @@ -8335,6 +8347,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 4, 0); cli_insert_gis_data(); } + elsif ($param eq '--update_event_custom_id'){ + param_check($ltotal, 2); + cli_update_event_custom_id(); + } else { print_log "[ERROR] Invalid option '$param'.\n\n"; $param = '';