$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 ()));
////////////////////////////////////
// Begin Build SQL sentences
$sql_from = ' FROM ttipo_modulo,tagente, tagente_modulo, tagente_estado,tmodule ';
$sql_conditions_base = ' WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo AND tmodule.id_module = tagente_modulo.id_modulo';
$sql_conditions = ' AND 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', $ag_group);
}
elseif ($user_groups != '') {
// User has explicit permission on group 1 ?
$sql_conditions_group = ' AND tagente.id_grupo 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) ', $ag_group);
}
elseif ($user_groups != '') {
// User has explicit permission on group 1 ?
$sql_conditions_group = ' AND tagente.id_grupo 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 .= sprintf (' AND tagente_modulo.nombre = \'%s\'',
$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))) ';
}
elseif ($status == AGENT_MODULE_STATUS_CRITICAL_BAD) { //Critical
$sql_conditions .= ' AND tagente_estado.estado = 1 AND utimestamp > 0';
}
elseif ($status == AGENT_MODULE_STATUS_WARNING) { //Warning
$sql_conditions .= ' AND tagente_estado.estado = 2 AND utimestamp > 0';
}
elseif ($status == AGENT_MODULE_STATUS_NOT_NORMAL) { //Not normal
$sql_conditions .= ' AND tagente_estado.estado <> 0';
}
elseif ($status == AGENT_MODULE_STATUS_UNKNOWN) { //Unknown
$sql_conditions .= ' AND tagente_estado.estado = 3 AND tagente_estado.utimestamp <> 0';
}
elseif ($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)';
}
// Filter by agent custom fields
$sql_conditions_custom_fields = "";
if (!empty($ag_custom_fields)) {
$cf_filter = array();
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()) {
if ($ag_group !== 0) {
$sql_conditions_tags = tags_get_acl_tags($config['id_user'],
$ag_group, 'AR', 'module_condition', 'AND', 'tagente_modulo',
true, array(), false);
} else {
// Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!)
$groups = users_get_groups($config['id_user']);
$sql_conditions_tags = tags_get_acl_tags(
$config['id_user'], array_keys($groups), 'AR',
'module_condition', 'AND', 'tagente_modulo', true, array(),
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_base . $sql_conditions . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields;
$sql_conditions_acl = $sql_conditions_base . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields;
// Get count to paginate
if (!defined('METACONSOLE'))
$count = db_get_sql ('SELECT COUNT(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 = array ();
$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 = array();
$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] = 2;
$table->data[0][6] = html_print_submit_button (__('Show'), 'uptbutton',
false, 'class="sub search" style="margin-top:0px;"',true);
$modules = array();
$modules = modules_get_modules_name ($sql_from , $sql_conditions_acl, is_metaconsole());
$table->data[1][0] = __('Module name');
$table->data[1][1] = html_print_select (index_array ($modules, 'nombre', 'nombre'), 'ag_modulename',
$ag_modulename, '', __('All'), '', true, false, true, '', false, 'width: 150px;');
$table->data[1][2] = __('Search');
$table->data[1][3] = html_print_input_text ('ag_freestring', $ag_freestring, '', 20, 30, true);
if (!is_metaconsole())
$table->data[1][4] = __('Tags') .
ui_print_help_tip(__('Only it is show tags in use.'), true);
else
$table->data[1][4] = __('Tags') .
ui_print_help_tip(__('Only it is show tags in use.'), true);
$tags = array();
$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
// Development mode to use all servers
if ($develop_bypass) {
$network_available = 1;
$wmi_available = 1;
$plugin_available = 1;
$prediction_available = 1;
}
$typemodules = array ();
$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');
}
$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 = array(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;');
$table->data[2][4] = 'data[2][4] .= 'style="display:none"';
}
$table->data[2][4] .= '>'.__('Data type').'';
$table->data[2][5] .='
';
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 '':
$sql = sprintf ('SELECT id_tipo, descripcion
FROM ttipo_modulo');
break;
}
$a = db_get_all_rows_sql($sql);
$table->data[2][5] .= '';
$table->data[2][5] .= '