';
} else {
$data[9] = '';
}
$data[9] .= ui_print_timestamp($module['utimestamp'], true, ['style' => 'font-size: 7pt']);
$data[9] .= '';
array_push($table->data, $data);
$rowIndex++;
}
ui_require_javascript_file('pandora.js');
?>
data)) {
if ($filter_monitors) {
ui_print_info_message([ 'no_close' => true, 'message' => __('Any monitors aren\'t with this filter.') ]);
} else {
ui_print_info_message([ 'no_close' => true, 'message' => __('This agent doesn\'t have any active monitors.') ]);
}
} else {
$url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agente.'&refr=&filter_monitors=1&status_filter_monitor='.$status_filter_monitor.'&status_text_monitor='.$status_text_monitor.'&status_module_group='.$status_module_group;
if ($paginate_module) {
ui_pagination(
$count_modules,
false,
0,
0,
false,
'offset',
true,
'',
'pagination_list_modules(offset_param)',
[
'count' => '',
'offset' => 'offset_param',
]
);
}
html_print_table($table);
if ($paginate_module) {
ui_pagination(
$count_modules,
false,
0,
0,
false,
'offset',
true,
'pagination-bottom',
'pagination_list_modules(offset_param)',
[
'count' => '',
'offset' => 'offset_param',
]
);
}
}
unset($table);
unset($table_data);
}
if ($get_type) {
$id_module = (int) get_parameter('id_module');
$module = modules_get_agentmodule($id_module);
$graph_type = return_graphtype($module['id_tipo_modulo']);
echo $graph_type;
return;
}
if ($get_graph_module === true) {
global $config;
$output = '';
$graph_data = get_parameter('graph_data', '');
$params = json_decode(base64_decode($graph_data), true);
$server_id = (int) get_parameter('server_id', 0);
include_once $config['homedir'].'/include/functions_graph.php';
// Metaconsole connection to the node.
if (is_metaconsole() === true && empty($server_id) === false) {
$server = metaconsole_get_connection_by_id($server_id);
metaconsole_connect($server);
}
if ($params['histogram'] === true) {
$params['id_agent_module'] = $params['agent_module_id'];
$params['dinamic_proc'] = 1;
$output .= '';
if ($params['compare'] === 'separated') {
$graph = \reporting_module_histogram_graph(
['datetime' => ($params['begin_date'] - $params['period'])],
$params
);
$output .= $graph['chart'];
}
$graph = \reporting_module_histogram_graph(
['datetime' => $params['begin_date']],
$params
);
$output .= $graph['chart'];
$output .= '
';
} else {
$output .= grafico_modulo_sparse($params);
}
if (is_metaconsole() === true && empty($server_id) === false) {
metaconsole_restore_db();
}
echo $output;
return;
}
if ($get_graph_module_interfaces === true) {
global $config;
include_once $config['homedir'].'/include/functions_graph.php';
$output = '';
$graph_data = get_parameter('graph_data', '');
$params = json_decode(base64_decode($graph_data), true);
$modules = get_parameter('modules', '');
$modules = json_decode(base64_decode($modules), true);
$graph_data_combined = get_parameter('graph_data_combined', '');
$params_combined = json_decode(
base64_decode($graph_data_combined),
true
);
$output .= graphic_combined_module(
$modules,
$params,
$params_combined
);
echo $output;
return;
}
if ($get_data_dataMatrix === true) {
global $config;
$table_id = get_parameter('table_id', '');
$modules = json_decode(
io_safe_output(
get_parameter('modules', '')
),
true
);
$period = get_parameter('period', 0);
$slice = get_parameter('slice', 0);
// Datatables offset, limit.
$start = get_parameter('start', 0);
$formatData = (bool) get_parameter('formatData', 0);
$length = get_parameter(
'length',
$config['block_size']
);
$order = get_datatable_order(true);
// Total time per page.
$time_all_box = ($length * $slice);
// Total number of boxes.
$total_box = ceil($period / $slice);
if ($start > 0) {
$start = ($start / $length);
}
// Uncompress.
try {
ob_start();
$dateNow = get_system_time();
$final = ($dateNow - $period);
$date = ($dateNow - ($time_all_box * $start));
if (($date - $time_all_box) > $final) {
$datelimit = ($date - $time_all_box);
} else {
$datelimit = $final;
}
foreach ($modules as $key => $value) {
if (is_metaconsole() === true) {
try {
$node = new Node((int) $value['id_node']);
$node->connect();
} catch (\Exception $e) {
// Unexistent agent.
$node->disconnect();
}
}
$value['thresholds'] = [
'min_critical' => (empty($value['c_min']) === true) ? null : $value['c_min'],
'max_critical' => (empty($value['c_max']) === true) ? null : $value['c_max'],
'min_warning' => (empty($value['w_min']) === true) ? null : $value['w_min'],
'max_warning' => (empty($value['w_max']) === true) ? null : $value['w_max'],
];
$module_data = db_uncompress_module_data(
$value['id'],
$datelimit,
$date,
$slice,
true
);
$uncompressData[] = array_reduce(
$module_data,
function ($carry, $item) use ($value, $config, $formatData) {
// Last value.
$vdata = null;
if (is_array($item['data']) === true) {
foreach ($item['data'] as $v) {
$vdata = $v['datos'];
}
}
$status = get_status_data_modules(
$value['id'],
$vdata,
$value['thresholds']
);
$resultData = '';
if ($vdata !== null && $vdata !== '' && $vdata !== false) {
if (isset($formatData) === true
&& (bool) $formatData === true
) {
$resultData .= format_for_graph(
$vdata,
$config['graph_precision']
);
} else {
$resultData .= sla_truncate(
$vdata,
$config['graph_precision']
);
}
$resultData .= ' '.$value['unit'];
} else {
$resultData .= '--';
}
$resultData .= '';
$carry[] = [
'utimestamp' => $item['utimestamp'],
'Column-'.$value['id'] => $resultData,
];
return $carry;
},
[]
);
if (is_metaconsole() === true) {
$node->disconnect();
}
}
if (empty($uncompressData) === false) {
$data = array_reduce(
$uncompressData,
function ($carry, $item) {
foreach ($item as $data_module) {
foreach ($data_module as $key => $value) {
if ($key === 'utimestamp') {
$carry[$data_module['utimestamp']]['date'] = date('Y-m-d H:i', (int) $value);
} else {
$carry[$data_module['utimestamp']][$key] = $value;
}
}
}
return $carry;
}
);
}
if (empty($data) === false) {
$data = array_reverse(array_values($data));
} else {
$data = [];
}
// RecordsTotal && recordsfiltered resultados totales.
echo json_encode(
[
'data' => $data,
'recordsTotal' => $total_box,
'recordsFiltered' => $total_box,
]
);
$response = ob_get_clean();
// Clean output buffer.
while (ob_get_level() !== 0) {
ob_end_clean();
}
} catch (Exception $e) {
echo json_encode(
['error' => $e->getMessage()]
);
}
// If not valid it will throw an exception.
json_decode($response);
if (json_last_error() == JSON_ERROR_NONE) {
// If valid dump.
echo $response;
} else {
echo json_encode(
['error' => $response]
);
}
return;
}
if ($get_children_modules === true) {
$parent_modules = get_parameter('parent_modulues', false);
$children_selected = [];
if ($parent_modules === false) {
$children_selected = false;
} else {
foreach ($parent_modules as $parent) {
$child_modules = get_children_module($parent_modules, ['nombre', 'id_agente_modulo'], true);
if ((bool) $child_modules === false) {
continue;
}
foreach ($child_modules as $child) {
$module_exist = in_array($child['id_agente_modulo'], $parent_modules);
$child_exist = in_array($child, $children_selected);
if ($module_exist === false && $child_exist === false) {
array_push($children_selected, $child);
}
}
}
}
if (empty($children_selected) === true) {
$children_selected = false;
}
echo json_encode($children_selected);
return;
}
// Saves an event filter.
if ($save_monitor_filter) {
$values = [];
$values['id_name'] = get_parameter('id_name');
$values['id_group_filter'] = get_parameter('id_group_filter');
$values['ag_group'] = get_parameter('ag_group');
$values['modulegroup'] = get_parameter('modulegroup');
$values['recursion'] = get_parameter('recursion');
$values['status'] = get_parameter('status');
$values['ag_modulename'] = get_parameter('ag_modulename');
$values['ag_freestring'] = get_parameter('ag_freestring');
$values['tag_filter'] = json_encode(get_parameter('tag_filter'));
$values['moduletype'] = get_parameter('moduletype');
$values['module_option'] = get_parameter('module_option');
$values['min_hours_status'] = get_parameter('min_hours_status');
$values['datatype'] = get_parameter('datatype');
$values['not_condition'] = get_parameter('not_condition');
$values['ag_custom_fields'] = get_parameter('ag_custom_fields');
$exists = (bool) db_get_value_filter(
'id_filter',
'tmonitor_filter',
$values
);
if ($exists === true) {
echo 'duplicate';
} else {
$result = db_process_sql_insert('tmonitor_filter', $values);
if ($result === false) {
echo 'error';
} else {
echo $result;
}
}
}
if ($update_monitor_filter) {
$values = [];
$id = get_parameter('id');
$values['ag_group'] = get_parameter('ag_group');
$values['modulegroup'] = get_parameter('modulegroup');
$values['recursion'] = get_parameter('recursion');
$values['status'] = get_parameter('status');
$values['ag_modulename'] = get_parameter('ag_modulename');
$values['ag_freestring'] = get_parameter('ag_freestring');
$values['tag_filter'] = json_encode(get_parameter('tag_filter'));
$values['moduletype'] = get_parameter('moduletype');
$values['module_option'] = get_parameter('module_option');
$values['min_hours_status'] = get_parameter('min_hours_status');
$values['datatype'] = get_parameter('datatype');
$values['not_condition'] = get_parameter('not_condition');
$values['ag_custom_fields'] = get_parameter('ag_custom_fields');
$result = db_process_sql_update(
'tmonitor_filter',
$values,
['id_filter' => $id]
);
if ($result === false) {
echo 'error';
} else {
echo 'ok';
}
}
if ($get_monitor_filters) {
$sql = 'SELECT id_filter, id_name FROM tmonitor_filter';
$monitor_filters = db_get_all_rows_sql($sql);
$result = [];
if ($monitor_filters !== false) {
foreach ($monitor_filters as $monitor_filter) {
$result[$monitor_filter['id_filter']] = $monitor_filter['id_name'];
}
}
echo io_json_mb_encode($result);
}
if ((int) $load_filter_modal === 1) {
$user_groups = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all(),
true
);
$sql = 'SELECT id_filter, id_name
FROM tmonitor_filter
WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$event_filters = db_get_all_rows_sql($sql);
$filters = [];
foreach ($event_filters as $event_filter) {
$filters[$event_filter['id_filter']] = $event_filter['id_name'];
}
echo '';
echo '';
echo '
';
?>
';
if (check_acl($config['id_user'], 0, 'AW')) {
echo '';
$table = new StdClass;
$table->id = 'save_filter_form';
$table->width = '100%';
$table->cellspacing = 4;
$table->cellpadding = 4;
$table->class = 'databox';
if (is_metaconsole()) {
$table->class = 'databox filters';
$table->cellspacing = 0;
$table->cellpadding = 0;
}
$table->styleTable = 'font-weight: bold; text-align:left;';
if (!is_metaconsole()) {
$table->style[0] = 'width: 50%; width:50%;';
}
$data = [];
$table->rowid[0] = 'update_save_selector';
$data[0] = html_print_radio_button(
'filter_mode',
'new',
'',
true,
true
).__('New filter').'';
$data[1] = html_print_radio_button(
'filter_mode',
'update',
'',
false,
true
).__('Update filter').'';
$table->data[] = $data;
$table->rowclass[] = '';
$data = [];
$table->rowid[1] = 'save_filter_row1';
$data[0] = __('Filter name').$jump;
$data[0] .= html_print_input_text('id_name', '', '', 15, 255, true);
if (is_metaconsole()) {
$data[1] = __('Save in Group').$jump;
} else {
$data[1] = __('Filter group').$jump;
}
$user_groups_array = users_get_groups_for_select(
$config['id_user'],
'AW',
users_can_manage_group_all(),
true
);
$data[1] .= html_print_select(
$user_groups_array,
'id_group_filter_dialog',
$id_group_filter,
'',
'',
0,
true,
false,
false,
'w130'
);
$table->data[] = $data;
$table->rowclass[] = '';
$data = [];
$table->rowid[2] = 'save_filter_row2';
$table->data[] = $data;
$table->rowclass[] = '';
$data = [];
$table->rowid[3] = 'update_filter_row1';
$data[0] = __('Overwrite filter').$jump;
$sql = 'SELECT id_filter, id_name FROM tmonitor_filter';
$monitor_filters = db_get_all_rows_sql($sql);
$_filters_update = [];
if ($monitor_filters !== false) {
foreach ($monitor_filters as $monitor_filter) {
$_filters_update[$monitor_filter['id_filter']] = $monitor_filter['id_name'];
}
}
$data[0] .= html_print_select(
$_filters_update,
'overwrite_filter',
'',
'',
'',
0,
true
);
$data[1] = html_print_submit_button(
__('Update filter'),
'update_filter',
false,
'class="sub upd" onclick="save_update_filter();"',
true
);
$table->data[] = $data;
$table->rowclass[] = '';
html_print_table($table);
echo '';
echo html_print_submit_button(
__('Save filter'),
'save_filter',
false,
'class="sub upd float-right" onclick="save_new_filter();"',
true
);
echo '
';
} else {
include 'general/noaccess.php';
}
echo '';
?>