#8365 merge conflict
This commit is contained in:
commit
c41b360a6e
|
@ -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;
|
||||
|
|
|
@ -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 .= '<br/>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 .= '<br/>IP: '.$custom_value;
|
||||
} else {
|
||||
$array_macros = return_agent_macros($id_agente);
|
||||
if (isset($array_macros[$module['ip_target']])) {
|
||||
$title .= '<br/>IP: '.$array_macros[$module['ip_target']];
|
||||
} else {
|
||||
$title .= '<br/>IP: '.$module['ip_target'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$title .= '<br/>IP: '.$module['ip_target'];
|
||||
}
|
||||
}
|
||||
|
||||
// This module is initialized ? (has real data).
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 .= '<br/>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 .= '<br/>IP: '.$custom_value;
|
||||
} else {
|
||||
$array_macros = return_agent_macros($id_agente);
|
||||
if (isset($array_macros[$module['ip_target']])) {
|
||||
$title .= '<br/>IP: '.$array_macros[$module['ip_target']];
|
||||
} else {
|
||||
$title .= '<br/>IP: '.$module['ip_target'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$title .= '<br/>IP: '.$module['ip_target'];
|
||||
}
|
||||
}
|
||||
|
||||
$last_status_change_text = __('Time elapsed since last status change: ');
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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] = '<i>'.__('N/A').'</i>';
|
||||
}
|
||||
|
||||
$table_details->data[] = $data;
|
||||
$readonly = true;
|
||||
if (check_acl($config['id_user'], 0, 'EW')) {
|
||||
$readonly = false;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data[0] = __('Event Custom ID');
|
||||
$data[1] = '<div class="flex-row-center">'.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] .= '</div>';
|
||||
$table_details->data[] = $data;
|
||||
|
||||
$details = '<div id="extended_event_details_page" class="extended_event_pages">'.html_print_table($table_details, true).'</div>';
|
||||
|
@ -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,
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - https://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2023 Pandora FMS
|
||||
// Please see https://pandorafms.com/community/ for full contribution list
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
|
||||
/**
|
||||
* Return array with macros of agent like core.pm
|
||||
*
|
||||
* @param interger $id_agente Id agent to return data.
|
||||
*
|
||||
* @return array Array with all macros.
|
||||
*/
|
||||
function return_agent_macros($id_agente)
|
||||
{
|
||||
global $config;
|
||||
$array_macros = [];
|
||||
$grupo = [];
|
||||
$agente = db_get_row_sql(
|
||||
'SELECT * FROM tagente WHERE id_agente = '.$id_agente
|
||||
);
|
||||
if (isset($agente['id_grupo'])) {
|
||||
$grupo = db_get_row_sql(
|
||||
'SELECT * FROM tgrupo WHERE id_grupo = '.$agente['id_grupo']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($agente['server_name'])) {
|
||||
$server_ip = db_get_row_sql(
|
||||
'SELECT ip_address FROM tserver WHERE name = "'.$agente['server_name'].'"'
|
||||
)['id_address'];
|
||||
}
|
||||
|
||||
$array_macros = [
|
||||
'_agentname_' => ($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;
|
||||
}
|
|
@ -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");
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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'),
|
||||
];
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 .= '<b>'.$this->elements[$data_type].'</b>';
|
||||
|
||||
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']);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -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'];
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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,
|
||||
]
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
<script>
|
||||
function handle_date_range(element){
|
||||
if(element.checked) {
|
||||
$(".row_date_range").show();
|
||||
var def_state_range = $('#range_range').is(':visible');
|
||||
var def_state_default = $('#range_default').is(':visible');
|
||||
var def_state_extend = $('#range_extend').is(':visible');
|
||||
if (
|
||||
def_state_range === false
|
||||
&& def_state_default === false
|
||||
&& def_state_extend === false
|
||||
&& $('#range').val() !== 'chose_range'
|
||||
) {
|
||||
$('#range_default').show();
|
||||
} else if ($('#range').val() === 'chose_range') {
|
||||
$('#range_range').show();
|
||||
}
|
||||
} else {
|
||||
$(".row_date_range").hide();
|
||||
}
|
||||
}
|
||||
var date_range = $("#date_range")[0];
|
||||
handle_date_range(date_range);
|
||||
</script>
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -201,6 +201,7 @@ sub help_screen{
|
|||
help_screen_line('--disable_double_auth', '<user_name>', 'Disable the double authentication for the specified user');
|
||||
print "\nEVENTS:\n\n" unless $param ne '';
|
||||
help_screen_line('--create_event', "<event> <event_type> <group_name> [<agent_name> <module_name>\n\t <event_status> <severity> <template_name> <user_name> <comment> \n\t <source> <id_extra> <tags> <custom_data_json> <force_create_agent> \n\t <critical_instructions> <warning_instructions> <unknown_instructions> <use_alias>]", 'Add event');
|
||||
help_screen_line('--update_event_custom_id', "<event> <event_custom_id>", 'Update Event Custom ID');
|
||||
help_screen_line('--validate_event', "<agent_name> <module_name> <datetime_min> <datetime_max>\n\t <user_name> <criticity> <template_name> [<use_alias>]", 'Validate events');
|
||||
help_screen_line('--validate_event_id', '<event_id>', 'Validate event given a event id');
|
||||
help_screen_line('--get_event_info', '<event_id>[<csv_separator>]', '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 = '';
|
||||
|
|
Loading…
Reference in New Issue