'.$agent_name.ui_print_help_tip(__('Disabled'), true);
} else {
$agent_name = ''.$agent_name.''.ui_print_help_tip(__('Disabled'), true);
}
} else if ($agent['quiet']) {
if ($in_planned_downtime) {
$agent_name = "".$agent_name.' '.html_print_image('images/dot_blue.png', true, ['border' => '0', 'title' => __('Quiet'), 'alt' => '']);
} else {
$agent_name = "".$agent_name.' '.html_print_image('images/dot_blue.png', true, ['border' => '0', 'title' => __('Quiet'), 'alt' => '']).'';
}
} else {
$agent_name = $agent_name;
}
if ($in_planned_downtime && !$agent['disabled'] && !$agent['quiet']) {
$agent_name .= ' '.ui_print_help_tip(
__('Agent in planned downtime'),
true,
'images/minireloj-16.png'
).'';
} else if (($in_planned_downtime && !$agent['disabled'])
|| ($in_planned_downtime && !$agent['quiet'])
) {
$agent_name .= ' '.ui_print_help_tip(
__('Agent in planned downtime'),
true,
'images/minireloj-16.png'
).'';
}
$table_agent_header = '
';
$table_agent_header .= $agent_name;
$table_agent_header .= '
';
$table_agent_header .= '';
if (!$config['show_group_name']) {
$table_agent_header .= ui_print_group_icon(
$agent['id_grupo'],
true,
'groups_small',
'padding-right: 6px;'
);
}
$table_agent_header .= '
';
$status_img = agents_detail_view_status_img(
$agent['critical_count'],
$agent['warning_count'],
$agent['unknown_count'],
$agent['total_count'],
$agent['notinit_count']
);
$table_agent_header .= ''.$status_img.'
';
// Fixed width non interactive charts.
$status_chart_width = 180;
$graph_width = 180;
$table_agent_graph = '';
$table_agent_graph .= graph_agent_status(
$id_agente,
$graph_width,
$graph_width,
true,
false,
false,
true
);
$table_agent_graph .= '
';
$table_agent_os = ''.ui_print_os_icon(
$agent['id_os'],
false,
true,
true,
false,
false,
false,
['title' => __('OS').': '.get_os_name($agent['id_os'])]
);
$table_agent_os .= (empty($agent['os_version'])) ? get_os_name((int) $agent['id_os']) : $agent['os_version'].'
';
$addresses = agents_get_addresses($id_agente);
$address = agents_get_address($id_agente);
foreach ($addresses as $k => $add) {
if ($add == $address) {
unset($addresses[$k]);
}
}
if (!empty($address)) {
$table_agent_ip = ''.html_print_image('images/world.png', true, ['title' => __('IP address')]);
$table_agent_ip .= '';
$table_agent_ip .= empty($address) ? ''.__('N/A').'' : $address;
$table_agent_ip .= '
';
}
$table_agent_version = ''.html_print_image('images/version.png', true, ['title' => __('Agent Version')]);
$table_agent_version .= '';
$table_agent_version .= empty($agent['agent_version']) ? ''.__('N/A').'' : $agent['agent_version'];
$table_agent_version .= '
';
$table_agent_description = ''.html_print_image(
'images/default_list.png',
true,
['title' => __('Description')]
);
$table_agent_description .= '';
$table_agent_description .= empty($agent['comentarios']) ? ''.__('N/A').'' : $agent['comentarios'];
$table_agent_description .= '
';
$table_agent_count_modules = reporting_tiny_stats(
$agent,
true,
'agent',
// Useless.
':',
true
);
$has_remote_conf = enterprise_hook(
'config_agents_has_remote_configuration',
[$agent['id_agente']]
);
if ($has_remote_conf) {
$remote_cfg = ''.html_print_image('images/remote_configuration.png', true);
$remote_cfg .= __('Remote configuration enabled').'
';
} else {
$remote_cfg = '';
}
// $table_agent_count_modules .= ui_print_help_tip(__('Agent statuses are re-calculated by the server, they are not shown in real time.'), true);
$table_agent = '
'.$table_agent_graph.'
'.$table_agent_count_modules.'
'.$alive_animation.$table_agent_os.$table_agent_ip.$table_agent_version.$table_agent_description.$remote_cfg.'
';
/*
* END: TABLE AGENT BUILD.
*/
/*
*START: TABLE CONTACT BUILD.
*/
$table_contact = new stdClass();
$table_contact->id = 'agent_contact_main';
$table_contact->width = '100%';
$table_contact->cellspacing = 0;
$table_contact->cellpadding = 0;
$table_contact->class = 'white_table white_table_no_border';
$table_contact->style[0] = 'width: 30%;';
$table_contact->style[1] = 'width: 70%;';
$table_contact->headstyle[1] = 'padding-top:6px; padding-bottom:6px;padding-right: 10px;';
$table_contact->head[0] = ' '.__('Agent contact').'';
$buttons_refresh_agent_view = '';
$table_contact->head[1] = $buttons_refresh_agent_view;
$data = [];
$data[0] = ''.__('Interval').'';
$data[1] = human_time_description_raw($agent['intervalo']);
$table_contact->data[] = $data;
$data = [];
$data[0] = ''.__('Last contact').' / '.__('Remote').'';
$data[1] = ui_print_timestamp($agent['ultimo_contacto'], true);
$data[1] .= ' / ';
if ($agent['ultimo_contacto_remoto'] == '01-01-1970 00:00:00') {
$data[1] .= __('Never');
} else {
$data[1] .= date_w_fixed_tz($agent['ultimo_contacto_remoto']);
}
$table_contact->data[] = $data;
$data = [];
$data[0] = ''.__('Next contact').'';
$progress = agents_get_next_contact($id_agente);
$data[1] = ui_progress(
$progress,
'100%',
1.8,
'#BBB',
true,
($agent['intervalo'] - (strtotime('now') - strtotime($agent['ultimo_contacto']))).' s',
[
'page' => 'operation/agentes/ver_agente',
'interval' => (100 / $agent['intervalo']),
'data' => [
'id_agente' => $id_agente,
'refresh_contact' => 1,
],
]
);
if ($progress > 100) {
$data[0] .= clippy_context_help('agent_out_of_limits');
}
$table_contact->data[] = $data;
$data = [];
$data[0] = ''.__('Group').'';
$data[1] = ''.groups_get_name($agent['id_grupo']).'';
$table_contact->data[] = $data;
$data = [];
$data[0] = ''.__('Secondary groups').'';
$secondary_groups = enterprise_hook('agents_get_secondary_groups', [$id_agente]);
if (!$secondary_groups) {
$data[1] = ''.__('N/A').'';
} else {
$secondary_links = [];
foreach ($secondary_groups['for_select'] as $id => $name) {
$secondary_links[] = ''.$name.'';
}
$data[1] = implode(', ', $secondary_links);
}
$table_contact->data[] = $data;
if (enterprise_installed()) {
$data = [];
$data[0] = ''.__('Parent').'';
if ($agent['id_parent'] == 0) {
$data[1] = ''.__('N/A').'';
} else {
$data[1] = ''.agents_get_alias($agent['id_parent']).'';
}
$table_contact->data[] = $data;
}
$data = [];
$data[0] = ''.__('Last status change').'';
$last_status_change_agent = agents_get_last_status_change($agent['id_agente']);
$time_elapsed = !empty($last_status_change_agent) ? human_time_comparation($last_status_change_agent) : ''.__('N/A').'';
$data[1] = $time_elapsed;
$table_contact->data[] = $data;
/*
* END: TABLE CONTACT BUILD
*/
/*
* START: TABLE DATA BUILD
*/
$table_data = new stdClass();
$table_data->id = 'agent_data_main';
$table_data->width = '100%';
$table_data->cellspacing = 0;
$table_data->cellpadding = 0;
$table_data->class = 'box-shadow white_table white_table_droppable align-top';
$table_data->style = array_fill(0, 3, 'width: 25%;');
$table_data->head[0] = html_print_image(
'images/arrow_down_green.png',
true,
$options
);
$table_data->head[0] .= ' '.__('Agent info').'';
$table_data->head_colspan[0] = 4;
// Gis and url address.
$data_opcional = [];
// Position Information.
if ($config['activate_gis']) {
$data_opcional[] = ''.__('Position (Long, Lat)').'';
$dataPositionAgent = gis_get_data_last_position_agent(
$agent['id_agente']
);
if ($dataPositionAgent === false) {
$data_opcional[] = __('There is no GIS data.');
} else {
$data_opcional[] = '';
if ($dataPositionAgent['description'] != '') {
$data_opcional[] .= $dataPositionAgent['description'];
} else {
$data_opcional[] .= $dataPositionAgent['stored_longitude'].', '.$dataPositionAgent['stored_latitude'];
}
$data_opcional[] .= '';
}
array_push($data_opcional);
}
// If the url description is set.
if ($agent['url_address'] != '') {
// $data_opcional = [];
$data_opcional[] = ''.__('Url address').'';
if ($agent['url_address'] != '') {
$data_opcional[] = ''.$agent['url_address'].'';
}
}
// Other IP address and timezone offset.
if (!empty($addresses)) {
// $data_opcional = [];
$data_opcional[] = ''.__('Other IP addresses').'';
if (!empty($addresses)) {
$data_opcional[] = ''.implode('
', $addresses).'
';
}
}
// Timezone Offset.
if ($agent['timezone_offset'] != 0) {
$data_opcional[] = ''.__('Timezone Offset').'';
if ($agent['timezone_offset'] != 0) {
$data_opcional[] = $agent['timezone_offset'];
}
}
$data_opcional = array_chunk($data_opcional, 4);
foreach ($data_opcional as $key => $value) {
$table_data->data[] = $data_opcional[$key];
}
// Custom fields.
$fields = db_get_all_rows_filter(
'tagent_custom_fields',
['display_on_front' => 1]
);
if ($fields === false) {
$fields = [];
}
$custom_fields = [];
foreach ($fields as $field) {
$custom_value = db_get_all_rows_sql(
'select tagent_custom_data.description,tagent_custom_fields.is_password_type from tagent_custom_fields
INNER JOIN tagent_custom_data ON tagent_custom_fields.id_field = tagent_custom_data.id_field where tagent_custom_fields.id_field = '.$field['id_field'].' and tagent_custom_data.id_agent = '.$id_agente
);
if ($custom_value[0]['description'] !== false && $custom_value[0]['description'] != '') {
$data = [];
$data[0] = ''.$field['name'].ui_print_help_tip(__('Custom field'), true).'';
$custom_value[0]['description'] = ui_bbcode_to_html($custom_value[0]['description']);
if ($custom_value[0]['is_password_type']) {
$data[1] = '••••••••';
} else {
$data[1] = $custom_value[0]['description'];
}
$custom_fields[] = $data;
}
}
$custom_fields_count = count($custom_fields);
for ($i = 0; $i < $custom_fields_count; $i++) {
$first_column = $custom_fields[$i];
$j = ($i + 1);
$second_column = $custom_fields[$j];
if (is_array($second_column)) {
$columns = array_merge($first_column, $second_column);
} else {
$columns = $first_column;
$filas = count($table_data->data);
$table_data->colspan[$filas][1] = 3;
}
$table_data->data[] = $columns;
$i++;
}
/*
* END: TABLE DATA BUILD
*/
/*
* START: ACCESS RATE GRAPH
*/
$access_agent = db_get_value_sql(
'SELECT COUNT(id_agent)
FROM tagent_access
WHERE id_agent = '.$id_agente
);
if ($config['agentaccess'] && $access_agent > 0) {
$table_access_rate = '';
$table_access_rate .= '';
$table_access_rate .= '
';
$table_access_rate .= graphic_agentaccess(
$id_agente,
SECONDS_1DAY,
true
);
$table_access_rate .= '
';
$table_access_rate .= '
';
}
/*
* END: ACCESS RATE GRAPH
*/
/*
* START: TABLE INCIDENTS
*/
$last_incident = db_get_row_sql(
sprintf(
'SELECT * FROM tincidencia
WHERE estado IN (0,1)
AND id_agent = %d
ORDER BY actualizacion DESC',
$id_agente
)
);
if ($last_incident != false) {
$table_incident->id = 'agent_incident_main';
$table_incident->width = '100%';
$table_incident->cellspacing = 0;
$table_incident->cellpadding = 0;
$table_incident->class = 'white_table';
$table_incident->style = array_fill(0, 3, 'width: 25%;');
$table_incident->head[0] = ' '.__('Active incident on this agent').'';
$table_incident->head_colspan[0] = 4;
$data = [];
$data[0] = ''.__('Author').'';
$data[1] = $last_incident['id_creator'];
$data[2] = ''.__('Timestamp').'';
$data[3] = $last_incident['inicio'];
$table_incident->data[] = $data;
$data = [];
$data[0] = ''.__('Title').'';
$data[1] = ''.$last_incident['titulo'].'';
$data[2] = ''.__('Priority').'';
$data[3] = incidents_print_priority_img($last_incident['prioridad'], true);
$table_incident->data[] = $data;
}
/*
* END: TABLE INCIDENTS
*/
/*
* START: TABLE INTERFACES
*/
$network_interfaces_by_agents = agents_get_network_interfaces([$agent]);
$network_interfaces = [];
if (!empty($network_interfaces_by_agents) && !empty($network_interfaces_by_agents[$id_agente])) {
$network_interfaces = $network_interfaces_by_agents[$id_agente]['interfaces'];
}
if (!empty($network_interfaces)) {
$table_interface = new stdClass();
$table_interface->id = 'agent_interface_info';
$table_interface->class = 'info_table';
$table_interface->width = '100%';
$table_interface->style = [];
$table_interface->style['interface_status'] = 'width: 30px;padding-top:0px;padding-bottom:0px;';
$table_interface->style['interface_graph'] = 'width: 20px;padding-top:0px;padding-bottom:0px;';
$table_interface->style['interface_event_graph'] = 'width: 35%;padding-top:0px;padding-bottom:0px;';
$table_interface->align['interface_event_graph'] = 'right';
// $table_interface->style['interface_event_graph'] = 'width: 5%;padding-top:0px;padding-bottom:0px;';
$table_interface->align['interface_event_graph_text'] = 'left';
$table_interface->style['interface_name'] = 'width: 10%;padding-top:0px;padding-bottom:0px;';
$table_interface->align['interface_name'] = 'left';
$table_interface->align['interface_ip'] = 'left';
$table_interface->align['last_contact'] = 'left';
$table_interface->style['last_contact'] = 'width: 20%;padding-top:0px;padding-bottom:0px;';
$table_interface->style['interface_ip'] = 'width: 8%;padding-top:0px;padding-bottom:0px;';
$table_interface->style['interface_mac'] = 'width: 12%;padding-top:0px;padding-bottom:0px;';
$table_interface->head = [];
$options = [
'class' => 'closed',
'style' => 'cursor:pointer;',
];
$table_interface->data = [];
$event_text_cont = 0;
foreach ($network_interfaces as $interface_name => $interface) {
if (!empty($interface['traffic'])) {
$permission = check_acl_one_of_groups($config['id_user'], $all_groups, 'RR');
if ($permission) {
$params = [
'interface_name' => $interface_name,
'agent_id' => $id_agente,
'traffic_module_in' => $interface['traffic']['in'],
'traffic_module_out' => $interface['traffic']['out'],
];
$params_json = json_encode($params);
$params_encoded = base64_encode($params_json);
$win_handle = dechex(crc32($interface['status_module_id'].$interface_name));
$graph_link = "";
$graph_link .= html_print_image(
'images/chart_curve.png',
true,
['title' => __('Interface traffic')]
).'';
} else {
$graph_link = '';
}
} else {
$graph_link = '';
}
$events_limit = 5000;
$user_groups = users_get_groups($config['id_user'], 'ER');
$user_groups_ids = array_keys($user_groups);
if (empty($user_groups)) {
$groups_condition = ' 1 = 0 ';
} else {
$groups_condition = ' id_grupo IN ('.implode(',', $user_groups_ids).') ';
}
if (!check_acl($config['id_user'], 0, 'PM')) {
$groups_condition .= ' AND id_grupo != 0';
}
$status_condition = ' AND (estado = 0 OR estado = 1) ';
$unixtime = (get_system_time() - SECONDS_1DAY);
// Last hour.
$time_condition = 'AND (utimestamp > '.$unixtime.')';
// Tags ACLs.
if ($id_group > 0 && in_array(0, $user_groups_ids)) {
$group_array = (array) $id_group;
} else {
$group_array = $user_groups_ids;
}
$acl_tags = tags_get_acl_tags(
$config['id_user'],
$group_array,
'ER',
'event_condition',
'AND',
'',
true,
[],
true
);
$id_modules_array = [];
$id_modules_array[] = $interface['status_module_id'];
$unixtime = (get_system_time() - SECONDS_1DAY);
// Last hour.
$time_condition = 'WHERE (te.utimestamp > '.$unixtime.')';
$sqlEvents = sprintf(
'SELECT *
FROM tevento te
INNER JOIN tagente_estado tae
ON te.id_agentmodule = tae.id_agente_modulo
AND tae.id_agente_modulo IN (%s)
%s',
implode(',', $id_modules_array),
$time_condition
);
$sqlLast_contact = sprintf(
'
SELECT timestamp
FROM tagente_estado
WHERE id_agente_modulo = '.$interface['status_module_id']
);
$last_contact = db_get_all_rows_sql($sqlLast_contact);
$last_contact = array_shift($last_contact);
$last_contact = array_shift($last_contact);
$events = db_get_all_rows_sql($sqlEvents);
$text_event_header = __('Events info (24hr.)');
if (!$events) {
$no_events = ['color' => ['criticity' => 2]];
$e_graph = reporting_get_event_histogram(
$no_events,
$text_event_header
);
} else {
$e_graph = reporting_get_event_histogram(
$events,
$text_event_header
);
}
$data = [];
$data['interface_name'] = ''.$interface_name.'';
$data['interface_status'] = $interface['status_image'];
$data['interface_graph'] = $graph_link;
$data['interface_ip'] = $interface['ip'];
$data['interface_mac'] = $interface['mac'];
$data['last_contact'] = __('Last contact: ').$last_contact;
$data['interface_event_graph'] = $e_graph;
if ($event_text_cont == 0) {
$data['interface_event_graph_text'] = ui_print_help_tip('Module events graph', true);
$event_text_cont++;
} else {
$data['interface_event_graph_text'] = '';
}
$table_interface->data[] = $data;
}
}
/*
* END: TABLE INTERFACES
*/
// This javascript piece of code is used to make expandible
// the body of the table.
?>
';
$table_events .= '';
$table_events .= '';
$table_events .= graph_graphic_agentevents(
$id_agente,
95,
70,
SECONDS_1DAY,
'',
true,
true,
500
);
$table_events .= '
';
$table_events .= '';
/*
* EVENTS TABLE END.
*/
$agent_contact = html_print_table($table_contact, true);
if (empty($table_data->data)) {
$agent_info = '';
} else {
if (count($table_data->data) === 1 && $config['activate_gis'] && $dataPositionAgent === false) {
$agent_info = '';
} else {
$agent_info = html_print_table($table_data, true);
}
}
$agent_incidents = !isset($table_incident) ? '' : html_print_table($table_incident, true);
echo '
'.$table_agent.'
'.$agent_contact.'
'.$agent_info;
// Show both graphs, events and access rate.
if ($table_access_rate) {
echo ''.$table_access_rate.$table_events.'
';
} else {
echo ''.$table_events.'
';
}
echo $agent_incidents;
if (isset($table_interface)) {
ui_toggle(
html_print_table($table_interface, true),
''.__('Interface information (SNMP)').'',
'',
'interface-table-status-agent',
true
);
}