', $description);
echo $description;
return;
}
if ($get_response_params) {
$response_id = get_parameter('response_id');
$params = db_get_value('params', 'tevent_response', 'id', $response_id);
if ($params === false) {
return;
}
echo json_encode(explode(',', $params));
return;
}
if ($get_response_target) {
$response_id = (int) get_parameter('response_id');
$event_id = (int) get_parameter('event_id');
$server_id = (int) get_parameter('server_id');
$event_response = db_get_row('tevent_response', 'id', $response_id);
if (empty($event_response)) {
return;
}
echo events_get_response_target($event_id, $response_id, $server_id);
return;
}
if ($get_response) {
$response_id = get_parameter('response_id');
$event_response = db_get_row('tevent_response', 'id', $response_id);
if (empty($event_response)) {
return;
}
echo json_encode($event_response);
return;
}
if ($perform_event_response) {
global $config;
$command = get_parameter('target', '');
$response_id = get_parameter('response_id');
$event_response = db_get_row('tevent_response', 'id', $response_id);
if (enterprise_installed()) {
if ($event_response['server_to_exec'] != 0 && $event_response['type'] == 'command') {
$commandExclusions = [
'vi',
'vim',
'nano',
];
$server_data = db_get_row(
'tserver',
'id_server',
$event_response['server_to_exec']
);
if (in_array(strtolower($command), $commandExclusions)) {
echo 'Only stdin/stdout commands are supported';
} else {
switch (PHP_OS) {
case 'FreeBSD':
$timeout_bin = '/usr/local/bin/gtimeout';
break;
case 'NetBSD':
$timeout_bin = '/usr/pkg/bin/gtimeout';
break;
default:
$timeout_bin = '/usr/bin/timeout';
break;
}
system('ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$timeout_bin.' 90 '.io_safe_output($command).' 2>&1"', $ret_val);
}
} else {
switch (PHP_OS) {
case 'FreeBSD':
$timeout_bin = '/usr/local/bin/gtimeout';
break;
case 'NetBSD':
$timeout_bin = '/usr/pkg/bin/gtimeout';
break;
default:
$timeout_bin = '/usr/bin/timeout';
break;
}
system($timeout_bin.' 90 '.io_safe_output($command).' 2>&1');
}
} else {
switch (PHP_OS) {
case 'FreeBSD':
$timeout_bin = '/usr/local/bin/gtimeout';
break;
case 'NetBSD':
$timeout_bin = '/usr/pkg/bin/gtimeout';
break;
default:
$timeout_bin = '/usr/bin/timeout';
break;
}
system($timeout_bin.' 90 '.io_safe_output($command).' 2>&1');
}
return;
}
if ($dialogue_event_response) {
global $config;
$event_id = get_parameter('event_id');
$response_id = get_parameter('response_id');
$command = get_parameter('target');
$massive = get_parameter('massive');
$end = get_parameter('end');
$show_execute_again_btn = get_parameter('show_execute_again_btn');
$out_iterator = get_parameter('out_iterator');
$event_response = db_get_row('tevent_response', 'id', $response_id);
$event = db_get_row('tevento', 'id_evento', $event_id);
$prompt = '
> ';
switch ($event_response['type']) {
case 'command':
if ($massive) {
echo "
";
echo $prompt.sprintf(
'(Event #'.$event_id.') '.__(
'Executing command: %s',
$command
)
);
echo '
';
echo "";
echo html_print_image(
'images/spinner.gif',
true
);
echo '
';
echo "
";
if ($end) {
echo "
";
html_print_button(
__('Execute again'),
'btn_str',
false,
'execute_event_response(false);',
"class='sub next'"
);
echo "";
echo html_print_image(
'images/spinner.gif',
true
);
echo '';
echo '
';
}
} else {
echo "";
echo $prompt.sprintf(__('Executing command: %s', $command));
echo '
';
echo "".html_print_image('images/spinner.gif', true).'
';
echo "
";
echo "
";
html_print_button(__('Execute again'), 'btn_str', false, 'perform_response(\''.$command.'\', '.$response_id.');', "class='sub next'");
echo '
';
}
break;
case 'url':
$command = str_replace('localhost', $_SERVER['SERVER_NAME'], $command);
echo "";
break;
default:
// Ignore.
break;
}
}
if ($add_comment) {
$comment = get_parameter('comment');
$event_id = get_parameter('event_id');
$return = events_comment($event_id, $comment, 'Added comment', $meta, $history);
if ($return) {
echo 'comment_ok';
} else {
echo 'comment_error';
}
return;
}
if ($change_status) {
$event_ids = get_parameter('event_ids');
$new_status = get_parameter('new_status');
$return = events_change_status(explode(',', $event_ids), $new_status, $meta, $history);
if ($return) {
echo 'status_ok';
} else {
echo 'status_error';
}
return;
}
if ($change_owner) {
$new_owner = get_parameter('new_owner');
$event_id = get_parameter('event_id');
$similars = true;
if ($new_owner == -1) {
$new_owner = '';
}
$return = events_change_owner($event_id, $new_owner, true, $meta, $history);
if ($return) {
echo 'owner_ok';
} else {
echo 'owner_error';
}
return;
}
if ($get_extended_event) {
global $config;
$event_id = get_parameter('event_id', false);
$childrens_ids = get_parameter('childrens_ids');
$childrens_ids = json_decode($childrens_ids);
if ($meta) {
$event = events_meta_get_event($event_id, false, $history, 'ER');
} else {
$event = events_get_event($event_id);
}
$readonly = false;
if (!$meta
&& isset($config['event_replication'])
&& $config['event_replication'] == 1
&& $config['show_events_in_local'] == 1
) {
$readonly = true;
}
// Clean url from events and store in array.
$event['clean_tags'] = events_clean_tags($event['tags']);
// If the event is not found, we abort.
if (empty($event)) {
ui_print_error_message('Event not found');
return false;
}
$dialog_page = get_parameter('dialog_page', 'general');
$similar_ids = get_parameter('similar_ids', $event_id);
$group_rep = get_parameter('group_rep', false);
$event_rep = get_parameter('event_rep', 1);
$timestamp_first = get_parameter('timestamp_first', $event['utimestamp']);
$timestamp_last = get_parameter('timestamp_last', $event['utimestamp']);
$server_id = get_parameter('server_id', 0);
$event['similar_ids'] = $similar_ids;
$event['timestamp_first'] = $timestamp_first;
$event['timestamp_last'] = $timestamp_last;
$event['event_rep'] = $event_rep;
// Check ACLs.
if (is_user_admin($config['id_user'])) {
// Do nothing if you're admin, you get full access.
$__ignored_line = 0;
} else if ($config['id_user'] == $event['owner_user']) {
// Do nothing if you're the owner user, you get access.
$__ignored_line = 0;
} else if ($event['id_grupo'] == 0) {
// If the event has access to all groups, you get access.
$__ignored_line = 0;
} else {
// Get your groups.
$groups = users_get_groups($config['id_user'], 'ER');
if (in_array($event['id_grupo'], array_keys($groups))) {
// If event group is among the groups of the user, you get access.
$__ignored_line = 0;
} else {
// If all the access types fail, abort.
echo 'Access denied';
return false;
}
}
// Print group_rep in a hidden field to recover it from javascript.
html_print_input_hidden('group_rep', (int) $group_rep);
if ($event === false) {
return;
}
// Tabs.
$tabs = "";
$tabs .= "- ".html_print_image('images/lightning_go.png', true).''.__('General').'
';
if (events_has_extended_info($event['id_evento']) === true) {
$tabs .= "- ".html_print_image('images/zoom.png', true).''.__('Related').'
';
}
$tabs .= "- ".html_print_image('images/zoom.png', true).''.__('Details').'
';
$tabs .= "- ".html_print_image('images/custom_field_col.png', true).''.__('Agent fields').'
';
$tabs .= "';
if (!$readonly
&& ((tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'EM',
$event['clean_tags'],
$childrens_ids
)) || (tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'EW',
$event['clean_tags'],
$childrens_ids
)))
) {
$tabs .= "- ".html_print_image('images/event_responses_col.png', true)."".__('Responses').'
';
}
if ($event['custom_data'] != '') {
$tabs .= "- ".html_print_image('images/custom_field_col.png', true)."".__('Custom data').'
';
}
$tabs .= '
';
// Get criticity image.
switch ($event['criticity']) {
default:
case 0:
$img_sev = 'images/status_sets/default/severity_maintenance_rounded.png';
break;
case 1:
$img_sev = 'images/status_sets/default/severity_informational_rounded.png';
break;
case 2:
$img_sev = 'images/status_sets/default/severity_normal_rounded.png';
break;
case 3:
$img_sev = 'images/status_sets/default/severity_warning_rounded.png';
break;
case 4:
$img_sev = 'images/status_sets/default/severity_critical_rounded.png';
break;
case 5:
$img_sev = 'images/status_sets/default/severity_minor_rounded.png';
break;
case 6:
$img_sev = 'images/status_sets/default/severity_major_rounded.png';
break;
}
if (!$readonly
&& ((tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'EM',
$event['clean_tags'],
$childrens_ids
)) || (tags_checks_event_acl(
$config['id_user'],
$event['id_grupo'],
'EW',
$event['clean_tags'],
$childrens_ids
)))
) {
$responses = events_page_responses($event, $childrens_ids);
} else {
$responses = '';
}
$console_url = '';
// If metaconsole switch to node to get details and custom fields.
if ($meta) {
$server = metaconsole_get_connection_by_id($server_id);
metaconsole_connect($server);
} else {
$server = '';
}
$details = events_page_details($event, $server);
if (events_has_extended_info($event['id_evento']) === true) {
$related = events_page_related($event, $server);
}
// Juanma (09/05/2014) Fix: Needs to reconnect to node, in previous funct
// node connection was lost.
if ($meta) {
$server = metaconsole_get_connection_by_id($server_id);
metaconsole_connect($server);
}
$custom_fields = events_page_custom_fields($event);
$custom_data = events_page_custom_data($event);
if ($meta) {
metaconsole_restore_db();
}
$general = events_page_general($event);
$comments = events_page_comments($event, $childrens_ids);
$notifications = '';
$notifications .= '';
$notifications .= ''.ui_print_error_message(__('Error changing event status'), '', true).'
';
$notifications .= ''.ui_print_success_message(__('Event status changed successfully'), '', true).'
';
$notifications .= ''.ui_print_error_message(__('Error changing event owner'), '', true).'
';
$notifications .= ''.ui_print_success_message(__('Event owner changed successfully'), '', true).'
';
$loading = ''.html_print_image('images/spinner.gif', true).'
';
$out = ''.$tabs.$notifications.$loading.$general.$details.$related.$custom_fields.$comments.$responses.$custom_data.html_print_input_hidden('id_event', $event['id_evento']).'
';
$js = '';
echo $out.$js;
}
if ($get_events_details) {
$event_ids = explode(',', get_parameter('event_ids'));
$events = db_get_all_rows_filter(
'tevento',
[
'id_evento' => $event_ids,
'order' => 'utimestamp ASC',
],
[
'evento',
'utimestamp',
'estado',
'criticity',
'id_usuario',
],
'AND',
true
);
$out = '';
$out .= ' | |
';
foreach ($events as $event) {
switch ($event['estado']) {
case 0:
$img = ui_get_full_url('images/star.png', false, false, false);
$title = __('New event');
break;
case 1:
$img = ui_get_full_url('images/tick.png', false, false, false);
$title = __('Event validated');
break;
case 2:
$img = ui_get_full_url('images/hourglass.png', false, false, false);
$title = __('Event in process');
break;
default:
// Ignore.
break;
}
$out .= '';
$out .= '';
$out .= io_safe_output($event['evento']);
$out .= ' |
';
$out .= '';
$out .= '';
$out .= html_print_image(ui_get_full_url('images/clock.png', false, false, false), true, ['title' => __('Timestamp')], false, true);
$out .= ' | ';
$out .= '';
$out .= date($config['date_format'], $event['utimestamp']);
$out .= ' |
';
$out .= '';
$out .= '';
$out .= html_print_image($img, true, ['title' => $title], false, true);
$out .= ' | ';
$out .= '';
$out .= $title;
if ($event['estado'] == 1) {
if (empty($event['id_usuario'])) {
$ack_user = ''.__('Auto').'';
} else {
$ack_user = $event['id_usuario'];
}
$out .= ' ('.$ack_user.')';
}
$out .= ' |
';
$out .= ' | ';
$out .= ' |
| ';
$out .= ' |
';
}
$out .= '
';
echo $out;
}
if ($table_events) {
include_once 'include/functions_events.php';
include_once 'include/functions_graph.php';
$id_agente = (int) get_parameter('id_agente', 0);
$all_events_24h = (int) get_parameter('all_events_24h', 0);
// Fix: for tag functionality groups have to be all user_groups
// (propagate ACL funct!).
$groups = users_get_groups($config['id_user']);
$tags_condition = tags_get_acl_tags(
$config['id_user'],
array_keys($groups),
'ER',
'event_condition',
'AND'
);
echo '';
echo '';
echo html_print_switch(
[
'name' => 'all_events_24h',
'value' => $all_events_24h,
'id' => 'checkbox-all_events_24h',
]
);
echo '
';
$date_subtract_day = (time() - (24 * 60 * 60));
if ($all_events_24h) {
events_print_event_table(
'utimestamp > '.$date_subtract_day,
200,
'100%',
false,
$id_agente,
true
);
} else {
events_print_event_table(
'estado <> 1 '.$tags_condition,
200,
'100%',
false,
$id_agente,
true
);
}
}
if ($get_list_events_agents) {
global $config;
$id_agent = get_parameter('id_agent');
$server_id = get_parameter('server_id');
$event_type = get_parameter('event_type');
$severity = get_parameter('severity');
$status = get_parameter('status');
$search = get_parameter('search');
$id_agent_module = get_parameter('id_agent_module');
$event_view_hr = get_parameter('event_view_hr');
$id_user_ack = get_parameter('id_user_ack');
$tag_with = get_parameter('tag_with');
$tag_without = get_parameter('tag_without');
$filter_only_alert = get_parameter('filter_only_alert');
$date_from = get_parameter('date_from');
$date_to = get_parameter('date_to');
$id_user = $config['id_user'];
$server_id = get_parameter('server_id');
$returned_sql = events_sql_events_grouped_agents(
$id_agent,
$server_id,
$event_type,
$severity,
$status,
$search,
$id_agent_module,
$event_view_hr,
$id_user_ack,
$tag_with,
$tag_without,
$filter_only_alert,
$date_from,
$date_to,
$id_user
);
$returned_list = events_list_events_grouped_agents($returned_sql);
echo $returned_list;
return;
}
if ($total_events) {
global $config;
$sql_count_event = 'SELECT SQL_NO_CACHE COUNT(id_evento) FROM tevento ';
if ($config['event_view_hr']) {
$sql_count_event .= 'WHERE utimestamp > (UNIX_TIMESTAMP(NOW()) - '.($config['event_view_hr'] * SECONDS_1HOUR).')';
}
$system_events = db_get_value_sql($sql_count_event);
echo $system_events;
return;
}
if ($total_event_graph) {
global $config;
include_once $config['homedir'].'/include/functions_graph.php';
$prueba = grafico_eventos_total('', 280, 150, false, true);
echo $prueba;
return;
}
if ($graphic_event_group) {
global $config;
include_once $config['homedir'].'/include/functions_graph.php';
$prueba = grafico_eventos_grupo(280, 150, '', false, true);
echo $prueba;
return;
}
if ($get_table_response_command) {
global $config;
$response_id = get_parameter('event_response_id');
$params_string = db_get_value(
'params',
'tevent_response',
'id',
$response_id
);
$params = explode(',', $params_string);
$table = new stdClass;
$table->id = 'events_responses_table_command';
$table->width = '90%';
$table->styleTable = 'text-align:center; margin: 0 auto;';
$table->style = [];
$table->style[0] = 'text-align:center;';
$table->style[1] = 'text-align:center;';
$table->head = [];
$table->head[0] = __('Parameters');
$table->head[0] .= ui_print_help_tip(
__('These commands will apply to all selected events'),
true
);
$table->head[1] = __('Value');
if (isset($params) === true
&& is_array($params) === true
) {
foreach ($params as $key => $value) {
$table->data[$key][0] = $value;
$table->data[$key][1] = html_print_input_text(
$value.'-'.$key,
'',
'',
50,
255,
true,
false,
false,
'',
'response_command_input'
);
}
}
echo '';
echo html_print_submit_button(
__('Execute'),
'enter_command',
false,
'class="sub next" style="float:right; margin-top:15px; margin-right:25px;"',
true
);
return;
}