add not option in monitor detail filter

This commit is contained in:
marcos 2021-05-06 17:08:11 +02:00
parent f0f7244d84
commit f03364bf96

View File

@ -11,7 +11,7 @@
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// Load global vars // Load global vars.
global $config; global $config;
check_login(); check_login();
@ -115,9 +115,18 @@ $sort = get_parameter('sort', 'none');
$id_module = (int) get_parameter('id_module', 0); $id_module = (int) get_parameter('id_module', 0);
$ag_custom_fields = (array) get_parameter('ag_custom_fields', []); $ag_custom_fields = (array) get_parameter('ag_custom_fields', []);
$module_option = (int) get_parameter('module_option', 1); $module_option = (int) get_parameter('module_option', 1);
$not_condition = (string) get_parameter('not_condition', '');
// If option not_condition is enabled, the conditions of the queries are reversed.
$condition_query = '=';
if ($not_condition !== '') {
$condition_query = '!=';
}
$autosearch = false; $autosearch = false;
// It is validated if it receives parameters different from those it has by default // It is validated if it receives parameters different from those it has by default.
if ($ag_freestring !== '' || $moduletype !== '' || $datatype !== '' if ($ag_freestring !== '' || $moduletype !== '' || $datatype !== ''
|| $ag_modulename !== '' || $refr !== 0 || $offset !== 0 || $status !== 4 || $ag_modulename !== '' || $refr !== 0 || $offset !== 0 || $status !== 4
|| $modulegroup !== -1 || $tag_filter !== 0 || $sortField !== '' || $modulegroup !== -1 || $tag_filter !== 0 || $sortField !== ''
@ -151,10 +160,10 @@ if ($id_module) {
enterprise_hook('open_meta_frame'); enterprise_hook('open_meta_frame');
// Get Groups and profiles from user // Get Groups and profiles from user.
$user_groups = implode(',', array_keys(users_get_groups(false, 'AR', false))); $user_groups = implode(',', array_keys(users_get_groups(false, 'AR', false)));
// Begin Build SQL sentences // Begin Build SQL sentences.
$sql_from = ' FROM tagente_modulo $sql_from = ' FROM tagente_modulo
INNER JOIN tagente INNER JOIN tagente
ON tagente_modulo.id_agente = tagente.id_agente ON tagente_modulo.id_agente = tagente.id_agente
@ -177,7 +186,7 @@ if (is_numeric($ag_group)) {
$id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group); $id_ag_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $ag_group);
} }
// Agent group selector // Agent group selector.
if (!is_metaconsole()) { if (!is_metaconsole()) {
if ($ag_group > 0 && check_acl($config['id_user'], $ag_group, 'AR')) { if ($ag_group > 0 && check_acl($config['id_user'], $ag_group, 'AR')) {
if ($recursion) { if ($recursion) {
@ -191,7 +200,7 @@ if (!is_metaconsole()) {
); );
} else { } else {
$sql_conditions_group = sprintf( $sql_conditions_group = sprintf(
' AND (tagente.id_grupo = %d OR tasg.id_group = %d)', ' AND (tagente.id_grupo '.$condition_query.' %d OR tasg.id_group '.$condition_query.' %d)',
$ag_group, $ag_group,
$ag_group $ag_group
); );
@ -230,66 +239,66 @@ if (!is_metaconsole()) {
} }
} }
// Module group // Module group.
if (is_metaconsole()) { if (is_metaconsole()) {
if ($modulegroup != '-1') { if ($modulegroup != '-1') {
$sql_conditions .= sprintf(' AND tagente_modulo.id_module_group IN (%s)', $modulegroup); $sql_conditions .= sprintf(' AND tagente_modulo.id_module_group '.$not_condition.' IN (%s)', $modulegroup);
} }
} else if ($modulegroup > -1) { } else if ($modulegroup > -1) {
$sql_conditions .= sprintf(' AND tagente_modulo.id_module_group = \'%d\'', $modulegroup); $sql_conditions .= sprintf(' AND tagente_modulo.id_module_group '.$condition_query.' \'%d\'', $modulegroup);
} }
// Module name selector // Module name selector.
if ($ag_modulename != '') { if ($ag_modulename != '') {
$sql_conditions .= " AND tagente_modulo.nombre LIKE '%".$ag_modulename."%'"; $sql_conditions .= " AND tagente_modulo.nombre $not_condition LIKE '%".$ag_modulename."%'";
} }
if ($module_option !== 0) { if ($module_option !== 0) {
if ($module_option == 1) { if ($module_option == 1) {
// Only enabled // Only enabled.
$sql_conditions .= sprintf(' AND tagente_modulo.disabled = 0'); $sql_conditions .= sprintf(' AND tagente_modulo.disabled '.$condition_query.' 0');
} else if ($module_option == 2) { } else if ($module_option == 2) {
// Only disabled // Only disabled.
$sql_conditions .= sprintf(' AND tagente_modulo.disabled = 1'); $sql_conditions .= sprintf(' AND tagente_modulo.disabled '.$condition_query.' 1');
} }
} }
if ($datatype != '') { if ($datatype != '') {
$sql_conditions .= sprintf(' AND ttipo_modulo.id_tipo ='.$datatype); $sql_conditions .= sprintf(' AND ttipo_modulo.id_tipo '.$condition_query.' '.$datatype);
} }
if ($moduletype != '') { if ($moduletype != '') {
$sql_conditions .= sprintf(' AND tagente_modulo.id_modulo ='.$moduletype); $sql_conditions .= sprintf(' AND tagente_modulo.id_modulo '.$condition_query.' '.$moduletype.'');
} }
// Freestring selector // Freestring selector.
if ($ag_freestring != '') { if ($ag_freestring != '') {
$sql_conditions .= ' AND (tagente.nombre COLLATE utf8_general_ci LIKE \'%%'.$ag_freestring.'%%\' $sql_conditions .= ' AND (tagente.nombre COLLATE utf8_general_ci '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\'
OR tagente.alias COLLATE utf8_general_ci LIKE \'%%'.$ag_freestring.'%%\' OR tagente.alias COLLATE utf8_general_ci '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\'
OR tagente_modulo.nombre COLLATE utf8_general_ci LIKE \'%%'.$ag_freestring.'%%\' OR tagente_modulo.nombre COLLATE utf8_general_ci '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\'
OR tagente_modulo.descripcion COLLATE utf8_general_ci LIKE \'%%'.$ag_freestring.'%%\')'; OR tagente_modulo.descripcion COLLATE utf8_general_ci '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\')';
} }
// Status selector // Status selector.
if ($status == AGENT_MODULE_STATUS_NORMAL) { if ($status == AGENT_MODULE_STATUS_NORMAL) {
// Normal // Normal.
$sql_conditions .= ' AND tagente_estado.estado = 0 $sql_conditions .= ' AND tagente_estado.estado '.$condition_query.' 0
AND (utimestamp > 0 OR (tagente_modulo.id_tipo_modulo IN(21,22,23,100))) '; AND (utimestamp > 0 OR (tagente_modulo.id_tipo_modulo IN(21,22,23,100))) ';
} else if ($status == AGENT_MODULE_STATUS_CRITICAL_BAD) { } else if ($status == AGENT_MODULE_STATUS_CRITICAL_BAD) {
// Critical // Critical.
$sql_conditions .= ' AND tagente_estado.estado = 1 AND utimestamp > 0'; $sql_conditions .= ' AND tagente_estado.estado '.$condition_query.' 1 AND utimestamp > 0';
} else if ($status == AGENT_MODULE_STATUS_WARNING) { } else if ($status == AGENT_MODULE_STATUS_WARNING) {
// Warning // Warning.
$sql_conditions .= ' AND tagente_estado.estado = 2 AND utimestamp > 0'; $sql_conditions .= ' AND tagente_estado.estado '.$condition_query.' 2 AND utimestamp > 0';
} else if ($status == AGENT_MODULE_STATUS_NOT_NORMAL) { } else if ($status == AGENT_MODULE_STATUS_NOT_NORMAL) {
// Not normal // Not normal.
$sql_conditions .= ' AND tagente_estado.estado <> 0'; $sql_conditions .= ' AND tagente_estado.estado <> 0';
} else if ($status == AGENT_MODULE_STATUS_UNKNOWN) { } else if ($status == AGENT_MODULE_STATUS_UNKNOWN) {
// Unknown // Unknown.
$sql_conditions .= ' AND tagente_estado.estado = 3 AND tagente_estado.utimestamp <> 0'; $sql_conditions .= ' AND tagente_estado.estado '.$condition_query.' 3 AND tagente_estado.utimestamp <> 0';
} else if ($status == AGENT_MODULE_STATUS_NOT_INIT) { } else if ($status == AGENT_MODULE_STATUS_NOT_INIT) {
// Not init // Not init.
$sql_conditions .= ' AND tagente_estado.utimestamp = 0 $sql_conditions .= ' AND tagente_estado.utimestamp '.$condition_query.' 0
AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,100)'; AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,100)';
} }
@ -300,13 +309,13 @@ if (!empty($min_hours_status)) {
$sql_conditions .= sprintf(' AND tagente_estado.last_status_change < %d', $max_time); $sql_conditions .= sprintf(' AND tagente_estado.last_status_change < %d', $max_time);
} }
// Filter by agent custom fields // Filter by agent custom fields.
$sql_conditions_custom_fields = ''; $sql_conditions_custom_fields = '';
if (!empty($ag_custom_fields)) { if (!empty($ag_custom_fields)) {
$cf_filter = []; $cf_filter = [];
foreach ($ag_custom_fields as $field_id => $value) { foreach ($ag_custom_fields as $field_id => $value) {
if (!empty($value)) { if (!empty($value)) {
$cf_filter[] = '(tagent_custom_data.id_field = '.$field_id.' AND tagent_custom_data.description LIKE \'%'.$value.'%\')'; $cf_filter[] = '(tagent_custom_data.id_field '.$condition_query.' '.$field_id.' AND tagent_custom_data.description '.$not_condition.' LIKE \'%'.$value.'%\')';
} }
} }
@ -318,24 +327,24 @@ if (!empty($ag_custom_fields)) {
} }
} }
// Filter by tag // Filter by tag.
if ($tag_filter !== 0) { if ($tag_filter !== 0) {
if (is_metaconsole()) { if (is_metaconsole()) {
$sql_conditions .= ' AND tagente_modulo.id_agente_modulo IN ( $sql_conditions .= ' AND tagente_modulo.id_agente_modulo '.$not_condition.' IN (
SELECT ttag_module.id_agente_modulo SELECT ttag_module.id_agente_modulo
FROM ttag_module FROM ttag_module
WHERE ttag_module.id_tag IN ('.$tag_filter.'))'; WHERE ttag_module.id_tag '.$not_condition.' IN ('.$tag_filter.'))';
} else { } else {
$sql_conditions .= ' AND tagente_modulo.id_agente_modulo IN ( $sql_conditions .= ' AND tagente_modulo.id_agente_modulo '.$not_condition.' IN (
SELECT ttag_module.id_agente_modulo SELECT ttag_module.id_agente_modulo
FROM ttag_module FROM ttag_module
WHERE ttag_module.id_tag = '.$tag_filter.')'; WHERE ttag_module.id_tag '.$condition_query.' '.$tag_filter.')';
} }
} }
// Apply the module ACL with tags // Apply the module ACL with tags.
$sql_conditions_tags = ''; $sql_conditions_tags = '';
if (!users_is_admin()) { if (!users_is_admin()) {
@ -356,20 +365,20 @@ if (!users_is_admin()) {
} }
} }
// Two modes of filter. All the filters and only ACLs filter // 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; $sql_conditions_all = $sql_conditions.$sql_conditions_group.$sql_conditions_tags.$sql_conditions_custom_fields;
// Get count to paginate // Get count to paginate.
if (!defined('METACONSOLE')) { if (!defined('METACONSOLE')) {
$count = db_get_sql('SELECT COUNT(DISTINCT tagente_modulo.id_agente_modulo)'.$sql_from.$sql_conditions_all); $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 // Get limit_sql depend of the metaconsole or standard mode.
if (is_metaconsole()) { if (is_metaconsole()) {
// Offset will be used to get the subset of modules // Offset will be used to get the subset of modules.
$inferior_limit = $offset; $inferior_limit = $offset;
$superior_limit = ($config['block_size'] + $offset); $superior_limit = ($config['block_size'] + $offset);
// Offset reset to get all elements // Offset reset to get all elements.
$offset = 0; $offset = 0;
if (!isset($config['meta_num_elements'])) { if (!isset($config['meta_num_elements'])) {
$config['meta_num_elements'] = 100; $config['meta_num_elements'] = 100;
@ -380,9 +389,9 @@ if (is_metaconsole()) {
$limit_sql = $config['block_size']; $limit_sql = $config['block_size'];
} }
// End Build SQL sentences // End Build SQL sentences.
// //
// Start Build Search Form // Start Build Search Form.
// //
$table = new StdClass(); $table = new StdClass();
$table->width = '100%'; $table->width = '100%';
@ -436,7 +445,7 @@ $fields[AGENT_MODULE_STATUS_WARNING] = __('Warning');
$fields[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical'); $fields[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical');
$fields[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown'); $fields[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown');
$fields[AGENT_MODULE_STATUS_NOT_NORMAL] = __('Not normal'); $fields[AGENT_MODULE_STATUS_NOT_NORMAL] = __('Not normal');
// default // Default.
$fields[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init'); $fields[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init');
$table->data[0][2] = __('Monitor status'); $table->data[0][2] = __('Monitor status');
@ -528,32 +537,32 @@ $network_available = db_get_sql(
FROM tserver FROM tserver
WHERE server_type = 1' WHERE server_type = 1'
); );
// POSTGRESQL AND ORACLE COMPATIBLE // POSTGRESQL AND ORACLE COMPATIBLE.
$wmi_available = db_get_sql( $wmi_available = db_get_sql(
'SELECT count(*) 'SELECT count(*)
FROM tserver FROM tserver
WHERE server_type = 6' WHERE server_type = 6'
); );
// POSTGRESQL AND ORACLE COMPATIBLE // POSTGRESQL AND ORACLE COMPATIBLE.
$plugin_available = db_get_sql( $plugin_available = db_get_sql(
'SELECT count(*) 'SELECT count(*)
FROM tserver FROM tserver
WHERE server_type = 4' WHERE server_type = 4'
); );
// POSTGRESQL AND ORACLE COMPATIBLE // POSTGRESQL AND ORACLE COMPATIBLE.
$prediction_available = db_get_sql( $prediction_available = db_get_sql(
'SELECT count(*) 'SELECT count(*)
FROM tserver FROM tserver
WHERE server_type = 5' WHERE server_type = 5'
); );
// POSTGRESQL AND ORACLE COMPATIBLE // POSTGRESQL AND ORACLE COMPATIBLE.
$wux_available = db_get_sql( $wux_available = db_get_sql(
'SELECT count(*) 'SELECT count(*)
FROM tserver FROM tserver
WHERE server_type = 17' WHERE server_type = 17'
); );
// POSTGRESQL AND ORACLE COMPATIBLE // POSTGRESQL AND ORACLE COMPATIBLE.
// Development mode to use all servers // Development mode to use all servers.
if ($develop_bypass) { if ($develop_bypass) {
$network_available = 1; $network_available = 1;
$wmi_available = 1; $wmi_available = 1;
@ -606,7 +615,7 @@ $min_hours_val = empty($min_hours_status) ? '' : (int) $min_hours_status;
$table->data[2][4] = '<span>'.__('Min. hours in current status').'</span>'; $table->data[2][4] = '<span>'.__('Min. hours in current status').'</span>';
$table->data[2][5] = html_print_input_text('min_hours_status', $min_hours_val, '', 12, 20, true); $table->data[2][5] = html_print_input_text('min_hours_status', $min_hours_val, '', 12, 20, true);
$table->data[3][0] = '<span id="datatypetittle" '; $table->data[3][0] = '<span id="datatypetittle"';
$table->data[3][0] .= '>'.__('Data type').'</span>'; $table->data[3][0] .= '>'.__('Data type').'</span>';
@ -619,7 +628,7 @@ switch ($moduletype) {
$sql = sprintf( $sql = sprintf(
'SELECT id_tipo, descripcion 'SELECT id_tipo, descripcion
FROM ttipo_modulo FROM ttipo_modulo
WHERE categoria IN (6,7,8,0,1,2,-1) order by descripcion ' WHERE categoria '.$not_condition.' IN (6,7,8,0,1,2,-1) order by descripcion '
); );
break; break;
@ -627,7 +636,7 @@ switch ($moduletype) {
$sql = sprintf( $sql = sprintf(
'SELECT id_tipo, descripcion 'SELECT id_tipo, descripcion
FROM ttipo_modulo FROM ttipo_modulo
WHERE categoria between 3 and 5 ' WHERE categoria '.$not_condition.' between 3 and 5 '
); );
break; break;
@ -635,7 +644,7 @@ switch ($moduletype) {
$sql = sprintf( $sql = sprintf(
'SELECT id_tipo, descripcion 'SELECT id_tipo, descripcion
FROM ttipo_modulo FROM ttipo_modulo
WHERE categoria between 0 and 2 ' WHERE categoria '.$not_condition.' between 0 and 2 '
); );
break; break;
@ -643,7 +652,7 @@ switch ($moduletype) {
$sql = sprintf( $sql = sprintf(
'SELECT id_tipo, descripcion 'SELECT id_tipo, descripcion
FROM ttipo_modulo FROM ttipo_modulo
WHERE categoria between 0 and 2 ' WHERE categoria '.$not_condition.' between 0 and 2 '
); );
break; break;
@ -651,7 +660,7 @@ switch ($moduletype) {
$sql = sprintf( $sql = sprintf(
'SELECT id_tipo, descripcion 'SELECT id_tipo, descripcion
FROM ttipo_modulo FROM ttipo_modulo
WHERE categoria = 9' WHERE categoria '.$condition_query.' 9'
); );
break; break;
@ -659,7 +668,7 @@ switch ($moduletype) {
$sql = sprintf( $sql = sprintf(
'SELECT id_tipo, descripcion 'SELECT id_tipo, descripcion
FROM ttipo_modulo FROM ttipo_modulo
WHERE categoria = 0' WHERE categoria '.$condition_query.' 0'
); );
break; break;
@ -667,7 +676,7 @@ switch ($moduletype) {
$sql = sprintf( $sql = sprintf(
'SELECT id_tipo, descripcion 'SELECT id_tipo, descripcion
FROM ttipo_modulo FROM ttipo_modulo
WHERE nombre = \'web_analysis\'' WHERE nombre '.$condition_query.' \'web_analysis\''
); );
break; break;
@ -677,6 +686,10 @@ switch ($moduletype) {
FROM ttipo_modulo' FROM ttipo_modulo'
); );
break; break;
default:
// Nothing.
break;
} }
$a = db_get_all_rows_sql($sql); $a = db_get_all_rows_sql($sql);
@ -704,33 +717,45 @@ foreach ($a as $valor) {
$table->data[3][1] .= '</div>'; $table->data[3][1] .= '</div>';
$table->data[3][1] .= '<div class="w120px mrgn_top_20px">';
$table->data[3][1] .= html_print_input(
[
'type' => 'checkbox',
'name' => 'not_condition',
'return' => true,
'checked' => $check_not_condition,
'value' => 'NOT',
]
);
$table->data[3][1] .= __('Not condition').ui_print_help_tip(__('If this option is enabled, the events that DO NOT comply with this condition will be displayed.'), true);
$table->data[3][1] .= '</div>';
$table_custom_fields = new stdClass(); $table_custom_fields = new stdClass();
$table_custom_fields->class = 'filters'; $table_custom_fields->class = 'filters';
$table_custom_fields->width = '100%'; $table_custom_fields->width = '100%';
if (is_metaconsole()) { if (is_metaconsole()) {
$table_custom_fields->styleTable = 'margin-left:0px; margin-top:15px;'; $table_custom_fields->styleTable = 'margin-left:0px; margin-top:15px;';
$table_custom_fields->cellpadding = '0'; $table_custom_fields->cellpadding = '0';
$table_custom_fields->cellspacing = '0'; $table_custom_fields->cellspacing = '0';
} }
$table_custom_fields->style = []; $table_custom_fields->style = [];
if (!is_metaconsole()) { if (!is_metaconsole()) {
$table_custom_fields->style[0] = 'font-weight: bold; width: 150px;'; $table_custom_fields->style[0] = 'font-weight: bold; width: 150px;';
} else { } else {
$table_custom_fields->style[0] = 'font-weight: bold;'; $table_custom_fields->style[0] = 'font-weight: bold;';
} }
$table_custom_fields->colspan = []; $table_custom_fields->colspan = [];
$table_custom_fields->data = []; $table_custom_fields->data = [];
$custom_fields = db_get_all_fields_in_table('tagent_custom_fields'); $custom_fields = db_get_all_fields_in_table('tagent_custom_fields');
if ($custom_fields === false) { if ($custom_fields === false) {
$custom_fields = []; $custom_fields = [];
} }
foreach ($custom_fields as $custom_field) { foreach ($custom_fields as $custom_field) {
$row = []; $row = [];
$row[0] = $custom_field['name']; $row[0] = $custom_field['name'];
@ -745,10 +770,19 @@ foreach ($custom_fields as $custom_field) {
$row[1] = html_print_input_text('ag_custom_fields['.$custom_field['id_field'].']', $custom_field_value, '', 100, 300, true); $row[1] = html_print_input_text('ag_custom_fields['.$custom_field['id_field'].']', $custom_field_value, '', 100, 300, true);
$table_custom_fields->data[] = $row; $table_custom_fields->data[] = $row;
} }
$filters = '<form method="post" action="index.php?sec='.$section.'&sec2=operation/agentes/status_monitor&refr='.$refr.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&module_option='.$module_option.'&ag_modulename='.$ag_modulename.'&moduletype='.$moduletype.'&datatype='.$datatype.'&status='.$status.'&sort_field='.$sortField.'&sort='.$sort.'&pure='.$config['pure'].$ag_custom_fields_params.'">'; if ($not_condition !== '') {
if (is_metaconsole()) { $check_not_condition = true;
}
$filters = '<form method="post" action="index.php?sec='.$section.'&sec2=operation/agentes/status_monitor&refr='.$refr.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&module_option='.$module_option.'&ag_modulename='.$ag_modulename.'&moduletype='.$moduletype.'&datatype='.$datatype.'&status='.$status.'&sort_field='.$sortField.'&sort='.$sort.'&pure='.$config['pure'].$ag_custom_fields_params.'">';
if (is_metaconsole()) {
$table->colspan[4][0] = 7; $table->colspan[4][0] = 7;
$table->cellstyle[4][0] = 'padding: 10px;'; $table->cellstyle[4][0] = 'padding: 10px;';
$table->data[4][0] = ui_toggle( $table->data[4][0] = ui_toggle(
@ -763,7 +797,7 @@ if (is_metaconsole()) {
$filters .= html_print_table($table, true); $filters .= html_print_table($table, true);
$filters .= '</form>'; $filters .= '</form>';
ui_toggle($filters, __('Show filters'), '', '', false); ui_toggle($filters, __('Show filters'), '', '', false);
} else { } else {
$table->colspan[4][0] = 7; $table->colspan[4][0] = 7;
$table->cellstyle[4][0] = 'padding-left: 10px;'; $table->cellstyle[4][0] = 'padding-left: 10px;';
$table->data[4][0] = ui_toggle( $table->data[4][0] = ui_toggle(
@ -784,32 +818,32 @@ if (is_metaconsole()) {
$filters .= html_print_table($table, true); $filters .= html_print_table($table, true);
$filters .= '</form>'; $filters .= '</form>';
echo $filters; echo $filters;
} }
unset($table); unset($table);
// End Build Search Form // End Build Search Form.
// //
// Sort functionality // Sort functionality.
$selected = true; $selected = true;
$selectAgentNameUp = false; $selectAgentNameUp = false;
$selectAgentNameDown = false; $selectAgentNameDown = false;
$selectDataTypeUp = false; $selectDataTypeUp = false;
$selectDataTypeDown = false; $selectDataTypeDown = false;
$selectTypeUp = false; $selectTypeUp = false;
$selectTypeDown = false; $selectTypeDown = false;
$selectModuleNameUp = false; $selectModuleNameUp = false;
$selectModuleNameDown = false; $selectModuleNameDown = false;
$selectIntervalUp = false; $selectIntervalUp = false;
$selectIntervalDown = false; $selectIntervalDown = false;
$selectStatusUp = false; $selectStatusUp = false;
$selectStatusDown = false; $selectStatusDown = false;
$selectDataUp = false; $selectDataUp = false;
$selectDataDown = false; $selectDataDown = false;
$selectTimestampUp = false; $selectTimestampUp = false;
$selectTimestampDown = false; $selectTimestampDown = false;
$order = null; $order = null;
switch ($sortField) { switch ($sortField) {
case 'agent_alias': case 'agent_alias':
switch ($sort) { switch ($sort) {
case 'up': case 'up':
@ -1012,9 +1046,9 @@ switch ($sortField) {
'order' => 'ASC', 'order' => 'ASC',
]; ];
break; break;
} }
$sql = 'SELECT $sql = 'SELECT
(SELECT GROUP_CONCAT(ttag.name SEPARATOR \',\') (SELECT GROUP_CONCAT(ttag.name SEPARATOR \',\')
FROM ttag FROM ttag
WHERE ttag.id_tag IN ( WHERE ttag.id_tag IN (
@ -1060,8 +1094,8 @@ $sql = 'SELECT
LIMIT '.$offset.','.$limit_sql; LIMIT '.$offset.','.$limit_sql;
// We do not show the modules until the user searches with the filter // We do not show the modules until the user searches with the filter.
if ($autosearch) { if ($autosearch) {
if (! defined('METACONSOLE')) { if (! defined('METACONSOLE')) {
$result = db_get_all_rows_sql($sql); $result = db_get_all_rows_sql($sql);
@ -1071,7 +1105,7 @@ if ($autosearch) {
ui_pagination($count, false, $offset, 0, false, 'offset', true); ui_pagination($count, false, $offset, 0, false, 'offset', true);
} }
} else { } else {
// For each server defined and not disabled: // For each server defined and not disabled.
$servers = db_get_all_rows_sql( $servers = db_get_all_rows_sql(
'SELECT * 'SELECT *
FROM tmetaconsole_setup FROM tmetaconsole_setup
@ -1084,7 +1118,7 @@ if ($autosearch) {
$result = []; $result = [];
$count_modules = 0; $count_modules = 0;
foreach ($servers as $server) { foreach ($servers as $server) {
// If connection was good then retrieve all data server // If connection was good then retrieve all data server.
if (metaconsole_connect($server) == NOERR) { if (metaconsole_connect($server) == NOERR) {
$connection = true; $connection = true;
} else { } else {
@ -1094,7 +1128,7 @@ if ($autosearch) {
$result_server = db_get_all_rows_sql($sql); $result_server = db_get_all_rows_sql($sql);
if (!empty($result_server)) { if (!empty($result_server)) {
// Create HASH login info // Create HASH login info.
$pwd = $server['auth_token']; $pwd = $server['auth_token'];
$auth_serialized = json_decode($pwd, true); $auth_serialized = json_decode($pwd, true);
@ -1135,67 +1169,67 @@ if ($autosearch) {
ui_pagination($count_modules, false, $offset); ui_pagination($count_modules, false, $offset);
} }
// Get number of elements of the pagination // Get number of elements of the pagination.
$result = ui_meta_get_subset_array($result, $inferior_limit, $superior_limit); $result = ui_meta_get_subset_array($result, $inferior_limit, $superior_limit);
} }
} }
if (($config['dbtype'] == 'oracle') && ($result !== false)) { if (($config['dbtype'] == 'oracle') && ($result !== false)) {
for ($i = 0; $i < count($result); $i++) { for ($i = 0; $i < count($result); $i++) {
unset($result[$i]['rnum']); unset($result[$i]['rnum']);
} }
} }
// Urls to sort the table. // Urls to sort the table.
$url_agent_name = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_agent_name = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_type = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_type = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_module_name = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_module_name = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_server_type = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_server_type = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_interval = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_interval = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_status = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_status = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_status = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_status = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_data = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_data = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_timestamp_up = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_timestamp_up = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_timestamp_down = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor'; $url_timestamp_down = 'index.php?sec='.$section.'&sec2=operation/agentes/status_monitor';
$url_agent_name .= '&refr='.$refr.'&datatype='.$datatype.'&moduletype='.$moduletype.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_agent_name .= '&refr='.$refr.'&datatype='.$datatype.'&moduletype='.$moduletype.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_type .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_type .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_module_name .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_module_name .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_server_type .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_server_type .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_interval .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_interval .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_status .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_status .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_status .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_status .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_data .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_data .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_timestamp_up .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_timestamp_up .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
$url_timestamp_down .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params; $url_timestamp_down .= '&datatype='.$datatype.'&moduletype='.$moduletype.'&refr='.$refr.'&modulegroup='.$modulegroup.'&offset='.$offset.'&ag_group='.$ag_group.'&ag_freestring='.$ag_freestring.'&ag_modulename='.$ag_modulename.'&status='.$status.$ag_custom_fields_params;
// Holy god... // Holy god...
$url_agent_name .= '&recursion='.$recursion; $url_agent_name .= '&recursion='.$recursion;
$url_type .= '&recursion='.$recursion; $url_type .= '&recursion='.$recursion;
$url_module_name .= '&recursion='.$recursion; $url_module_name .= '&recursion='.$recursion;
$url_server_type .= '&recursion='.$recursion; $url_server_type .= '&recursion='.$recursion;
$url_interval .= '&recursion='.$recursion; $url_interval .= '&recursion='.$recursion;
$url_status .= '&recursion='.$recursion; $url_status .= '&recursion='.$recursion;
$url_status .= '&recursion='.$recursion; $url_status .= '&recursion='.$recursion;
$url_data .= '&recursion='.$recursion; $url_data .= '&recursion='.$recursion;
$url_timestamp_up .= '&recursion='.$recursion; $url_timestamp_up .= '&recursion='.$recursion;
$url_timestamp_down .= '&recursion='.$recursion; $url_timestamp_down .= '&recursion='.$recursion;
$url_agent_name .= '&sort_field=agent_alias&sort='; $url_agent_name .= '&sort_field=agent_alias&sort=';
$url_type .= '&sort_field=type&sort='; $url_type .= '&sort_field=type&sort=';
$url_module_name .= '&sort_field=module_name&sort='; $url_module_name .= '&sort_field=module_name&sort=';
$url_server_type .= '&sort_field=moduletype&sort='; $url_server_type .= '&sort_field=moduletype&sort=';
$url_interval .= '&sort_field=interval&sort='; $url_interval .= '&sort_field=interval&sort=';
$url_status .= '&sort_field=status&sort='; $url_status .= '&sort_field=status&sort=';
$url_status .= '&sort_field=last_status_change&sort='; $url_status .= '&sort_field=last_status_change&sort=';
$url_data .= '&sort_field=data&sort='; $url_data .= '&sort_field=data&sort=';
$url_timestamp_up .= '&sort_field=timestamp&sort=up'; $url_timestamp_up .= '&sort_field=timestamp&sort=up';
$url_timestamp_down .= '&sort_field=timestamp&sort=down'; $url_timestamp_down .= '&sort_field=timestamp&sort=down';
// Start Build List Result // Start Build List Result.
if (!empty($result)) { if (!empty($result)) {
$table = new StdClass(); $table = new StdClass();
$table->cellpadding = 0; $table->cellpadding = 0;
$table->cellspacing = 0; $table->cellspacing = 0;
@ -1286,7 +1320,7 @@ if (!empty($result)) {
); );
foreach ($result as $row) { foreach ($result as $row) {
// Avoid unset, null and false value // Avoid unset, null and false value.
if (empty($row['server_name'])) { if (empty($row['server_name'])) {
$row['server_name'] = ''; $row['server_name'] = '';
} }
@ -1300,13 +1334,13 @@ if (!empty($result)) {
] ]
); );
// Fixed the goliat sends the strings from web // Fixed the goliat sends the strings from web.
// without HTML entities // Without HTML entities.
if ($is_web_content_string) { if ($is_web_content_string) {
$row['datos'] = io_safe_input($row['datos']); $row['datos'] = io_safe_input($row['datos']);
} }
// Fixed the data from Selenium Plugin // Fixed the data from Selenium Plugin.
if ($row['datos'] != strip_tags($row['datos'])) { if ($row['datos'] != strip_tags($row['datos'])) {
$row['datos'] = io_safe_input($row['datos']); $row['datos'] = io_safe_input($row['datos']);
} }
@ -1479,7 +1513,9 @@ if (!empty($result)) {
if (is_numeric($row['datos'])) { if (is_numeric($row['datos'])) {
$data[6] = ui_print_status_image( $data[6] = ui_print_status_image(
STATUS_MODULE_CRITICAL, STATUS_MODULE_CRITICAL,
__('CRITICAL').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), __('CRITICAL').': '.remove_right_zeros(
number_format($row['datos'], $config['graph_precision'])
),
true true
); );
} else { } else {
@ -1493,7 +1529,9 @@ if (!empty($result)) {
if (is_numeric($row['datos'])) { if (is_numeric($row['datos'])) {
$data[6] = ui_print_status_image( $data[6] = ui_print_status_image(
STATUS_MODULE_WARNING, STATUS_MODULE_WARNING,
__('WARNING').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), __('WARNING').': '.remove_right_zeros(
number_format($row['datos'], $config['graph_precision'])
),
true true
); );
} else { } else {
@ -1507,7 +1545,9 @@ if (!empty($result)) {
if (is_numeric($row['datos'])) { if (is_numeric($row['datos'])) {
$data[6] = ui_print_status_image( $data[6] = ui_print_status_image(
STATUS_MODULE_UNKNOWN, STATUS_MODULE_UNKNOWN,
__('UNKNOWN').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), __('UNKNOWN').': '.remove_right_zeros(
number_format($row['datos'], $config['graph_precision'])
),
true true
); );
} else { } else {
@ -1521,7 +1561,9 @@ if (!empty($result)) {
if (is_numeric($row['datos'])) { if (is_numeric($row['datos'])) {
$data[6] = ui_print_status_image( $data[6] = ui_print_status_image(
STATUS_MODULE_NO_DATA, STATUS_MODULE_NO_DATA,
__('NO DATA').': '.remove_right_zeros(number_format($row['datos'], $config['graph_precision'])), __('NO DATA').': '.remove_right_zeros(
number_format($row['datos'], $config['graph_precision'])
),
true true
); );
} else { } else {
@ -1596,7 +1638,7 @@ if (!empty($result)) {
$acl_graphs = false; $acl_graphs = false;
// Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions // Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions.
if (!is_metaconsole()) { if (!is_metaconsole()) {
$agent_groups = agents_get_all_groups_agent($row['id_agent'], $row['id_group']); $agent_groups = agents_get_all_groups_agent($row['id_agent'], $row['id_group']);
$acl_graphs = check_acl_one_of_groups($config['id_user'], $agent_groups, 'RR'); $acl_graphs = check_acl_one_of_groups($config['id_user'], $agent_groups, 'RR');
@ -1619,7 +1661,7 @@ if (!empty($result)) {
]; ];
if (is_metaconsole() && isset($row['server_id'])) { if (is_metaconsole() && isset($row['server_id'])) {
// Set the server id // Set the server id.
$graph_params['server'] = $row['server_id']; $graph_params['server'] = $row['server_id'];
} }
@ -1710,7 +1752,7 @@ if (!empty($result)) {
} }
} }
// Show units ONLY in numeric data types // Show units ONLY in numeric data types.
if (isset($row['unit'])) { if (isset($row['unit'])) {
$data_macro = modules_get_unit_macro($row['datos'], $row['unit']); $data_macro = modules_get_unit_macro($row['datos'], $row['unit']);
if ($data_macro) { if ($data_macro) {
@ -1719,7 +1761,7 @@ if (!empty($result)) {
$salida .= '&nbsp;'.'<i>'.io_safe_output($row['unit']).'</i>'; $salida .= '&nbsp;'.'<i>'.io_safe_output($row['unit']).'</i>';
if (strlen($salida) > $config['agent_size_text_small']) { if (strlen($salida) > $config['agent_size_text_small']) {
$salida = ui_print_truncate_text($salida, 'agent_small', true, true, false, '[&hellip;]', 'font-size:7.5pt;'); $salida = ui_print_truncate_text($salida, 'agent_small', true, true, false, '[&hellip;]', 'font-size:7.5pt;');
// clean tag <i> // Clean tag <i>.
$text_aux = explode('<a', $salida); $text_aux = explode('<a', $salida);
$match = preg_replace('/(&lt;i&gt;|&lt;\/i&gt;|&lt;i|&lt;\/i|i&gt;|\/i&gt;|&lt;|&gt;)/', '', $text_aux[0]); $match = preg_replace('/(&lt;i&gt;|&lt;\/i&gt;|&lt;i|&lt;\/i|i&gt;|\/i&gt;|&lt;|&gt;)/', '', $text_aux[0]);
$salida = $match.'<a'.$text_aux[1]; $salida = $match.'<a'.$text_aux[1];
@ -1729,8 +1771,8 @@ if (!empty($result)) {
} }
} }
} else { } else {
// Fixed the goliat sends the strings from web // Fixed the goliat sends the strings from web.
// without HTML entities // Without HTML entities.
if ($is_web_content_string) { if ($is_web_content_string) {
$module_value = $row['datos']; $module_value = $row['datos'];
} else { } else {
@ -1764,12 +1806,12 @@ if (!empty($result)) {
} }
} }
} else { } else {
// Fixed the goliat sends the strings from web // Fixed the goliat sends the strings from web.
// without HTML entities // Without HTML entities.
if ($is_web_content_string) { if ($is_web_content_string) {
$sub_string = substr($row['datos'], 0, 12); $sub_string = substr($row['datos'], 0, 12);
} else { } else {
// Fixed the data from Selenium Plugin // Fixed the data from Selenium Plugin.
if ($module_value != strip_tags($module_value)) { if ($module_value != strip_tags($module_value)) {
$module_value = io_safe_input($module_value); $module_value = io_safe_input($module_value);
$sub_string = substr($row['datos'], 0, 12); $sub_string = substr($row['datos'], 0, 12);
@ -1821,22 +1863,22 @@ if (!empty($result)) {
if ($count_modules > $config['block_size']) { if ($count_modules > $config['block_size']) {
ui_pagination($count_modules, false, $offset, 0, false, 'offset', true, 'pagination-bottom'); ui_pagination($count_modules, false, $offset, 0, false, 'offset', true, 'pagination-bottom');
} }
} else { } else {
if ($first_interaction) { if ($first_interaction) {
ui_print_info_message(['no_close' => true, 'message' => __('This group doesn\'t have any monitor')]); ui_print_info_message(['no_close' => true, 'message' => __('This group doesn\'t have any monitor')]);
} else { } else {
ui_print_info_message(['no_close' => true, 'message' => __('Sorry no search parameters')]); ui_print_info_message(['no_close' => true, 'message' => __('Sorry no search parameters')]);
} }
} }
// End Build List Result. // End Build List Result.
echo "<div id='monitor_details_window'></div>"; echo "<div id='monitor_details_window'></div>";
enterprise_hook('close_meta_frame'); enterprise_hook('close_meta_frame');
ui_require_javascript_file('pandora_modules'); ui_require_javascript_file('pandora_modules');
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$('#moduletype').click(function() { $('#moduletype').click(function() {
@ -1869,7 +1911,7 @@ function toggle_full_value(id) {
$("#value_module_text_" + id).html(text); $("#value_module_text_" + id).html(text);
} }
// Show the modal window of an module // Show the modal window of an module.
function show_module_detail_dialog(module_id, id_agent, server_name, offset, period, module_name) { function show_module_detail_dialog(module_id, id_agent, server_name, offset, period, module_name) {
if (period == -1) { if (period == -1) {
if ($("#period").length == 1) { if ($("#period").length == 1) {