fixed css errors custom field view and new features
This commit is contained in:
parent
151cba3cbf
commit
e21fde537a
|
@ -0,0 +1,646 @@
|
|||
<?php
|
||||
|
||||
if(check_login()){
|
||||
|
||||
//Pandora FMS- http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License
|
||||
// as published by the Free Software Foundation; 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.
|
||||
|
||||
global $config;
|
||||
|
||||
include_once($config['homedir'] . "/include/functions_agents.php");
|
||||
include_once($config['homedir'] . "/include/functions_modules.php");
|
||||
include_once($config['homedir'] . "/include/functions_ui.php");
|
||||
enterprise_include_once ('include/functions_metaconsole.php');
|
||||
|
||||
$get_custom_fields_data = (bool) get_parameter('get_custom_fields_data', 0);
|
||||
$build_table_custom_fields = (bool)get_parameter('build_table_custom_fields', 0);
|
||||
$build_table_child_custom_fields = (bool)get_parameter('build_table_child_custom_fields', 0);
|
||||
$build_table_save_filter = (bool)get_parameter('build_table_save_filter', 0);
|
||||
$append_tab_filter = (bool)get_parameter('append_tab_filter', 0);
|
||||
$create_filter_cf = (bool)get_parameter('create_filter_cf', 0);
|
||||
$update_filter_cf = (bool)get_parameter('update_filter_cf', 0);
|
||||
$delete_filter_cf = (bool)get_parameter('delete_filter_cf', 0);
|
||||
|
||||
if ($get_custom_fields_data){
|
||||
$name_custom_fields = get_parameter("name_custom_fields", 0);
|
||||
$array_custom_fields_data = get_custom_fields_data($name_custom_fields);
|
||||
echo json_encode($array_custom_fields_data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if($build_table_custom_fields){
|
||||
$order = get_parameter("order", '');
|
||||
$length = get_parameter("length", 20);
|
||||
$start = get_parameter("start", 0);
|
||||
$draw = get_parameter("draw", 0);
|
||||
$search = get_parameter("search", '');
|
||||
$indexed_descriptions = json_decode(io_safe_output(get_parameter("indexed_descriptions", '')), true);
|
||||
|
||||
//order query
|
||||
$order_column = $order[0]['column'];
|
||||
$type_order = $order[0]['dir'];
|
||||
switch ($order_column) {
|
||||
default:
|
||||
case '1':
|
||||
$order_by = "ORDER BY temp.name_custom_fields " . $type_order;
|
||||
break;
|
||||
case '2':
|
||||
$order_by = "ORDER BY tma.server_name " . $type_order;
|
||||
break;
|
||||
case '3':
|
||||
$order_by = "ORDER BY tma.alias " . $type_order;
|
||||
break;
|
||||
case '4':
|
||||
$order_by = "ORDER BY tma.direccion " . $type_order;
|
||||
break;
|
||||
}
|
||||
|
||||
//table temporary for save array in table by order and search custom_field data
|
||||
$table_temporary = "CREATE TEMPORARY TABLE temp_custom_fields (
|
||||
id_server int(10),
|
||||
id_agent int(10),
|
||||
name_custom_fields varchar(2048),
|
||||
KEY `data_index_temp_1` (`id_server`, `id_agent`)
|
||||
)";
|
||||
db_process_sql($table_temporary);
|
||||
|
||||
//insert values array in table temporary
|
||||
$values_insert = array();
|
||||
foreach ($indexed_descriptions as $key => $value) {
|
||||
$values_insert[] = "(".$value['id_server'].", ".$value['id_agente'].", '".$value['description']."')";
|
||||
}
|
||||
$values_insert_implode = implode(",", $values_insert);
|
||||
$query_insert ="INSERT INTO temp_custom_fields VALUES ". $values_insert_implode;
|
||||
db_process_sql($query_insert);
|
||||
|
||||
//search table for alias, custom field data, server_name, direction
|
||||
$search_query = "";
|
||||
if($search['value'] != ''){
|
||||
$search_query = ' AND (tma.alias LIKE "%' . $search['value']. '%"';
|
||||
$search_query .= ' OR tma.server_name LIKE "%' . $search['value']. '%"';
|
||||
$search_query .= ' OR tma.direccion LIKE "%' . $search['value']. '%"';
|
||||
$search_query .= ' OR temp.name_custom_fields LIKE "%' . $search['value']. '%" ) ';
|
||||
}
|
||||
|
||||
//query all fields result
|
||||
$query = sprintf("SELECT
|
||||
tma.id_agente,
|
||||
tma.id_tagente,
|
||||
tma.id_tmetaconsole_setup,
|
||||
tma.alias,
|
||||
tma.direccion,
|
||||
tma.server_name,
|
||||
temp.name_custom_fields,
|
||||
(CASE
|
||||
WHEN tma.critical_count > 0
|
||||
THEN 1
|
||||
WHEN tma.critical_count = 0
|
||||
AND tma.warning_count > 0
|
||||
THEN 2
|
||||
WHEN tma.critical_count = 0
|
||||
AND tma.warning_count = 0
|
||||
AND tma.unknown_count > 0
|
||||
THEN 3
|
||||
WHEN tma.critical_count = 0
|
||||
AND tma.warning_count = 0
|
||||
AND tma.unknown_count = 0
|
||||
AND tma.notinit_count <> tma.total_count
|
||||
THEN 0
|
||||
WHEN tma.total_count = tma.notinit_count
|
||||
THEN 5
|
||||
ELSE 0
|
||||
END) AS `status`
|
||||
FROM tmetaconsole_agent tma
|
||||
INNER JOIN temp_custom_fields temp
|
||||
ON temp.id_agent = tma.id_tagente
|
||||
AND temp.id_server = tma.id_tmetaconsole_setup
|
||||
WHERE tma.disabled = 0
|
||||
%s
|
||||
%s
|
||||
LIMIT %d OFFSET %d
|
||||
",
|
||||
$search_query,
|
||||
$order_by,
|
||||
$length,
|
||||
$start
|
||||
);
|
||||
|
||||
$result = db_get_all_rows_sql($query);
|
||||
|
||||
//query count
|
||||
$query_count = sprintf("SELECT
|
||||
COUNT(tma.id_agente) AS `count`
|
||||
FROM tmetaconsole_agent tma
|
||||
INNER JOIN temp_custom_fields temp
|
||||
ON temp.id_agent = tma.id_tagente
|
||||
AND temp.id_server = tma.id_tmetaconsole_setup
|
||||
WHERE tma.disabled = 0
|
||||
%s
|
||||
",
|
||||
$search_query
|
||||
);
|
||||
|
||||
$count = db_get_sql($query_count);
|
||||
|
||||
//prepare rows for table dinamic
|
||||
$data = array();
|
||||
foreach ($result as $values) {
|
||||
switch ($values['status']) {
|
||||
case AGENT_STATUS_NORMAL:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_ok.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents ok')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AGENT_STATUS_CRITICAL:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_critical.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents critical')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AGENT_STATUS_WARNING:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_warning.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents warning')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_down.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents unknown')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AGENT_STATUS_ALERT_FIRED:
|
||||
$image_status = 'alert';
|
||||
break;
|
||||
case AGENT_STATUS_NOT_INIT:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_no_data.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents not init')
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$image_status= html_print_image(
|
||||
'images/status_sets/default/agent_ok.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents ok')
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
"ref" => $referencia,
|
||||
"data_custom_field" => $values['name_custom_fields'],
|
||||
"server" => $values['server_name'],
|
||||
"agent" => $values['alias'],
|
||||
"IP" => $values['direccion'],
|
||||
"status" => $image_status,
|
||||
"id_agent" => $values['id_tagente'],
|
||||
"id_server" => $values['id_tmetaconsole_setup']
|
||||
);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => count($data),
|
||||
"recordsFiltered" => $count,
|
||||
"data" => $data
|
||||
);
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
if($build_table_child_custom_fields){
|
||||
$id_agent = get_parameter("id_agent", 0);
|
||||
$id_server = get_parameter("id_server", 0);
|
||||
$module_search = str_replace('amp;', '',get_parameter("module_search", ''));
|
||||
|
||||
if(!$id_server || !$id_agent){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($module_search != ''){
|
||||
$name_where = " AND tam.nombre LIKE '%" . $module_search . "%'";
|
||||
}
|
||||
|
||||
if (is_metaconsole()) {
|
||||
$server = metaconsole_get_connection_by_id ($id_server);
|
||||
metaconsole_connect($server);
|
||||
}
|
||||
|
||||
$query = sprintf("SELECT tam.nombre,
|
||||
tam.min_warning, tam.max_warning,
|
||||
tam.min_critical, tam.max_critical,
|
||||
tae.estado, tae.current_interval,
|
||||
tae.utimestamp, tae.datos
|
||||
FROM tagente_modulo tam
|
||||
INNER JOIN tagente_estado tae
|
||||
ON tam.id_agente_modulo = tae.id_agente_modulo
|
||||
WHERE tam.id_agente = %d
|
||||
%s",
|
||||
$id_agent,
|
||||
$name_where
|
||||
);
|
||||
|
||||
$modules = db_get_all_rows_sql ($query);
|
||||
|
||||
$table_modules = new stdClass();
|
||||
$table_modules->width = "100%";
|
||||
$table_modules->class="databox data";
|
||||
|
||||
$table_modules->head = array();
|
||||
$table_modules->head[0] = __('Module name');
|
||||
$table_modules->head[1] = __('Data');
|
||||
$table_modules->head[2] = __('Min Warning');
|
||||
$table_modules->head[3] = __('Max Warning');
|
||||
$table_modules->head[4] = __('Min Critical');
|
||||
$table_modules->head[5] = __('Max Critical');
|
||||
$table_modules->head[6] = __('Current interval');
|
||||
$table_modules->head[7] = __('Timestamp');
|
||||
$table_modules->head[8] = __('Status');
|
||||
|
||||
$table_modules->data = array();
|
||||
if(isset($modules) && is_array($modules)){
|
||||
foreach ($modules as $key => $value) {
|
||||
$table_modules->data[$key][0] = $value['nombre'];
|
||||
$table_modules->data[$key][1] = $value['datos'];
|
||||
$table_modules->data[$key][2] = $value['min_warning'];
|
||||
$table_modules->data[$key][3] = $value['max_warning'];
|
||||
$table_modules->data[$key][4] = $value['min_critical'];
|
||||
$table_modules->data[$key][5] = $value['max_critical'];
|
||||
$table_modules->data[$key][6] = $value['current_interval'];
|
||||
$table_modules->data[$key][7] = date('d/m/Y h:i:s', $value['utimestamp']);
|
||||
switch ($value['estado']) {
|
||||
case 0:
|
||||
case 300:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_normal.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules normal')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
case 100:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_critical.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules critical')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
case 200:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_warning.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules warning')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_maintenance.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules unknown')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_informational.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules no init')
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_normal.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules normal')
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_metaconsole()) {
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
html_print_table ($table_modules);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if($build_table_save_filter){
|
||||
$type_form = get_parameter("type_form", '');
|
||||
|
||||
if($type_form == 'save'){
|
||||
$tabs = '<div id="tabs" style="height:95%;">';
|
||||
$tabs .= "<ul class='tab_save_filter'>";
|
||||
$tabs .= "<li>";
|
||||
$tabs .= "<a href='#extended_create_filter' id='link_create'>";
|
||||
$tabs .= html_print_image('images/lightning_go.png',true);
|
||||
$tabs .= "<span>". __('New Filter') . "</span>";
|
||||
$tabs .= "</a>";
|
||||
$tabs .= "</li>";
|
||||
|
||||
$tabs .= "<li>";
|
||||
$tabs .= "<a href='#extended_update_filter' id='link_update'>";
|
||||
$tabs .= html_print_image('images/zoom.png',true);
|
||||
$tabs .= "<span>".__('Existing Filter')."</span>";
|
||||
$tabs .= "</a>";
|
||||
$tabs .= "</li>";
|
||||
$tabs .= "</ul>";
|
||||
|
||||
$tabs .= '<div id="extended_create_filter">';
|
||||
$tabs .= '</div>';
|
||||
$tabs .= '<div id="extended_update_filter">';
|
||||
$tabs .= '</div>';
|
||||
$tabs .= "</div>";
|
||||
echo $tabs;
|
||||
}
|
||||
else{
|
||||
$table = new StdClass;
|
||||
$table->id = 'save_filter_form';
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox';
|
||||
|
||||
$array_filters = get_filters_custom_fields_view(0, true);
|
||||
$table->data[0][0] = __('Filter name');
|
||||
$table->data[0][1] = html_print_select(
|
||||
$array_filters, 'id_name',
|
||||
'', '', '', '',
|
||||
true, false, true, '', false
|
||||
);
|
||||
$table->data[0][3] = html_print_submit_button (__('Load filter'), 'load_filter', false, 'class="sub upd"', true);
|
||||
|
||||
echo "<form action='' method='post'>";
|
||||
html_print_table($table);
|
||||
echo "</form>";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if($append_tab_filter){
|
||||
$filters = json_decode(io_safe_output(get_parameter("filters", '')), true);
|
||||
|
||||
$table = new StdClass;
|
||||
$table->id = 'save_filter_form';
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox';
|
||||
|
||||
if($filters['id'] == 'extended_create_filter'){
|
||||
echo "<div id='msg_error_create'></div>";
|
||||
$table->data[0][0] = __('Filter name');
|
||||
$table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true);
|
||||
$table->data[0][2] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true);
|
||||
}
|
||||
else{
|
||||
echo "<div id='msg_error_update'></div>";
|
||||
echo "<div id='msg_error_delete'></div>";
|
||||
$array_filters = get_filters_custom_fields_view(0, true);
|
||||
$table->data[0][0] = __('Filter name');
|
||||
$table->data[0][1] = html_print_select(
|
||||
$array_filters, 'id_name',
|
||||
'', '', __('None'), -1,
|
||||
true, false, true, '', false
|
||||
);
|
||||
$table->data[0][2] = html_print_submit_button (__('Delete filter'), 'delete_filter', false, 'class="sub upd"', true);
|
||||
$table->data[0][3] = html_print_submit_button (__('Update filter'), 'update_filter', false, 'class="sub upd"', true);
|
||||
}
|
||||
|
||||
html_print_table($table);
|
||||
return;
|
||||
}
|
||||
|
||||
if($create_filter_cf){
|
||||
//initialize result
|
||||
$result_array = array();
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
//initialize vars
|
||||
$filters = json_decode(io_safe_output(get_parameter("filters", '')), true);
|
||||
$name_filter = get_parameter("name_filter", '');
|
||||
|
||||
//check that the name is not empty
|
||||
if($name_filter == ''){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('The name must not be empty'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
$name_exists = get_filters_custom_fields_view(0, false, $name_filter);
|
||||
|
||||
if($name_exists){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('Filter name already exists in the bbdd'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//check custom field is not empty
|
||||
if($filters['id_custom_fields'] == ''){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('Please, select a custom field'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//insert
|
||||
$values = array();
|
||||
$values['name'] = $name_filter;
|
||||
$values['id_group'] = $filters['group'];
|
||||
$values['id_custom_field'] = $filters['id_custom_fields'];
|
||||
$values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']);
|
||||
$values['id_status'] = json_encode($filters['id_status']);
|
||||
$values['module_search'] = $filters['module_search'];
|
||||
|
||||
$insert = db_process_sql_insert('tagent_custom_fields_filter', $values);
|
||||
|
||||
//check error insert
|
||||
if($insert) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
__("Success create filter."),
|
||||
'', true
|
||||
);
|
||||
} else {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__("Error create filter."),
|
||||
'', true
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
if($update_filter_cf){
|
||||
//initialize result
|
||||
$result_array = array();
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
//initialize vars
|
||||
$filters = json_decode(io_safe_output(get_parameter("filters", '')), true);
|
||||
$id_filter = get_parameter("id_filter", '');
|
||||
|
||||
//check selected filter
|
||||
if($id_filter == -1){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('please, select a filter'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//array condition update
|
||||
$condition = array();
|
||||
$condition['id'] = $id_filter;
|
||||
|
||||
//check selected custom fields
|
||||
if($filters['id_custom_fields'] == ''){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('please, select a custom field'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//array values update
|
||||
$values = array();
|
||||
$values['id_group'] = $filters['group'];
|
||||
$values['id_custom_field'] = $filters['id_custom_fields'];
|
||||
$values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']);
|
||||
$values['id_status'] = json_encode($filters['id_status']);
|
||||
$values['module_search'] = $filters['module_search'];
|
||||
|
||||
//update
|
||||
$update = db_process_sql_update('tagent_custom_fields_filter', $values, $condition);
|
||||
|
||||
//check error insert
|
||||
if($update) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
__("Success update filter."),
|
||||
'', true
|
||||
);
|
||||
} else {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__("Error update filter."),
|
||||
'', true
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
if($delete_filter_cf){
|
||||
//Initialize result
|
||||
$result_array = array();
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
//Initialize vars
|
||||
$filters = json_decode(io_safe_output(get_parameter("filters", '')), true);
|
||||
$id_filter = get_parameter("id_filter", '');
|
||||
|
||||
//Check selected filter
|
||||
if($id_filter == -1){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('please, select a filter'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//Array condition update
|
||||
$condition = array();
|
||||
$condition['id'] = $id_filter;
|
||||
|
||||
//Delete
|
||||
$delete = db_process_sql_delete('tagent_custom_fields_filter', $condition);
|
||||
|
||||
//Check error insert
|
||||
if($delete) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
__("Success delete filter."),
|
||||
'', true
|
||||
);
|
||||
} else {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__("Error delete filter."),
|
||||
'', true
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -18,7 +18,6 @@ if(check_login()){
|
|||
|
||||
global $config;
|
||||
|
||||
|
||||
include_once($config['homedir'] . "/include/functions_agents.php");
|
||||
include_once($config['homedir'] . "/include/functions_modules.php");
|
||||
include_once($config['homedir'] . "/include/functions_ui.php");
|
||||
|
@ -36,15 +35,6 @@ $get_type = (bool) get_parameter('get_type', 0);
|
|||
$list_modules = (bool) get_parameter('list_modules', 0);
|
||||
$get_agent_modules_json_by_name = (bool) get_parameter('get_agent_modules_json_by_name', 0);
|
||||
|
||||
$get_custom_fields_data = (bool) get_parameter('get_custom_fields_data', 0);
|
||||
$build_table_custom_fields = (bool)get_parameter('build_table_custom_fields', 0);
|
||||
$build_table_child_custom_fields = (bool)get_parameter('build_table_child_custom_fields', 0);
|
||||
$build_table_save_filter = (bool)get_parameter('build_table_save_filter', 0);
|
||||
$append_tab_filter = (bool)get_parameter('append_tab_filter', 0);
|
||||
$create_filter_cf = (bool)get_parameter('create_filter_cf', 0);
|
||||
$update_filter_cf = (bool)get_parameter('update_filter_cf', 0);
|
||||
$delete_filter_cf = (bool)get_parameter('delete_filter_cf', 0);
|
||||
|
||||
if ($get_agent_modules_json_by_name) {
|
||||
$agent_name = get_parameter('agent_name');
|
||||
|
||||
|
@ -1093,614 +1083,6 @@ if ($get_type) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ($get_custom_fields_data){
|
||||
$name_custom_fields = get_parameter("name_custom_fields", 0);
|
||||
$array_custom_fields_data = get_custom_fields_data($name_custom_fields);
|
||||
echo json_encode($array_custom_fields_data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if($build_table_custom_fields){
|
||||
$order = get_parameter("order", '');
|
||||
$length = get_parameter("length", 20);
|
||||
$start = get_parameter("start", 0);
|
||||
$draw = get_parameter("draw", 0);
|
||||
$search = get_parameter("search", '');
|
||||
$indexed_descriptions = json_decode(io_safe_output(get_parameter("indexed_descriptions", '')), true);
|
||||
|
||||
//order query
|
||||
$order_column = $order[0]['column'];
|
||||
$type_order = $order[0]['dir'];
|
||||
switch ($order_column) {
|
||||
default:
|
||||
case '1':
|
||||
$order_by = "ORDER BY temp.name_custom_fields " . $type_order;
|
||||
break;
|
||||
case '2':
|
||||
$order_by = "ORDER BY tma.server_name " . $type_order;
|
||||
break;
|
||||
case '3':
|
||||
$order_by = "ORDER BY tma.alias " . $type_order;
|
||||
break;
|
||||
case '4':
|
||||
$order_by = "ORDER BY tma.direccion " . $type_order;
|
||||
break;
|
||||
}
|
||||
|
||||
//table temporary for save array in table by order and search custom_field data
|
||||
$table_temporary = "CREATE TEMPORARY TABLE temp_custom_fields (
|
||||
id_server int(10),
|
||||
id_agent int(10),
|
||||
name_custom_fields varchar(2048),
|
||||
KEY `data_index_temp_1` (`id_server`, `id_agent`)
|
||||
)";
|
||||
db_process_sql($table_temporary);
|
||||
|
||||
//insert values array in table temporary
|
||||
$values_insert = array();
|
||||
foreach ($indexed_descriptions as $key => $value) {
|
||||
$values_insert[] = "(".$value['id_server'].", ".$value['id_agente'].", '".$value['description']."')";
|
||||
}
|
||||
$values_insert_implode = implode(",", $values_insert);
|
||||
$query_insert ="INSERT INTO temp_custom_fields VALUES ". $values_insert_implode;
|
||||
db_process_sql($query_insert);
|
||||
|
||||
//search table for alias, custom field data, server_name, direction
|
||||
$search_query = "";
|
||||
if($search['value'] != ''){
|
||||
$search_query = ' AND (tma.alias LIKE "%' . $search['value']. '%"';
|
||||
$search_query .= ' OR tma.server_name LIKE "%' . $search['value']. '%"';
|
||||
$search_query .= ' OR tma.direccion LIKE "%' . $search['value']. '%"';
|
||||
$search_query .= ' OR temp.name_custom_fields LIKE "%' . $search['value']. '%" ) ';
|
||||
}
|
||||
|
||||
//query all fields result
|
||||
$query = sprintf("SELECT
|
||||
tma.id_agente,
|
||||
tma.id_tagente,
|
||||
tma.id_tmetaconsole_setup,
|
||||
tma.alias,
|
||||
tma.direccion,
|
||||
tma.server_name,
|
||||
temp.name_custom_fields,
|
||||
(CASE
|
||||
WHEN tma.critical_count > 0
|
||||
THEN 1
|
||||
WHEN tma.critical_count = 0
|
||||
AND tma.warning_count > 0
|
||||
THEN 2
|
||||
WHEN tma.critical_count = 0
|
||||
AND tma.warning_count = 0
|
||||
AND tma.unknown_count > 0
|
||||
THEN 3
|
||||
WHEN tma.critical_count = 0
|
||||
AND tma.warning_count = 0
|
||||
AND tma.unknown_count = 0
|
||||
AND tma.notinit_count <> tma.total_count
|
||||
THEN 0
|
||||
WHEN tma.total_count = tma.notinit_count
|
||||
THEN 5
|
||||
ELSE 0
|
||||
END) AS `status`
|
||||
FROM tmetaconsole_agent tma
|
||||
INNER JOIN temp_custom_fields temp
|
||||
ON temp.id_agent = tma.id_tagente
|
||||
AND temp.id_server = tma.id_tmetaconsole_setup
|
||||
WHERE tma.disabled = 0
|
||||
%s
|
||||
%s
|
||||
LIMIT %d OFFSET %d
|
||||
",
|
||||
$search_query,
|
||||
$order_by,
|
||||
$length,
|
||||
$start
|
||||
);
|
||||
|
||||
$result = db_get_all_rows_sql($query);
|
||||
|
||||
//query count
|
||||
$query_count = sprintf("SELECT
|
||||
COUNT(tma.id_agente) AS `count`
|
||||
FROM tmetaconsole_agent tma
|
||||
INNER JOIN temp_custom_fields temp
|
||||
ON temp.id_agent = tma.id_tagente
|
||||
AND temp.id_server = tma.id_tmetaconsole_setup
|
||||
WHERE tma.disabled = 0
|
||||
%s
|
||||
",
|
||||
$search_query
|
||||
);
|
||||
|
||||
$count = db_get_sql($query_count);
|
||||
|
||||
//prepare rows for table dinamic
|
||||
$data = array();
|
||||
foreach ($result as $values) {
|
||||
switch ($values['status']) {
|
||||
case AGENT_STATUS_NORMAL:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_ok.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents ok')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AGENT_STATUS_CRITICAL:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_critical.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents critical')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AGENT_STATUS_WARNING:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_warning.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents warning')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_down.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents unknown')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AGENT_STATUS_ALERT_FIRED:
|
||||
$image_status = 'alert';
|
||||
break;
|
||||
case AGENT_STATUS_NOT_INIT:
|
||||
$image_status = html_print_image(
|
||||
'images/status_sets/default/agent_no_data.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents not init')
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$image_status= html_print_image(
|
||||
'images/status_sets/default/agent_ok.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Agents ok')
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
"ref" => $referencia,
|
||||
"data_custom_field" => $values['name_custom_fields'],
|
||||
"server" => $values['server_name'],
|
||||
"agent" => $values['alias'],
|
||||
"IP" => $values['direccion'],
|
||||
"status" => $image_status,
|
||||
"id_agent" => $values['id_tagente'],
|
||||
"id_server" => $values['id_tmetaconsole_setup']
|
||||
);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"draw" => $draw,
|
||||
"recordsTotal" => count($data),
|
||||
"recordsFiltered" => $count,
|
||||
"data" => $data
|
||||
);
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
if($build_table_child_custom_fields){
|
||||
$id_agent = get_parameter("id_agent", 0);
|
||||
$id_server = get_parameter("id_server", 0);
|
||||
$module_search = str_replace('amp;', '',get_parameter("module_search", ''));
|
||||
|
||||
if(!$id_server || !$id_agent){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($module_search != ''){
|
||||
$name_where = " AND tam.nombre LIKE '%" . $module_search . "%'";
|
||||
}
|
||||
|
||||
if (is_metaconsole()) {
|
||||
$server = metaconsole_get_connection_by_id ($id_server);
|
||||
metaconsole_connect($server);
|
||||
}
|
||||
|
||||
$query = sprintf("SELECT tam.nombre,
|
||||
tam.min_warning, tam.max_warning,
|
||||
tam.min_critical, tam.max_critical,
|
||||
tae.estado, tae.current_interval,
|
||||
tae.utimestamp, tae.datos
|
||||
FROM tagente_modulo tam
|
||||
INNER JOIN tagente_estado tae
|
||||
ON tam.id_agente_modulo = tae.id_agente_modulo
|
||||
WHERE tam.id_agente = %d
|
||||
%s",
|
||||
$id_agent,
|
||||
$name_where
|
||||
);
|
||||
|
||||
$modules = db_get_all_rows_sql ($query);
|
||||
|
||||
$table_modules = new stdClass();
|
||||
$table_modules->width = "100%";
|
||||
$table_modules->class="databox data";
|
||||
|
||||
$table_modules->head = array();
|
||||
$table_modules->head[0] = __('Module name');
|
||||
$table_modules->head[1] = __('Min Warning');
|
||||
$table_modules->head[2] = __('Max Warning');
|
||||
$table_modules->head[3] = __('Min Critical');
|
||||
$table_modules->head[4] = __('Max Critical');
|
||||
$table_modules->head[5] = __('Status');
|
||||
$table_modules->head[6] = __('Current interval');
|
||||
$table_modules->head[7] = __('Date');
|
||||
$table_modules->head[8] = __('Status');
|
||||
|
||||
$table_modules->data = array();
|
||||
if(isset($modules) && is_array($modules)){
|
||||
foreach ($modules as $key => $value) {
|
||||
$table_modules->data[$key][0] = $value['nombre'];
|
||||
$table_modules->data[$key][1] = $value['datos'];
|
||||
$table_modules->data[$key][2] = $value['min_warning'];
|
||||
$table_modules->data[$key][3] = $value['max_warning'];
|
||||
$table_modules->data[$key][4] = $value['min_critical'];
|
||||
$table_modules->data[$key][5] = $value['max_critical'];
|
||||
$table_modules->data[$key][6] = $value['current_interval'];
|
||||
$table_modules->data[$key][7] = date('d/m/Y h:i:s', $value['utimestamp']);
|
||||
switch ($value['estado']) {
|
||||
case 0:
|
||||
case 300:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_normal.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules normal')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
case 100:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_critical.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules critical')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
case 200:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_warning.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules warning')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_maintenance.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules unknown')
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_informational.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules no init')
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$table_modules->data[$key][8] = html_print_image(
|
||||
'images/status_sets/default/severity_normal.png',
|
||||
true,
|
||||
array(
|
||||
'title' => __('Modules normal')
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_metaconsole()) {
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
html_print_table ($table_modules);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if($build_table_save_filter){
|
||||
$type_form = get_parameter("type_form", '');
|
||||
|
||||
if($type_form == 'save'){
|
||||
$tabs = '<div id="tabs" style="height:95%;">';
|
||||
$tabs .= "<ul class='tab_save_filter'>";
|
||||
$tabs .= "<li>";
|
||||
$tabs .= "<a href='#extended_create_filter' id='link_create'>";
|
||||
$tabs .= html_print_image('images/lightning_go.png',true);
|
||||
$tabs .= "<span>". __('New Filter') . "</span>";
|
||||
$tabs .= "</a>";
|
||||
$tabs .= "</li>";
|
||||
|
||||
$tabs .= "<li>";
|
||||
$tabs .= "<a href='#extended_update_filter' id='link_update'>";
|
||||
$tabs .= html_print_image('images/zoom.png',true);
|
||||
$tabs .= "<span>".__('Existing Filter')."</span>";
|
||||
$tabs .= "</a>";
|
||||
$tabs .= "</li>";
|
||||
$tabs .= "</ul>";
|
||||
|
||||
$tabs .= '<div id="extended_create_filter">';
|
||||
$tabs .= '</div>';
|
||||
$tabs .= '<div id="extended_update_filter">';
|
||||
$tabs .= '</div>';
|
||||
$tabs .= "</div>";
|
||||
echo $tabs;
|
||||
}
|
||||
else{
|
||||
$table = new StdClass;
|
||||
$table->id = 'save_filter_form';
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox';
|
||||
|
||||
$array_filters = get_filters_custom_fields_view(0, true);
|
||||
$table->data[0][0] = __('Filter name');
|
||||
$table->data[0][1] = html_print_select(
|
||||
$array_filters, 'id_name',
|
||||
'', '', '', '',
|
||||
true, false, true, '', false
|
||||
);
|
||||
$table->data[0][3] = html_print_submit_button (__('Load filter'), 'load_filter', false, 'class="sub upd"', true);
|
||||
|
||||
echo "<form action='' method='post'>";
|
||||
html_print_table($table);
|
||||
echo "</form>";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if($append_tab_filter){
|
||||
$filters = json_decode(io_safe_output(get_parameter("filters", '')), true);
|
||||
|
||||
$table = new StdClass;
|
||||
$table->id = 'save_filter_form';
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox';
|
||||
|
||||
if($filters['id'] == 'extended_create_filter'){
|
||||
echo "<div id='msg_error_create'></div>";
|
||||
$table->data[0][0] = __('Filter name');
|
||||
$table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true);
|
||||
$table->data[0][2] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true);
|
||||
}
|
||||
else{
|
||||
echo "<div id='msg_error_update'></div>";
|
||||
echo "<div id='msg_error_delete'></div>";
|
||||
$array_filters = get_filters_custom_fields_view(0, true);
|
||||
$table->data[0][0] = __('Filter name');
|
||||
$table->data[0][1] = html_print_select(
|
||||
$array_filters, 'id_name',
|
||||
'', '', __('None'), -1,
|
||||
true, false, true, '', false
|
||||
);
|
||||
$table->data[0][2] = html_print_submit_button (__('Delete filter'), 'delete_filter', false, 'class="sub upd"', true);
|
||||
$table->data[0][3] = html_print_submit_button (__('Update filter'), 'update_filter', false, 'class="sub upd"', true);
|
||||
}
|
||||
|
||||
html_print_table($table);
|
||||
return;
|
||||
}
|
||||
|
||||
if($create_filter_cf){
|
||||
//initialize result
|
||||
$result_array = array();
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
//initialize vars
|
||||
$filters = json_decode(io_safe_output(get_parameter("filters", '')), true);
|
||||
$name_filter = get_parameter("name_filter", '');
|
||||
|
||||
//check that the name is not empty
|
||||
if($name_filter == ''){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('The name must not be empty'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
$name_exists = get_filters_custom_fields_view(0, false, $name_filter);
|
||||
|
||||
if($name_exists){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('Filter name already exists in the bbdd'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//check custom field is not empty
|
||||
if($filters['id_custom_fields'] == ''){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('Please, select a custom field'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//insert
|
||||
$values = array();
|
||||
$values['name'] = $name_filter;
|
||||
$values['id_group'] = $filters['group'];
|
||||
$values['id_custom_field'] = $filters['id_custom_fields'];
|
||||
$values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']);
|
||||
$values['id_status'] = json_encode($filters['id_status']);
|
||||
$values['module_search'] = $filters['module_search'];
|
||||
|
||||
$insert = db_process_sql_insert('tagent_custom_fields_filter', $values);
|
||||
|
||||
//check error insert
|
||||
if($insert) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
__("Success create filter."),
|
||||
'', true
|
||||
);
|
||||
} else {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__("Error create filter."),
|
||||
'', true
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
if($update_filter_cf){
|
||||
//initialize result
|
||||
$result_array = array();
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
//initialize vars
|
||||
$filters = json_decode(io_safe_output(get_parameter("filters", '')), true);
|
||||
$id_filter = get_parameter("id_filter", '');
|
||||
|
||||
//check selected filter
|
||||
if($id_filter == -1){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('please, select a filter'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//array condition update
|
||||
$condition = array();
|
||||
$condition['id'] = $id_filter;
|
||||
|
||||
//check selected custom fields
|
||||
if($filters['id_custom_fields'] == ''){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('please, select a custom field'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//array values update
|
||||
$values = array();
|
||||
$values['id_group'] = $filters['group'];
|
||||
$values['id_custom_field'] = $filters['id_custom_fields'];
|
||||
$values['id_custom_fields_data'] = json_encode($filters['id_custom_fields_data']);
|
||||
$values['id_status'] = json_encode($filters['id_status']);
|
||||
$values['module_search'] = $filters['module_search'];
|
||||
|
||||
//update
|
||||
$update = db_process_sql_update('tagent_custom_fields_filter', $values, $condition);
|
||||
|
||||
//check error insert
|
||||
if($update) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
__("Success update filter."),
|
||||
'', true
|
||||
);
|
||||
} else {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__("Error update filter."),
|
||||
'', true
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
if($delete_filter_cf){
|
||||
//Initialize result
|
||||
$result_array = array();
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = '';
|
||||
|
||||
//Initialize vars
|
||||
$filters = json_decode(io_safe_output(get_parameter("filters", '')), true);
|
||||
$id_filter = get_parameter("id_filter", '');
|
||||
|
||||
//Check selected filter
|
||||
if($id_filter == -1){
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__('please, select a filter'),
|
||||
'', true
|
||||
);
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
//Array condition update
|
||||
$condition = array();
|
||||
$condition['id'] = $id_filter;
|
||||
|
||||
//Delete
|
||||
$delete = db_process_sql_delete('tagent_custom_fields_filter', $condition);
|
||||
|
||||
//Check error insert
|
||||
if($delete) {
|
||||
$result_array['error'] = 0;
|
||||
$result_array['msg'] = ui_print_success_message(
|
||||
__("Success delete filter."),
|
||||
'', true
|
||||
);
|
||||
} else {
|
||||
$result_array['error'] = 1;
|
||||
$result_array['msg'] = ui_print_error_message(
|
||||
__("Error delete filter."),
|
||||
'', true
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode($result_array);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2787,450 +2787,4 @@ function agents_get_status_clause($state, $show_not_init = true) {
|
|||
// If the state is not an expected state, return no condition
|
||||
return "1=1";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns custom field all or 1.
|
||||
*
|
||||
* @param integer custom_field_id id.
|
||||
* @param bool Prepare for select or return all rows.
|
||||
*
|
||||
* @return array custom fields data.
|
||||
*/
|
||||
function get_custom_fields ($custom_field_id = false, $select = true, $display_on_front = false) {
|
||||
$fields = ($select)
|
||||
? ' tcf.id_field, tcf.name '
|
||||
: ' tcf.* ';
|
||||
|
||||
$where = ($custom_field_id)
|
||||
? ' WHERE tcf.id_field ='.$custom_field_id
|
||||
: ' WHERE 1=1';
|
||||
|
||||
$display = ($display_on_front)
|
||||
? ' AND tcf.display_on_front = 1'
|
||||
: '';
|
||||
|
||||
$result_array=array();
|
||||
if(!is_metaconsole()){
|
||||
$sql = sprintf("SELECT
|
||||
%s
|
||||
FROM tagent_custom_fields tcf
|
||||
%s
|
||||
%s
|
||||
",
|
||||
$fields,
|
||||
$where,
|
||||
$display
|
||||
);
|
||||
|
||||
$result = db_get_all_rows_sql($sql);
|
||||
|
||||
if(isset($result) && is_array($result)){
|
||||
foreach ($result as $key => $value) {
|
||||
if($select){
|
||||
$result_array[$value['name']]= $value['name'];
|
||||
}
|
||||
else{
|
||||
$result_array[$value['name']]= $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
if(isset($metaconsole_connections) && is_array($metaconsole_connections)){
|
||||
$result_meta = array();
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
|
||||
// Establishes connection
|
||||
if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
|
||||
|
||||
$sql = sprintf("SELECT
|
||||
%s
|
||||
FROM tagent_custom_fields tcf
|
||||
%s
|
||||
%s
|
||||
",
|
||||
$fields,
|
||||
$where,
|
||||
$display
|
||||
);
|
||||
|
||||
$result[]= db_get_all_rows_sql($sql);
|
||||
|
||||
// Restore connection to root node
|
||||
metaconsole_restore_db();
|
||||
|
||||
if(isset($result) && is_array($result)){
|
||||
foreach ($result as $custom) {
|
||||
foreach ($custom as $key => $value) {
|
||||
if($select){
|
||||
$result_array[$value['name']]= $value['name'];
|
||||
}
|
||||
else{
|
||||
$result_array[$value['name']]= $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$result_array = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns custom field data.
|
||||
*
|
||||
* @param integer custom_field_id id.
|
||||
*
|
||||
* @return array custom fields data.
|
||||
*/
|
||||
function get_custom_fields_data ($custom_field_name) {
|
||||
if(!isset($custom_field_name)){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!is_metaconsole()){
|
||||
$sql = sprintf("SELECT tcf.id_field, tcf.name, tcd.description
|
||||
FROM tagent_custom_fields tcf
|
||||
INNER JOIN tagent_custom_data tcd
|
||||
ON tcf.id_field = tcd.id_field
|
||||
INNER JOIN tagente ta
|
||||
ON tcd.id_agent = ta.id_agente
|
||||
WHERE tcd.description <> ''
|
||||
AND tcf.name = '%s'
|
||||
GROUP BY tcf.id_field, tcd.description",
|
||||
$custom_field_name
|
||||
);
|
||||
|
||||
$result = db_get_all_rows_sql($sql);
|
||||
if(isset($result) && is_array($result)){
|
||||
foreach ($result as $k => $v) {
|
||||
$array_result[$v['description']] = $v['description'];
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
if(isset($metaconsole_connections) && is_array($metaconsole_connections)){
|
||||
$result_meta = array();
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
|
||||
// Establishes connection
|
||||
if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
|
||||
|
||||
$sql = sprintf("SELECT tcf.id_field, tcf.name, tcd.description
|
||||
FROM tagent_custom_fields tcf
|
||||
INNER JOIN tagent_custom_data tcd
|
||||
ON tcf.id_field = tcd.id_field
|
||||
INNER JOIN tagente ta
|
||||
ON tcd.id_agent = ta.id_agente
|
||||
WHERE tcd.description <> ''
|
||||
AND tcf.name = '%s'
|
||||
GROUP BY tcf.id_field, tcd.description", $custom_field_name
|
||||
);
|
||||
|
||||
$result_meta[]= db_get_all_rows_sql($sql);
|
||||
|
||||
// Restore connection to root node
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
$array_result = array();
|
||||
if(isset($result_meta) && is_array($result_meta)){
|
||||
foreach ($result_meta as $result) {
|
||||
foreach ($result as $k => $v) {
|
||||
$array_result[$v['description']] = $v['description'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$array_result = false;
|
||||
}
|
||||
}
|
||||
return $array_result;
|
||||
}
|
||||
|
||||
function agent_counters_custom_fields($filters){
|
||||
//filter by status
|
||||
$and_status = "";
|
||||
if(is_array($filters['id_status'])){
|
||||
if(!in_array(-1, $filters['id_status'])){
|
||||
if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['id_status'])){
|
||||
if(count($filters['id_status']) > 0){
|
||||
$and_status = " AND ( ";
|
||||
foreach ($filters['id_status'] as $key => $value) {
|
||||
$and_status .= ($key != 0)
|
||||
? " OR ("
|
||||
: " (";
|
||||
switch ($value) {
|
||||
default:
|
||||
case AGENT_STATUS_NORMAL:
|
||||
$and_status .= " ta.critical_count = 0
|
||||
AND ta.warning_count = 0
|
||||
AND ta.unknown_count = 0
|
||||
AND ta.total_count <> ta.notinit_count ) ";
|
||||
break;
|
||||
case AGENT_STATUS_CRITICAL:
|
||||
$and_status .= " ta.critical_count > 0 ) ";
|
||||
break;
|
||||
case AGENT_STATUS_WARNING:
|
||||
$and_status .= " ta.critical_count = 0
|
||||
AND ta.warning_count > 0 ) ";
|
||||
break;
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
$and_status .= " ta.critical_count = 0
|
||||
AND ta.warning_count = 0
|
||||
AND ta.unknown_count > 0 ) ";
|
||||
break;
|
||||
case AGENT_STATUS_NOT_INIT:
|
||||
$and_status .= " ta.total_count = ta.notinit_count ) ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$and_status .= " ) ";
|
||||
}
|
||||
}
|
||||
else{
|
||||
$and_status = " AND (
|
||||
( ta.critical_count > 0 )
|
||||
OR ( ta.critical_count = 0 AND ta.warning_count > 0 )
|
||||
OR ( ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0 )
|
||||
OR ( ta.total_count = ta.notinit_count )
|
||||
) ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//filter group and check ACL groups
|
||||
$groups_and = "";
|
||||
if (!users_can_manage_group_all("AR")) {
|
||||
if(!$filters['group']){
|
||||
$id_groups = explode(", ", array_keys(users_get_groups()));
|
||||
$groups_and = " AND (ta.id_grupo IN ($id_groups) OR tasg.id_group IN($id_groups))";
|
||||
}
|
||||
}
|
||||
|
||||
if($filters['group']){
|
||||
$groups_and = " AND (ta.id_grupo =". $filters['group']." OR tasg.id_group =". $filters['group'].")";
|
||||
}
|
||||
|
||||
//filter custom data
|
||||
$custom_data_and = '';
|
||||
if(!in_array(-1, $filters['id_custom_fields_data'])){
|
||||
$custom_data_array = implode("', '", $filters['id_custom_fields_data']);
|
||||
$custom_data_and = "AND tcd.description IN ('" . $custom_data_array . "')";
|
||||
}
|
||||
|
||||
//filter custom name
|
||||
$custom_field_name = $filters['id_custom_fields'];
|
||||
|
||||
//filters module
|
||||
$module_filter = "";
|
||||
if($filters['module_search']){
|
||||
$module_filter = ' AND (
|
||||
SELECT count(*) AS n
|
||||
FROM tagente_modulo
|
||||
WHERE nombre LIKE "%' . $filters['module_search'] . '%"
|
||||
AND id_agente=ta.id_agente
|
||||
) > 0 ';
|
||||
}
|
||||
|
||||
if(is_metaconsole()){
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
if(isset($metaconsole_connections) && is_array($metaconsole_connections)){
|
||||
$result_meta = array();
|
||||
$data = array();
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
// Establishes connection
|
||||
if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
|
||||
|
||||
$query = sprintf("SELECT
|
||||
tcd.description as name_data,
|
||||
SUM(ta.normal_count) AS m_normal,
|
||||
SUM(ta.critical_count) AS m_critical,
|
||||
SUM(ta.warning_count) AS m_warning,
|
||||
SUM(ta.unknown_count) AS m_unknown,
|
||||
SUM(ta.notinit_count) AS m_not_init,
|
||||
SUM(ta.fired_count) AS m_alerts,
|
||||
SUM(ta.total_count) AS m_total,
|
||||
SUM(IF(ta.critical_count > 0, 1, 0)) AS a_critical,
|
||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count > 0, 1, 0)) AS a_warning,
|
||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS a_unknown,
|
||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count = 0 AND ta.notinit_count <> ta.total_count, 1, 0)) AS a_normal,
|
||||
SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS a_not_init,
|
||||
COUNT(ta.id_agente) AS a_agents,
|
||||
GROUP_CONCAT(DISTINCT(ta.id_agente) SEPARATOR ',') as ids
|
||||
FROM tagente ta
|
||||
INNER JOIN tagent_custom_data tcd
|
||||
ON tcd.id_agent = ta.id_agente
|
||||
INNER JOIN tagent_custom_fields tcf
|
||||
ON tcd.id_field = tcf.id_field
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON ta.id_agente = tasg.id_agent
|
||||
WHERE ta.disabled = 0
|
||||
AND tcf.name = '%s'
|
||||
AND tcd.description <> ''
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
GROUP BY tcd.description",
|
||||
$custom_field_name,
|
||||
$custom_data_and,
|
||||
$groups_and,
|
||||
$and_status,
|
||||
$module_filter
|
||||
);
|
||||
|
||||
$result_meta[$server_data['id']] = db_get_all_rows_sql($query);
|
||||
|
||||
$query_data = sprintf("SELECT
|
||||
tcd.description,
|
||||
ta.id_agente,
|
||||
%d AS id_server
|
||||
FROM tagente ta
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON ta.id_agente = tasg.id_agent
|
||||
INNER JOIN tagent_custom_data tcd
|
||||
ON tcd.id_agent = ta.id_agente
|
||||
INNER JOIN tagent_custom_fields tcf
|
||||
ON tcd.id_field = tcf.id_field
|
||||
WHERE ta.disabled = 0
|
||||
AND tcf.name = '%s'
|
||||
AND tcd.description <> ''
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
",
|
||||
$server_data['id'],
|
||||
$custom_field_name,
|
||||
$custom_data_and,
|
||||
$groups_and,
|
||||
$and_status,
|
||||
$module_filter
|
||||
);
|
||||
|
||||
$node_result = db_get_all_rows_sql($query_data);
|
||||
if (empty($node_result)) $node_result = array();
|
||||
|
||||
$data = array_merge($data, $node_result);
|
||||
// Restore connection to root node
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
}
|
||||
|
||||
$final_result = array();
|
||||
$array_data = array();
|
||||
|
||||
if(isset($result_meta) && is_array($result_meta)){
|
||||
//initialize counters
|
||||
$final_result['counters_total'] = array(
|
||||
't_m_normal' => 0,
|
||||
't_m_critical' => 0,
|
||||
't_m_warning' => 0,
|
||||
't_m_unknown' => 0,
|
||||
't_m_not_init' => 0,
|
||||
't_m_alerts' => 0,
|
||||
't_m_total' => 0,
|
||||
't_a_critical' => 0,
|
||||
't_a_warning' => 0,
|
||||
't_a_unknown' => 0,
|
||||
't_a_normal' => 0,
|
||||
't_a_not_init' => 0,
|
||||
't_a_agents' => 0
|
||||
);
|
||||
|
||||
foreach ($result_meta as $k => $nodo) {
|
||||
foreach ($nodo as $key => $value) {
|
||||
//Sum counters total
|
||||
$final_result['counters_total']['t_m_normal'] += $value['m_normal'];
|
||||
$final_result['counters_total']['t_m_critical'] += $value['m_critical'];
|
||||
$final_result['counters_total']['t_m_warning'] += $value['m_warning'];
|
||||
$final_result['counters_total']['t_m_unknown'] += $value['m_unknown'];
|
||||
$final_result['counters_total']['t_m_not_init'] += $value['m_not_init'];
|
||||
$final_result['counters_total']['t_m_alerts'] += $value['m_alerts'];
|
||||
$final_result['counters_total']['t_m_total'] += $value['m_total'];
|
||||
$final_result['counters_total']['t_a_critical'] += $value['a_critical'];
|
||||
$final_result['counters_total']['t_a_warning'] += $value['a_warning'];
|
||||
$final_result['counters_total']['t_a_unknown'] += $value['a_unknown'];
|
||||
$final_result['counters_total']['t_a_normal'] += $value['a_normal'];
|
||||
$final_result['counters_total']['t_a_not_init'] += $value['a_not_init'];
|
||||
$final_result['counters_total']['t_a_agents'] += $value['a_agents'];
|
||||
|
||||
//Sum counters for data
|
||||
$array_data[$value['name_data']]['m_normal'] += $value['m_normal'];
|
||||
$array_data[$value['name_data']]['m_critical'] += $value['m_critical'];
|
||||
$array_data[$value['name_data']]['m_warning'] += $value['m_warning'];
|
||||
$array_data[$value['name_data']]['m_unknown'] += $value['m_unknown'];
|
||||
$array_data[$value['name_data']]['m_not_init'] += $value['m_not_init'];
|
||||
$array_data[$value['name_data']]['m_alerts'] += $value['m_alerts'];
|
||||
$array_data[$value['name_data']]['m_total'] += $value['m_total'];
|
||||
$array_data[$value['name_data']]['a_critical'] += $value['a_critical'];
|
||||
$array_data[$value['name_data']]['a_warning'] += $value['a_warning'];
|
||||
$array_data[$value['name_data']]['a_unknown'] += $value['a_unknown'];
|
||||
$array_data[$value['name_data']]['a_normal'] += $value['a_normal'];
|
||||
$array_data[$value['name_data']]['a_not_init'] += $value['a_not_init'];
|
||||
$array_data[$value['name_data']]['a_agents'] += $value['a_agents'];
|
||||
}
|
||||
}
|
||||
|
||||
$final_result['counters_name'] = $array_data;
|
||||
}
|
||||
|
||||
$final_result['indexed_descriptions'] = $data;
|
||||
}
|
||||
else{
|
||||
//TODO
|
||||
$final_result = false;
|
||||
}
|
||||
|
||||
return $final_result;
|
||||
}
|
||||
|
||||
function get_filters_custom_fields_view($id = 0, $for_select = false, $name = ""){
|
||||
if($for_select){
|
||||
$query = "SELECT id, `name` FROM tagent_custom_fields_filter";
|
||||
$rs = db_get_all_rows_sql($query);
|
||||
if(isset($rs) && is_array($rs)){
|
||||
foreach ($rs as $key => $value) {
|
||||
$result[$value['id']] = $value['name'];
|
||||
}
|
||||
}
|
||||
else{
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$query = "SELECT * FROM tagent_custom_fields_filter WHERE 1=1";
|
||||
|
||||
if($id){
|
||||
$query .= " AND id = " . $id;
|
||||
}
|
||||
|
||||
if($name){
|
||||
$query .= " AND `name` = '" . $name . "'";
|
||||
}
|
||||
|
||||
$result = db_get_all_rows_sql($query);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,462 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License
|
||||
// as published by the Free Software Foundation; 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.
|
||||
|
||||
/**
|
||||
* Returns custom field all or 1.
|
||||
*
|
||||
* @param integer custom_field_id id.
|
||||
* @param bool Prepare for select or return all rows.
|
||||
*
|
||||
* @return array custom fields data.
|
||||
*/
|
||||
function get_custom_fields ($custom_field_id = false, $select = true, $display_on_front = false) {
|
||||
$fields = ($select)
|
||||
? ' tcf.id_field, tcf.name '
|
||||
: ' tcf.* ';
|
||||
|
||||
$where = ($custom_field_id)
|
||||
? ' WHERE tcf.id_field ='.$custom_field_id
|
||||
: ' WHERE 1=1';
|
||||
|
||||
$display = ($display_on_front)
|
||||
? ' AND tcf.display_on_front = 1'
|
||||
: '';
|
||||
|
||||
$result_array=array();
|
||||
if(!is_metaconsole()){
|
||||
$sql = sprintf("SELECT
|
||||
%s
|
||||
FROM tagent_custom_fields tcf
|
||||
%s
|
||||
%s
|
||||
",
|
||||
$fields,
|
||||
$where,
|
||||
$display
|
||||
);
|
||||
|
||||
$result = db_get_all_rows_sql($sql);
|
||||
|
||||
if(isset($result) && is_array($result)){
|
||||
foreach ($result as $key => $value) {
|
||||
if($select){
|
||||
$result_array[$value['name']]= $value['name'];
|
||||
}
|
||||
else{
|
||||
$result_array[$value['name']]= $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
if(isset($metaconsole_connections) && is_array($metaconsole_connections)){
|
||||
$result_meta = array();
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
|
||||
// Establishes connection
|
||||
if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
|
||||
|
||||
$sql = sprintf("SELECT
|
||||
%s
|
||||
FROM tagent_custom_fields tcf
|
||||
%s
|
||||
%s
|
||||
",
|
||||
$fields,
|
||||
$where,
|
||||
$display
|
||||
);
|
||||
|
||||
$result[]= db_get_all_rows_sql($sql);
|
||||
|
||||
// Restore connection to root node
|
||||
metaconsole_restore_db();
|
||||
|
||||
if(isset($result) && is_array($result)){
|
||||
foreach ($result as $custom) {
|
||||
foreach ($custom as $key => $value) {
|
||||
if($select){
|
||||
$result_array[$value['name']]= $value['name'];
|
||||
}
|
||||
else{
|
||||
$result_array[$value['name']]= $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$result_array = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns custom field data.
|
||||
*
|
||||
* @param integer custom_field_id id.
|
||||
*
|
||||
* @return array custom fields data.
|
||||
*/
|
||||
function get_custom_fields_data ($custom_field_name) {
|
||||
if(!isset($custom_field_name)){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!is_metaconsole()){
|
||||
$sql = sprintf("SELECT tcf.id_field, tcf.name, tcd.description
|
||||
FROM tagent_custom_fields tcf
|
||||
INNER JOIN tagent_custom_data tcd
|
||||
ON tcf.id_field = tcd.id_field
|
||||
INNER JOIN tagente ta
|
||||
ON tcd.id_agent = ta.id_agente
|
||||
WHERE tcd.description <> ''
|
||||
AND tcf.name = '%s'
|
||||
GROUP BY tcf.id_field, tcd.description",
|
||||
$custom_field_name
|
||||
);
|
||||
|
||||
$result = db_get_all_rows_sql($sql);
|
||||
if(isset($result) && is_array($result)){
|
||||
foreach ($result as $k => $v) {
|
||||
$array_result[$v['description']] = $v['description'];
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
if(isset($metaconsole_connections) && is_array($metaconsole_connections)){
|
||||
$result_meta = array();
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
|
||||
// Establishes connection
|
||||
if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
|
||||
|
||||
$sql = sprintf("SELECT tcf.id_field, tcf.name, tcd.description
|
||||
FROM tagent_custom_fields tcf
|
||||
INNER JOIN tagent_custom_data tcd
|
||||
ON tcf.id_field = tcd.id_field
|
||||
INNER JOIN tagente ta
|
||||
ON tcd.id_agent = ta.id_agente
|
||||
WHERE tcd.description <> ''
|
||||
AND tcf.name = '%s'
|
||||
GROUP BY tcf.id_field, tcd.description", $custom_field_name
|
||||
);
|
||||
|
||||
$result_meta[]= db_get_all_rows_sql($sql);
|
||||
|
||||
// Restore connection to root node
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
$array_result = array();
|
||||
if(isset($result_meta) && is_array($result_meta)){
|
||||
foreach ($result_meta as $result) {
|
||||
foreach ($result as $k => $v) {
|
||||
$array_result[$v['description']] = $v['description'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$array_result = false;
|
||||
}
|
||||
}
|
||||
return $array_result;
|
||||
}
|
||||
|
||||
function agent_counters_custom_fields($filters){
|
||||
//filter by status
|
||||
$and_status = "";
|
||||
if(is_array($filters['id_status'])){
|
||||
if(!in_array(-1, $filters['id_status'])){
|
||||
if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['id_status'])){
|
||||
if(count($filters['id_status']) > 0){
|
||||
$and_status = " AND ( ";
|
||||
foreach ($filters['id_status'] as $key => $value) {
|
||||
$and_status .= ($key != 0)
|
||||
? " OR ("
|
||||
: " (";
|
||||
switch ($value) {
|
||||
default:
|
||||
case AGENT_STATUS_NORMAL:
|
||||
$and_status .= " ta.critical_count = 0
|
||||
AND ta.warning_count = 0
|
||||
AND ta.unknown_count = 0
|
||||
AND ta.total_count <> ta.notinit_count ) ";
|
||||
break;
|
||||
case AGENT_STATUS_CRITICAL:
|
||||
$and_status .= " ta.critical_count > 0 ) ";
|
||||
break;
|
||||
case AGENT_STATUS_WARNING:
|
||||
$and_status .= " ta.critical_count = 0
|
||||
AND ta.warning_count > 0 ) ";
|
||||
break;
|
||||
case AGENT_STATUS_UNKNOWN:
|
||||
$and_status .= " ta.critical_count = 0
|
||||
AND ta.warning_count = 0
|
||||
AND ta.unknown_count > 0 ) ";
|
||||
break;
|
||||
case AGENT_STATUS_NOT_INIT:
|
||||
$and_status .= " ta.total_count = ta.notinit_count ) ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$and_status .= " ) ";
|
||||
}
|
||||
}
|
||||
else{
|
||||
$and_status = " AND (
|
||||
( ta.critical_count > 0 )
|
||||
OR ( ta.critical_count = 0 AND ta.warning_count > 0 )
|
||||
OR ( ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0 )
|
||||
OR ( ta.total_count = ta.notinit_count )
|
||||
) ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//filter group and check ACL groups
|
||||
$groups_and = "";
|
||||
if (!users_can_manage_group_all("AR")) {
|
||||
if(!$filters['group']){
|
||||
$id_groups = explode(", ", array_keys(users_get_groups()));
|
||||
$groups_and = " AND (ta.id_grupo IN ($id_groups) OR tasg.id_group IN($id_groups))";
|
||||
}
|
||||
}
|
||||
|
||||
if($filters['group']){
|
||||
$groups_and = " AND (ta.id_grupo =". $filters['group']." OR tasg.id_group =". $filters['group'].")";
|
||||
}
|
||||
|
||||
//filter custom data
|
||||
$custom_data_and = '';
|
||||
if(!in_array(-1, $filters['id_custom_fields_data'])){
|
||||
$custom_data_array = implode("', '", $filters['id_custom_fields_data']);
|
||||
$custom_data_and = "AND tcd.description IN ('" . $custom_data_array . "')";
|
||||
}
|
||||
|
||||
//filter custom name
|
||||
$custom_field_name = $filters['id_custom_fields'];
|
||||
|
||||
//filters module
|
||||
$module_filter = "";
|
||||
if($filters['module_search']){
|
||||
$module_filter = ' AND (
|
||||
SELECT count(*) AS n
|
||||
FROM tagente_modulo
|
||||
WHERE nombre LIKE "%' . $filters['module_search'] . '%"
|
||||
AND id_agente=ta.id_agente
|
||||
) > 0 ';
|
||||
}
|
||||
|
||||
if(is_metaconsole()){
|
||||
$metaconsole_connections = metaconsole_get_connection_names();
|
||||
// For all nodes
|
||||
if(isset($metaconsole_connections) && is_array($metaconsole_connections)){
|
||||
$result_meta = array();
|
||||
$data = array();
|
||||
foreach ($metaconsole_connections as $metaconsole) {
|
||||
// Get server connection data
|
||||
$server_data = metaconsole_get_connection($metaconsole);
|
||||
// Establishes connection
|
||||
if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
|
||||
|
||||
$query = sprintf("SELECT
|
||||
tcd.description as name_data,
|
||||
SUM(ta.normal_count) AS m_normal,
|
||||
SUM(ta.critical_count) AS m_critical,
|
||||
SUM(ta.warning_count) AS m_warning,
|
||||
SUM(ta.unknown_count) AS m_unknown,
|
||||
SUM(ta.notinit_count) AS m_not_init,
|
||||
SUM(ta.fired_count) AS m_alerts,
|
||||
SUM(ta.total_count) AS m_total,
|
||||
SUM(IF(ta.critical_count > 0, 1, 0)) AS a_critical,
|
||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count > 0, 1, 0)) AS a_warning,
|
||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS a_unknown,
|
||||
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count = 0 AND ta.notinit_count <> ta.total_count, 1, 0)) AS a_normal,
|
||||
SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS a_not_init,
|
||||
COUNT(ta.id_agente) AS a_agents,
|
||||
GROUP_CONCAT(DISTINCT(ta.id_agente) SEPARATOR ',') as ids
|
||||
FROM tagente ta
|
||||
INNER JOIN tagent_custom_data tcd
|
||||
ON tcd.id_agent = ta.id_agente
|
||||
INNER JOIN tagent_custom_fields tcf
|
||||
ON tcd.id_field = tcf.id_field
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON ta.id_agente = tasg.id_agent
|
||||
WHERE ta.disabled = 0
|
||||
AND tcf.name = '%s'
|
||||
AND tcd.description <> ''
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
GROUP BY tcd.description",
|
||||
$custom_field_name,
|
||||
$custom_data_and,
|
||||
$groups_and,
|
||||
$and_status,
|
||||
$module_filter
|
||||
);
|
||||
|
||||
$result_meta[$server_data['id']] = db_get_all_rows_sql($query);
|
||||
|
||||
$query_data = sprintf("SELECT
|
||||
tcd.description,
|
||||
ta.id_agente,
|
||||
%d AS id_server
|
||||
FROM tagente ta
|
||||
LEFT JOIN tagent_secondary_group tasg
|
||||
ON ta.id_agente = tasg.id_agent
|
||||
INNER JOIN tagent_custom_data tcd
|
||||
ON tcd.id_agent = ta.id_agente
|
||||
INNER JOIN tagent_custom_fields tcf
|
||||
ON tcd.id_field = tcf.id_field
|
||||
WHERE ta.disabled = 0
|
||||
AND tcf.name = '%s'
|
||||
AND tcd.description <> ''
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
",
|
||||
$server_data['id'],
|
||||
$custom_field_name,
|
||||
$custom_data_and,
|
||||
$groups_and,
|
||||
$and_status,
|
||||
$module_filter
|
||||
);
|
||||
|
||||
$node_result = db_get_all_rows_sql($query_data);
|
||||
if (empty($node_result)) $node_result = array();
|
||||
|
||||
$data = array_merge($data, $node_result);
|
||||
// Restore connection to root node
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
}
|
||||
|
||||
$final_result = array();
|
||||
$array_data = array();
|
||||
|
||||
if(isset($result_meta) && is_array($result_meta)){
|
||||
//initialize counters
|
||||
$final_result['counters_total'] = array(
|
||||
't_m_normal' => 0,
|
||||
't_m_critical' => 0,
|
||||
't_m_warning' => 0,
|
||||
't_m_unknown' => 0,
|
||||
't_m_not_init' => 0,
|
||||
't_m_alerts' => 0,
|
||||
't_m_total' => 0,
|
||||
't_a_critical' => 0,
|
||||
't_a_warning' => 0,
|
||||
't_a_unknown' => 0,
|
||||
't_a_normal' => 0,
|
||||
't_a_not_init' => 0,
|
||||
't_a_agents' => 0
|
||||
);
|
||||
|
||||
foreach ($result_meta as $k => $nodo) {
|
||||
foreach ($nodo as $key => $value) {
|
||||
//Sum counters total
|
||||
$final_result['counters_total']['t_m_normal'] += $value['m_normal'];
|
||||
$final_result['counters_total']['t_m_critical'] += $value['m_critical'];
|
||||
$final_result['counters_total']['t_m_warning'] += $value['m_warning'];
|
||||
$final_result['counters_total']['t_m_unknown'] += $value['m_unknown'];
|
||||
$final_result['counters_total']['t_m_not_init'] += $value['m_not_init'];
|
||||
$final_result['counters_total']['t_m_alerts'] += $value['m_alerts'];
|
||||
$final_result['counters_total']['t_m_total'] += $value['m_total'];
|
||||
$final_result['counters_total']['t_a_critical'] += $value['a_critical'];
|
||||
$final_result['counters_total']['t_a_warning'] += $value['a_warning'];
|
||||
$final_result['counters_total']['t_a_unknown'] += $value['a_unknown'];
|
||||
$final_result['counters_total']['t_a_normal'] += $value['a_normal'];
|
||||
$final_result['counters_total']['t_a_not_init'] += $value['a_not_init'];
|
||||
$final_result['counters_total']['t_a_agents'] += $value['a_agents'];
|
||||
|
||||
//Sum counters for data
|
||||
$array_data[$value['name_data']]['m_normal'] += $value['m_normal'];
|
||||
$array_data[$value['name_data']]['m_critical'] += $value['m_critical'];
|
||||
$array_data[$value['name_data']]['m_warning'] += $value['m_warning'];
|
||||
$array_data[$value['name_data']]['m_unknown'] += $value['m_unknown'];
|
||||
$array_data[$value['name_data']]['m_not_init'] += $value['m_not_init'];
|
||||
$array_data[$value['name_data']]['m_alerts'] += $value['m_alerts'];
|
||||
$array_data[$value['name_data']]['m_total'] += $value['m_total'];
|
||||
$array_data[$value['name_data']]['a_critical'] += $value['a_critical'];
|
||||
$array_data[$value['name_data']]['a_warning'] += $value['a_warning'];
|
||||
$array_data[$value['name_data']]['a_unknown'] += $value['a_unknown'];
|
||||
$array_data[$value['name_data']]['a_normal'] += $value['a_normal'];
|
||||
$array_data[$value['name_data']]['a_not_init'] += $value['a_not_init'];
|
||||
$array_data[$value['name_data']]['a_agents'] += $value['a_agents'];
|
||||
}
|
||||
}
|
||||
|
||||
$final_result['counters_name'] = $array_data;
|
||||
}
|
||||
|
||||
$final_result['indexed_descriptions'] = $data;
|
||||
}
|
||||
else{
|
||||
//TODO
|
||||
$final_result = false;
|
||||
}
|
||||
|
||||
return $final_result;
|
||||
}
|
||||
|
||||
function get_filters_custom_fields_view($id = 0, $for_select = false, $name = ""){
|
||||
if($for_select){
|
||||
$query = "SELECT id, `name` FROM tagent_custom_fields_filter";
|
||||
$rs = db_get_all_rows_sql($query);
|
||||
if(isset($rs) && is_array($rs)){
|
||||
foreach ($rs as $key => $value) {
|
||||
$result[$value['id']] = $value['name'];
|
||||
}
|
||||
}
|
||||
else{
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$query = "SELECT * FROM tagent_custom_fields_filter WHERE 1=1";
|
||||
|
||||
if($id){
|
||||
$query .= " AND id = " . $id;
|
||||
}
|
||||
|
||||
if($name){
|
||||
$query .= " AND `name` = '" . $name . "'";
|
||||
}
|
||||
|
||||
$result = db_get_all_rows_sql($query);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue