Merge branch '2248-5730-Añadir-elementos-a-la-vista-de-eventos' into 'develop'

Add items to the view events

See merge request artica/pandorafms!1623
This commit is contained in:
vgilc 2018-07-23 11:22:23 +02:00
commit 44ad0c31d5
7 changed files with 116 additions and 7 deletions

View File

@ -18,4 +18,16 @@ DROP INDEX id_policy ON `tpolicy_agents`;
ALTER TABLE `tpolicy_agents` ADD COLUMN `id_node` int(10) NOT NULL DEFAULT '0';
ALTER TABLE `tpolicy_agents` ADD UNIQUE(`id_policy`, `id_agent`, `id_node`);
ALTER TABLE `tevento` ADD COLUMN `data` double(22,5) default NULL;
ALTER TABLE `tmetaconsole_event` ADD COLUMN `data` double(22,5) default NULL;
ALTER TABLE `tmetaconsole_event_history` ADD COLUMN `data` double(22,5) default NULL;
ALTER TABLE `tevento` ADD COLUMN `module_status` int(4) NOT NULL default '0';
ALTER TABLE `tmetaconsole_event` ADD COLUMN `module_status` int(4) NOT NULL default '0';
ALTER TABLE `tmetaconsole_event_history` ADD COLUMN `module_status` int(4) NOT NULL default '0';
COMMIT;

View File

@ -121,6 +121,12 @@ if ($fields_selected[0]!='') {
case 'server_name':
$result = __('Server name');
break;
case 'data':
$result = __('Data');
case 'module_status':
$result = __('Module status');
break;
break;
}
$result_selected[$field_selected] = $result;
}
@ -168,6 +174,8 @@ $fields_available['owner_user'] = __('Owner');
$fields_available['ack_utimestamp'] = __('ACK Timestamp');
$fields_available['instructions'] = __('Instructions');
$fields_available['server_name'] = __('Server name');
$fields_available['data'] = __('Data');
$fields_available['module_status'] = __('Module status');
//remove fields already selected
foreach ($fields_available as $key=>$available) {

View File

@ -50,6 +50,8 @@ function events_get_all_fields() {
$columns['ack_utimestamp'] = __('ACK Timestamp');
$columns['instructions'] = __('Instructions');
$columns['server_name'] = __('Server name');
$columns['data'] = __('Data');
$columns['module_status'] = __('Module status');
return $columns;
}

View File

@ -2764,4 +2764,57 @@ function force_set_module_status ($status, $id_agent_module) {
array('id_agente_modulo' => $id_agent_module)
);
}
function modules_get_modules_status ($mod_status_id) {
$diferent_types = get_priorities ();
$mod_status_desc = '';
switch ($mod_status_id) {
case AGENT_MODULE_STATUS_NORMAL:
$mod_status_desc = __('NORMAL');
break;
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$mod_status_desc = __('CRITICAL');
break;
case AGENT_MODULE_STATUS_WARNING:
$mod_status_desc = __('WARNING');
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$mod_status_desc = __('UNKNOWN');
break;
case AGENT_MODULE_STATUS_NOT_INIT:
$mod_status_desc = __('NOT INIT');
break;
case AGENT_MODULE_STATUS_ALL:
$mod_status_desc = __('ALL');
break;
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
$mod_status_desc = __('CRITICAL');
break;
case AGENT_MODULE_STATUS_NO_DATA:
$mod_status_desc = __('NO DATA');
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
$mod_status_desc = __('NORMAL');
break;
case AGENT_MODULE_STATUS_NOT_NORMAL:
$mod_status_desc = __('NOT NORMAL');
break;
case AGENT_MODULE_STATUS_WARNING_ALERT:
$mod_status_desc = __('WARNING');
break;
default:
if (isset($config['text_char_long'])) {
foreach ($diferent_types as $key => $type) {
if ($key == $mod_status_id) {
$mod_status_desc = ui_print_truncate_text($type,
$config['text_char_long'], false, true, false);
}
}
}
break;
}
return $mod_status_desc;
}
?>

View File

@ -249,6 +249,18 @@ else {
$i++;
}
if (in_array('data', $show_fields)) {
$table->head[$i] = __('Data');
$table->align[$i] = 'left';
$i++;
}
if (in_array('module_status', $show_fields)) {
$table->head[$i] = __('Module status');
$table->align[$i] = 'left';
$i++;
}
if ($i != 0 && $allow_action) {
$table->head[$i] = __('Action');
$table->align[$i] = 'left';
@ -663,6 +675,16 @@ else {
$table->cellclass[count($table->data)][$i] = $myclass;
$i++;
}
if (in_array('data',$show_fields)) {
$data[$i] = $event["data"];
$table->cellclass[count($table->data)][$i] = $myclass;
$i++;
}
if (in_array('module_status',$show_fields)) {
$data[$i] = modules_get_modules_status ($event["module_status"]);
$table->cellclass[count($table->data)][$i] = $myclass;
$i++;
}
if ($i != 0 && $allow_action) {
//Actions

View File

@ -641,6 +641,8 @@ CREATE TABLE IF NOT EXISTS `tevento` (
`owner_user` VARCHAR(100) NOT NULL DEFAULT '',
`ack_utimestamp` BIGINT(20) NOT NULL DEFAULT '0',
`custom_data` TEXT NOT NULL,
`data` double(22,5) default NULL,
`module_status` int(4) NOT NULL default '0',
PRIMARY KEY (`id_evento`),
KEY `idx_agente` (`id_agente`),
KEY `idx_agentmodule` (`id_agentmodule`),
@ -2878,6 +2880,8 @@ CREATE TABLE IF NOT EXISTS `tmetaconsole_event` (
`ack_utimestamp` BIGINT(20) NOT NULL DEFAULT '0',
`server_id` int(10) NOT NULL,
`custom_data` TEXT NOT NULL DEFAULT '',
`data` double(22,5) default NULL,
`module_status` int(4) NOT NULL default '0',
PRIMARY KEY (`id_evento`),
KEY `idx_agente` (`id_agente`),
KEY `idx_agentmodule` (`id_agentmodule`),
@ -2923,6 +2927,8 @@ CREATE TABLE IF NOT EXISTS `tmetaconsole_event_history` (
`ack_utimestamp` BIGINT(20) NOT NULL DEFAULT '0',
`server_id` int(10) NOT NULL,
`custom_data` TEXT NOT NULL DEFAULT '',
`data` double(22,5) default NULL,
`module_status` int(4) NOT NULL default '0',
PRIMARY KEY (`id_evento`),
KEY `idx_agente` (`id_agente`),
KEY `idx_agentmodule` (`id_agentmodule`),

View File

@ -3116,11 +3116,12 @@ Generate an event.
=cut
##########################################################################
sub pandora_event ($$$$$$$$$$;$$$$$$$$$) {
sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) {
my ($pa_config, $evento, $id_grupo, $id_agente, $severity,
$id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh,
$source, $user_name, $comment, $id_extra, $tags,
$critical_instructions, $warning_instructions, $unknown_instructions, $custom_data) = @_;
$critical_instructions, $warning_instructions, $unknown_instructions, $custom_data,
$module_data, $module_status) = @_;
my $event_table = is_metaconsole($pa_config) ? 'tmetaconsole_event' : 'tevento';
my $agent = undef;
@ -3134,7 +3135,10 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) {
my $module = undef;
if (defined($id_agentmodule) && $id_agentmodule != 0) {
$module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agentmodule);
$module = get_db_single_row ($dbh, 'SELECT *, tagente_estado.datos, tagente_estado.estado
FROM tagente_modulo, tagente_estado
WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_modulo.id_agente_modulo = ?', $id_agentmodule);
if (defined ($module) && $module->{'quiet'} == 1) {
logger($pa_config, "Generate Event. The module '" . $module->{'nombre'} . "' is in quiet mode.", 10);
return;
@ -3162,6 +3166,8 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) {
$warning_instructions = '' unless defined ($warning_instructions);
$unknown_instructions = '' unless defined ($unknown_instructions);
$custom_data = '' unless defined ($custom_data);
$module_data = defined($module) ? $module->{'datos'} : '' unless defined ($module_data);
$module_status = defined($module) ? $module->{'estado'} : '' unless defined ($module_status);
# If the event is created with validated status, assign ack_utimestamp
my $ack_utimestamp = $event_status == 1 ? time() : 0;
@ -3183,8 +3189,8 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) {
# Create the event
logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10);
db_do ($dbh, 'INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data);
db_do ($dbh, 'INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, $module_data, $module_status);
# Do not write to the event file
return if ($pa_config->{'event_file'} eq '');
@ -4168,11 +4174,11 @@ sub generate_status_event ($$$$$$$$) {
# Generate the event
if ($status != 0){
pandora_event ($pa_config, $description, $agent->{'id_grupo'}, $module->{'id_agente'},
$severity, 0, $module->{'id_agente_modulo'}, $event_type, 0, $dbh, 'monitoring_server', '', '', '', '', $module->{'critical_instructions'}, $module->{'warning_instructions'}, $module->{'unknown_instructions'});
$severity, 0, $module->{'id_agente_modulo'}, $event_type, 0, $dbh, 'monitoring_server', '', '', '', '', $module->{'critical_instructions'}, $module->{'warning_instructions'}, $module->{'unknown_instructions'}, undef, $data, $status);
} else {
# Self validate this event if has "normal" status
pandora_event ($pa_config, $description, $agent->{'id_grupo'}, $module->{'id_agente'},
$severity, 0, $module->{'id_agente_modulo'}, $event_type, 1, $dbh, 'monitoring_server', '', '', '', '', $module->{'critical_instructions'}, $module->{'warning_instructions'}, $module->{'unknown_instructions'});
$severity, 0, $module->{'id_agente_modulo'}, $event_type, 1, $dbh, 'monitoring_server', '', '', '', '', $module->{'critical_instructions'}, $module->{'warning_instructions'}, $module->{'unknown_instructions'}, undef, $data, $status);
}
}