false,
'text' => ''.html_print_image('images/custom_columns.png', true, ['title' => __('Custom fields')]).'',
'operation' => true,
];
$buttons['view'] = [
'active' => false,
'text' => ''.html_print_image('images/list.png', true, ['title' => __('View')]).'',
'operation' => true,
];
switch ($section) {
case 'fields':
$buttons['fields']['active'] = true;
$subpage = ' - '.__('Custom fields');
break;
default:
$buttons['view']['active'] = true;
break;
}
ui_print_page_header(
__('Monitor detail').$subpage,
'',
false,
'',
true,
$buttons
);
if ($section == 'fields') {
include_once $config['homedir'].'/godmode/agentes/status_monitor_custom_fields.php';
exit();
}
} else {
ui_meta_print_header(__('Monitor view'));
}
$ag_freestring = (string) get_parameter('ag_freestring');
$moduletype = (string) get_parameter('moduletype');
$datatype = (string) get_parameter('datatype');
$ag_modulename = (string) get_parameter('ag_modulename');
$refr = (int) get_parameter('refr', 0);
$offset = (int) get_parameter('offset', 0);
$status = (int) get_parameter('status', 4);
$modulegroup = (int) get_parameter('modulegroup', -1);
$tag_filter = (int) get_parameter('tag_filter', 0);
$min_hours_status = (string) get_parameter('min_hours_status', '');
// Sort functionality
$sortField = get_parameter('sort_field');
$sort = get_parameter('sort', 'none');
// When the previous page was a visualmap and show only one module
$id_module = (int) get_parameter('id_module', 0);
$ag_custom_fields = (array) get_parameter('ag_custom_fields', []);
$module_option = (int) get_parameter('module_option', 1);
$autosearch = false;
// It is validated if it receives parameters different from those it has by default
if ($ag_freestring !== '' || $moduletype !== '' || $datatype !== ''
|| $ag_modulename !== '' || $refr !== 0 || $offset !== 0 || $status !== 4
|| $modulegroup !== -1 || $tag_filter !== 0 || $sortField !== ''
|| $sort !== 'none' || $id_module !== 0 || $module_option !== 1
|| $min_hours_status !== ''
) {
$autosearch = true;
}
if (!is_metaconsole()) {
$ag_group = (int) get_parameter('ag_group', 0);
} else {
$ag_group = get_parameter('ag_group', 0);
$ag_group_metaconsole = $ag_group;
}
$ag_custom_fields_params = '';
if (!empty($ag_custom_fields)) {
foreach ($ag_custom_fields as $id => $value) {
if (!empty($value)) {
$ag_custom_fields_params .= '&ag_custom_fields['.$id.']='.$value;
}
}
}
if ($id_module) {
$status = -1;
$ag_modulename = modules_get_agentmodule_name($id_module);
$ag_freestring = modules_get_agentmodule_agent_alias($id_module);
}
enterprise_hook('open_meta_frame');
// Get Groups and profiles from user
$user_groups = implode(',', array_keys(users_get_groups(false, 'AR', false)));
// Begin Build SQL sentences
$sql_from = ' FROM tagente_modulo
INNER JOIN tagente
ON tagente_modulo.id_agente = tagente.id_agente
LEFT JOIN tagent_secondary_group tasg
ON tagente.id_agente = tasg.id_agent
INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
INNER JOIN tmodule
ON tmodule.id_module = tagente_modulo.id_modulo
INNER JOIN ttipo_modulo
ON tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo
LEFT JOIN ttag_module
ON tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo';
$sql_conditions = ' WHERE tagente.disabled = 0';
if (is_numeric($ag_group)) {
$id_ag_group = 0;
} else {
$id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group);
}
// Agent group selector
if (!is_metaconsole()) {
if ($ag_group > 0 && check_acl($config['id_user'], $ag_group, 'AR')) {
$sql_conditions_group = sprintf(
' AND (tagente.id_grupo = %d OR tasg.id_group = %d)',
$ag_group,
$ag_group
);
} else if ($user_groups != '') {
// User has explicit permission on group 1 ?
$sql_conditions_group = ' AND (
tagente.id_grupo IN ('.$user_groups.')
OR tasg.id_group IN ('.$user_groups.')
)';
}
} else {
if (((int) $ag_group !== 0) && (check_acl($config['id_user'], $id_ag_group, 'AR'))) {
$sql_conditions_group = sprintf(
' AND (tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))',
$ag_group,
$ag_group
);
} else if ($user_groups != '') {
// User has explicit permission on group 1 ?
$sql_conditions_group = ' AND (
tagente.id_grupo IN ('.$user_groups.')
OR tasg.id_group IN ('.$user_groups.')
)';
}
}
// Module group
if (is_metaconsole()) {
if ($modulegroup != '-1') {
$sql_conditions .= sprintf(' AND tagente_modulo.id_module_group IN (%s)', $modulegroup);
}
} else if ($modulegroup > -1) {
$sql_conditions .= sprintf(' AND tagente_modulo.id_module_group = \'%d\'', $modulegroup);
}
// Module name selector
if ($ag_modulename != '') {
$sql_conditions .= " AND tagente_modulo.nombre LIKE '%".$ag_modulename."%'";
}
if ($module_option !== 0) {
if ($module_option == 1) {
// Only enabled
$sql_conditions .= sprintf(' AND tagente_modulo.disabled = 0');
} else if ($module_option == 2) {
// Only disabled
$sql_conditions .= sprintf(' AND tagente_modulo.disabled = 1');
}
}
if ($datatype != '') {
$sql_conditions .= sprintf(' AND ttipo_modulo.id_tipo ='.$datatype);
}
if ($moduletype != '') {
$sql_conditions .= sprintf(' AND tagente_modulo.id_modulo ='.$moduletype);
}
// Freestring selector
if ($ag_freestring != '') {
$sql_conditions .= ' AND (tagente.nombre COLLATE utf8_general_ci LIKE \'%%'.$ag_freestring.'%%\'
OR tagente.alias COLLATE utf8_general_ci LIKE \'%%'.$ag_freestring.'%%\'
OR tagente_modulo.nombre COLLATE utf8_general_ci LIKE \'%%'.$ag_freestring.'%%\'
OR tagente_modulo.descripcion COLLATE utf8_general_ci LIKE \'%%'.$ag_freestring.'%%\')';
}
// Status selector
if ($status == AGENT_MODULE_STATUS_NORMAL) {
// Normal
$sql_conditions .= ' AND tagente_estado.estado = 0
AND (utimestamp > 0 OR (tagente_modulo.id_tipo_modulo IN(21,22,23,100))) ';
} else if ($status == AGENT_MODULE_STATUS_CRITICAL_BAD) {
// Critical
$sql_conditions .= ' AND tagente_estado.estado = 1 AND utimestamp > 0';
} else if ($status == AGENT_MODULE_STATUS_WARNING) {
// Warning
$sql_conditions .= ' AND tagente_estado.estado = 2 AND utimestamp > 0';
} else if ($status == AGENT_MODULE_STATUS_NOT_NORMAL) {
// Not normal
$sql_conditions .= ' AND tagente_estado.estado <> 0';
} else if ($status == AGENT_MODULE_STATUS_UNKNOWN) {
// Unknown
$sql_conditions .= ' AND tagente_estado.estado = 3 AND tagente_estado.utimestamp <> 0';
} else if ($status == AGENT_MODULE_STATUS_NOT_INIT) {
// Not init
$sql_conditions .= ' AND tagente_estado.utimestamp = 0
AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,100)';
}
if (!empty($min_hours_status)) {
$date = new DateTime(null, new DateTimeZone($config['timezone']));
$current_timestamp = $date->getTimestamp();
$max_time = ($current_timestamp - ((int) $min_hours_status * 3600));
$sql_conditions .= sprintf(' AND tagente_estado.last_status_change < %d', $max_time);
}
// Filter by agent custom fields
$sql_conditions_custom_fields = '';
if (!empty($ag_custom_fields)) {
$cf_filter = [];
foreach ($ag_custom_fields as $field_id => $value) {
if (!empty($value)) {
$cf_filter[] = '(tagent_custom_data.id_field = '.$field_id.' AND tagent_custom_data.description LIKE \'%'.$value.'%\')';
}
}
if (!empty($cf_filter)) {
$sql_conditions_custom_fields = ' AND tagente.id_agente IN (
SELECT tagent_custom_data.id_agent
FROM tagent_custom_data
WHERE '.implode(' AND ', $cf_filter).')';
}
}
// Filter by tag
if ($tag_filter !== 0) {
if (is_metaconsole()) {
$sql_conditions .= ' AND tagente_modulo.id_agente_modulo IN (
SELECT ttag_module.id_agente_modulo
FROM ttag_module
WHERE ttag_module.id_tag IN ('.$tag_filter.'))';
} else {
$sql_conditions .= ' AND tagente_modulo.id_agente_modulo IN (
SELECT ttag_module.id_agente_modulo
FROM ttag_module
WHERE ttag_module.id_tag = '.$tag_filter.')';
}
}
// Apply the module ACL with tags
$sql_conditions_tags = '';
if (!users_is_admin()) {
$sql_conditions_tags = tags_get_acl_tags(
$config['id_user'],
$ag_group,
'AR',
'module_condition',
'AND',
'tagente_modulo',
true,
[],
false
);
if (is_numeric($sql_conditions_tags)) {
$sql_conditions_tags = ' AND 1 = 0';
}
}
// Two modes of filter. All the filters and only ACLs filter
$sql_conditions_all = $sql_conditions.$sql_conditions_group.$sql_conditions_tags.$sql_conditions_custom_fields;
// Get count to paginate
if (!defined('METACONSOLE')) {
$count = db_get_sql('SELECT COUNT(DISTINCT tagente_modulo.id_agente_modulo)'.$sql_from.$sql_conditions_all);
}
// Get limit_sql depend of the metaconsole or standard mode
if (is_metaconsole()) {
// Offset will be used to get the subset of modules
$inferior_limit = $offset;
$superior_limit = ($config['block_size'] + $offset);
// Offset reset to get all elements
$offset = 0;
if (!isset($config['meta_num_elements'])) {
$config['meta_num_elements'] = 100;
}
$limit_sql = $config['meta_num_elements'];
} else {
$limit_sql = $config['block_size'];
}
// End Build SQL sentences
//
// Start Build Search Form
//
$table = new StdClass();
$table->width = '100%';
$table->cellspacing = 0;
$table->cellpadding = 0;
$table->class = 'databox filters';
$table->style[0] = 'font-weight: bold;';
$table->style[1] = 'font-weight: bold;';
$table->style[2] = 'font-weight: bold;';
$table->style[3] = 'font-weight: bold;';
$table->style[4] = 'font-weight: bold;';
$table->data[0][0] = __('Group');
$table->data[0][1] = html_print_select_groups(
$config['id_user'],
'AR',
true,
'ag_group',
$ag_group,
'',
'',
'0',
true,
false,
false,
'',
false,
'',
false,
false,
'id_grupo',
false
);
$fields = [];
$fields[AGENT_MODULE_STATUS_NORMAL] = __('Normal');
$fields[AGENT_MODULE_STATUS_WARNING] = __('Warning');
$fields[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical');
$fields[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown');
$fields[AGENT_MODULE_STATUS_NOT_NORMAL] = __('Not normal');
// default
$fields[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init');
$table->data[0][2] = __('Monitor status');
$table->data[0][3] = html_print_select(
$fields,
'status',
$status,
'',
__('All'),
-1,
true,
false,
true,
'',
false,
'width: 150px;'
);
$rows_select = [];
$table->data[0][4] = __('Module group');
$rows_select[0] = __('Not assigned');
if (!is_metaconsole()) {
$rows = db_get_all_rows_sql(
'SELECT *
FROM tmodule_group ORDER BY name'
);
$rows = io_safe_output($rows);
if (!empty($rows)) {
foreach ($rows as $module_group) {
$rows_select[$module_group['id_mg']] = $module_group['name'];
}
}
} else {
$rows_select = modules_get_modulegroups();
}
$table->data[0][5] = html_print_select($rows_select, 'modulegroup', $modulegroup, '', __('All'), -1, true, false, true, '', false, 'width: 120px;');
$table->rowspan[0][6] = 3;
$table->data[0][6] = html_print_submit_button(
__('Show'),
'uptbutton',
false,
'class="sub search" style="margin-top:0px;"',
true
);
$table->data[1][0] = __('Module name');
$table->data[1][1] = html_print_autocomplete_modules(
'ag_modulename',
$ag_modulename,
false,
true,
'',
[],
true
);
$table->data[1][2] = __('Search');
$table->data[1][3] = html_print_input_text('ag_freestring', $ag_freestring, '', 20, 30, true);
$table->data[1][4] = __('Tags').ui_print_help_tip(__('Only it is show tags in use.'), true);
$tags = [];
$tags = tags_get_user_tags();
if (empty($tags)) {
$table->data[1][5] = __('No tags');
} else {
$table->data[1][5] = html_print_select(
$tags,
'tag_filter',
$tag_filter,
'',
__('All'),
'',
true,
false,
true,
'',
false,
'width: 150px;'
);
}
$network_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 1'
);
// POSTGRESQL AND ORACLE COMPATIBLE
$wmi_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 6'
);
// POSTGRESQL AND ORACLE COMPATIBLE
$plugin_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 4'
);
// POSTGRESQL AND ORACLE COMPATIBLE
$prediction_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 5'
);
// POSTGRESQL AND ORACLE COMPATIBLE
$wux_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 17'
);
// POSTGRESQL AND ORACLE COMPATIBLE
// Development mode to use all servers
if ($develop_bypass) {
$network_available = 1;
$wmi_available = 1;
$plugin_available = 1;
$prediction_available = 1;
}
$typemodules = [];
$typemodules[1] = __('Data server module');
if ($network_available) {
$typemodules[2] = __('Network server module');
}
if ($plugin_available) {
$typemodules[4] = __('Plugin server module');
}
if ($wmi_available) {
$typemodules[6] = __('WMI server module');
}
if ($prediction_available) {
$typemodules[5] = __('Prediction server module');
}
if (enterprise_installed()) {
$typemodules[7] = __('Web server module');
if ($wux_available) {
$typemodules[8] = __('Wux server module');
}
}
$table->data[2][0] = ''.__('Server type').'';
$table->data[2][1] = html_print_select($typemodules, 'moduletype', $moduletype, '', __('All'), '', true, false, true, '', false, 'width: 150px;');
$monitor_options = [
0 => __('All'),
1 => __('Only enabled'),
2 => __('Only disabled'),
];
$table->data[2][2] = ''.__('Show monitors...').'';
$table->data[2][3] = html_print_select($monitor_options, 'module_option', $module_option, '', '', '', true, false, true, '', false, 'width: 150px;');
$min_hours_val = empty($min_hours_status) ? '' : (int) $min_hours_status;
$table->data[2][4] = ''.__('Min. hours in current status').'';
$table->data[2][5] = html_print_input_text('min_hours_status', $min_hours_val, '', 12, 20, true);
$table->data[3][0] = 'data[3][0] .= 'style="display:none"';
}
$table->data[3][0] .= '>'.__('Data type').'';
$table->data[3][1] .= '
';
switch ($moduletype) {
case 1:
$sql = sprintf(
'SELECT id_tipo, descripcion
FROM ttipo_modulo
WHERE categoria IN (6,7,8,0,1,2,-1) order by descripcion '
);
break;
case 2:
$sql = sprintf(
'SELECT id_tipo, descripcion
FROM ttipo_modulo
WHERE categoria between 3 and 5 '
);
break;
case 4:
$sql = sprintf(
'SELECT id_tipo, descripcion
FROM ttipo_modulo
WHERE categoria between 0 and 2 '
);
break;
case 6:
$sql = sprintf(
'SELECT id_tipo, descripcion
FROM ttipo_modulo
WHERE categoria between 0 and 2 '
);
break;
case 7:
$sql = sprintf(
'SELECT id_tipo, descripcion
FROM ttipo_modulo
WHERE categoria = 9'
);
break;
case 5:
$sql = sprintf(
'SELECT id_tipo, descripcion
FROM ttipo_modulo
WHERE categoria = 0'
);
break;
case 8:
$sql = sprintf(
'SELECT id_tipo, descripcion
FROM ttipo_modulo
WHERE nombre = \'web_analysis\''
);
break;
case '':
$sql = sprintf(
'SELECT id_tipo, descripcion
FROM ttipo_modulo'
);
break;
}
$a = db_get_all_rows_sql($sql);
$table->data[3][1] .= '';
$table->data[3][1] .= '