function tholds() { global $config, $device_actions, $item_rows, $thold_classes, $thold_states; /* ================= input validation and session storage ================= */ $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'name', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')), 'data_template_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'host_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1')); validate_store_request_vars($filters, 'sess_thold'); /* ================= input validation ================= */ /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } html_start_box(__('Threshold Status'), '100%', '', '3', 'center', ''); form_thold_filter(); html_end_box(); /* build the SQL query and WHERE clause */ if (get_request_var('sort_column') == 'lastread') { $sort = get_request_var('sort_column') . "/1"; } else { $sort = get_request_var('sort_column'); } $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows; $sql_where = ''; /* status filter */ if (get_request_var('status') == '-1') { /* return all rows */ } else { if (get_request_var('status') == '0') { $sql_where = "(td.thold_enabled='off'"; } /*disabled*/ if (get_request_var('status') == '2') { $sql_where = "(td.thold_enabled='on'"; } /* enabled */ if (get_request_var('status') == '1') { $sql_where = "((td.thold_alert!=0 OR td.bl_alert>0)"; } /* breached */ if (get_request_var('status') == '3') { $sql_where = "(((td.thold_alert!=0 AND td.thold_fail_count >= td.thold_fail_trigger) OR (td.bl_alert>0 AND td.bl_fail_count >= td.bl_fail_trigger))"; } /* status */ } if (strlen(get_request_var('filter'))) { $sql_where .= (strlen($sql_where) ? ' AND' : '(') . " td.name LIKE '%" . get_request_var('filter') . "%'"; } /* data template id filter */ if (get_request_var('data_template_id') != '-1') { $sql_where .= (strlen($sql_where) ? ' AND' : '(') . ' td.data_template_id=' . get_request_var('data_template_id'); } /* host id filter */ if (get_request_var('host_id') != '-1') { $sql_where .= (strlen($sql_where) ? ' AND' : '(') . ' td.host_id=' . get_request_var('host_id'); } if ($sql_where != '') { $sql_where .= ')'; } $tholds = get_allowed_thresholds($sql_where, $sort . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ", {$rows}", $total_rows); $nav = html_nav_bar('thold_graph.php?action=thold', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 13, 'Thresholds', 'page', 'main'); print $nav; html_start_box('', '100%', '', '4', 'center', ''); $display_text = array('nosort' => array('display' => __('Actions'), 'sort' => '', 'align' => 'left'), 'name' => array('display' => __('Name'), 'sort' => 'ASC', 'align' => 'left'), 'id' => array('display' => __('ID'), 'sort' => 'ASC', 'align' => 'right'), 'thold_type' => array('display' => __('Type'), 'sort' => 'ASC', 'align' => 'left'), 'lastread' => array('display' => __('Current'), 'sort' => 'ASC', 'align' => 'right'), 'nosort4' => array('display' => __('Warn Hi/Lo'), 'sort' => 'ASC', 'align' => 'right'), 'nosort5' => array('display' => __('Alert Hi/Lo'), 'sort' => 'ASC', 'align' => 'right'), 'nosort6' => array('display' => __('BL Hi/Lo'), 'sort' => 'ASC', 'align' => 'right'), 'nosort2' => array('display' => __('Trigger'), 'sort' => 'ASC', 'align' => 'right'), 'nosort3' => array('display' => __('Duration'), 'sort' => 'ASC', 'align' => 'right'), 'repeat_alert' => array('display' => __('Repeat'), 'sort' => 'ASC', 'align' => 'right'), 'thold_alert' => array('display' => __('Triggered'), 'sort' => 'ASC', 'align' => 'right')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'thold_graph.php?action=thold'); $step = read_config_option('poller_interval'); include $config['base_path'] . '/plugins/thold/includes/arrays.php'; $c = 0; $i = 0; if (sizeof($tholds)) { foreach ($tholds as $row) { $c++; $alertstat = 'No'; $bgcolor = 'green'; if ($row['thold_type'] == 0) { if ($row['thold_alert'] != 0) { $alertstat = __('Yes'); if ($row['thold_fail_count'] >= $row['thold_fail_trigger']) { $bgcolor = 'red'; } elseif ($row['thold_warning_fail_count'] >= $row['thold_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } elseif ($row['thold_type'] == 2) { if ($row['thold_alert'] != 0) { $alertstat = 'Yes'; if ($row['thold_fail_count'] >= $row['time_fail_trigger']) { $bgcolor = 'red'; } elseif ($row['thold_warning_fail_count'] >= $row['time_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } else { if ($row['bl_alert'] == 1) { $alertstat = __('Baseline-LOW'); $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow'; } elseif ($row['bl_alert'] == 2) { $alertstat = __('Baseline-HIGH'); $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow'; } } if ($row['thold_enabled'] == 'off') { print "<tr class='selectable " . $thold_states['grey']['class'] . "' id='line" . $row['id'] . "'>\n"; } else { print "<tr class='selectable " . $thold_states[$bgcolor]['class'] . "' id='line" . $row['id'] . "'>\n"; } print "<td width='1%' style='white-space:nowrap;'>"; if (api_user_realm_auth('thold.php')) { print '<a href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold.php?action=edit&id=' . $row['id']) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/edit_object.png" border="0" alt="" title="' . __('Edit Threshold') . '"></a>'; } if ($row['thold_enabled'] == 'on') { print '<a class="hyperLink" href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold_graph.php?action=disable&id=' . $row['id']) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/disable_thold.png" border="0" alt="" title="' . __('Disable Threshold') . '"></a>'; } else { print '<a class="hyperLink" href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold_graph.php?action=enable&id=' . $row['id']) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/enable_thold.png" border="0" alt="" title="' . __('Enable Threshold') . '"></a>'; } print "<a href='" . htmlspecialchars($config['url_path'] . 'graph.php?local_graph_id=' . $row['local_graph_id'] . '&rra_id=all') . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_graphs.gif' border='0' alt='' title='" . __('View Graph') . "'></a>"; print "<a class='hyperLink' href='" . htmlspecialchars($config['url_path'] . 'plugins/thold/thold_graph.php?action=log&threshold_id=' . $row['id'] . '&status=-1') . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_log.gif' border='0' alt='' title='" . __('View Threshold History') . "'></a>"; print '</td>'; print "<td class='left nowrap'>" . ($row['name'] != '' ? $row['name'] : 'No name set') . '</td>'; print "<td class='right'>" . $row['id'] . '</td>'; print "<td class='left nowrap'>" . $thold_types[$row['thold_type']] . '</td>'; print "<td class='right'>" . thold_format_number($row['lastread']) . '</td>'; print "<td class='right nowrap'>" . ($row['thold_type'] == 1 ? __('N/A') : ($row['thold_type'] == 2 ? thold_format_number($row['time_warning_hi']) . '/' . thold_format_number($row['time_warning_low']) : thold_format_number($row['thold_warning_hi']) . '/' . thold_format_number($row['thold_warning_low']))) . '</td>'; print "<td class='right'>" . ($row['thold_type'] == 1 ? __('N/A') : ($row['thold_type'] == 2 ? thold_format_number($row['time_hi']) . '/' . thold_format_number($row['time_low']) : thold_format_number($row['thold_hi']) . '/' . thold_format_number($row['thold_low']))) . '</td>'; print "<td class='right'>" . ($row['thold_type'] == 1 ? $row['bl_pct_up'] . (strlen($row['bl_pct_up']) ? '%' : '-') . '/' . $row['bl_pct_down'] . (strlen($row['bl_pct_down']) ? '%' : '-') : __('N/A')) . '</td>'; switch ($row['thold_type']) { case 0: print "<td class='right nowrap'><i>" . plugin_thold_duration_convert($row['local_data_id'], $row['thold_fail_trigger'], 'alert') . '</i></td>'; print "<td class='right'>" . __('N/A') . "</td>"; break; case 1: print "<td class='right nowrap'><i>" . plugin_thold_duration_convert($row['local_data_id'], $row['bl_fail_trigger'], 'alert') . '</i></td>'; print "<td class='right nowrap'>" . $timearray[$row['bl_ref_time_range'] / 300] . '</td>'; break; case 2: print "<td class='right nowrap'><i>" . $row['time_fail_trigger'] . ' Triggers</i></td>'; print "<td class='right nowrap'>" . plugin_thold_duration_convert($row['local_data_id'], $row['time_fail_length'], 'time') . '</td>'; break; default: print "<td class='right'>" . __('N/A') . "</td>"; print "<td class='right'>" . __('N/A') . "</td>"; } print "<td class='right nowrap'>" . ($row['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($row['local_data_id'], $row['repeat_alert'], 'repeat')) . '</td>'; print "<td class='right'>" . $alertstat . '</td>'; form_end_row(); } } else { print '<tr class="even"><td class="center" colspan="13">' . __('No Thresholds') . '</td></tr>'; } html_end_box(false); if (sizeof($tholds)) { print $nav; } thold_legend(); //thold_display_rusage(); }
function list_tholds() { global $thold_states, $config, $host_id, $timearray, $thold_types; $thold_actions = array(1 => __('Delete'), 2 => __('Disable'), 3 => __('Enable'), 4 => __('Reapply Suggested Names'), 5 => __('Propagate Template')); thold_request_validation(); /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } $statefilter = ''; if (isset_request_var('state')) { if (get_request_var('state') == '-1') { $statefilter = ''; } else { if (get_request_var('state') == '0') { $statefilter = "thold_data.thold_enabled='off'"; } if (get_request_var('state') == '2') { $statefilter = "thold_data.thold_enabled='on'"; } if (get_request_var('state') == '1') { $statefilter = '(thold_data.thold_alert!=0 OR thold_data.bl_alert>0)'; } if (get_request_var('state') == '3') { $statefilter = '((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))'; } } } top_header(); $sql_where = ''; $sort = get_request_var('sort_column'); $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ", {$rows}"; if (!isempty_request_var('host_id') && get_request_var('host_id') != '-1') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.host_id = " . get_request_var('host_id'); } if (!isempty_request_var('data_template_id') && get_request_var('data_template_id') != '-1') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.data_template_id = " . get_request_var('data_template_id'); } if ($statefilter != '') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "{$statefilter}"; } if ($sql_where != '') { $sql_where .= ')'; } $tholds = get_allowed_thresholds($sql_where, $sort . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ", {$rows}", $total_rows); $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\tFROM data_template\n\t\tINNER JOIN thold_data \n\t\tON thold_data.data_template_id = data_template.id\n\t\tORDER BY data_template.name"); html_start_box(__('Threshold Management'), '100%', '', '3', 'center', 'thold.php?action=add'); ?> <tr class='even'> <td> <form id='listthold' action='thold.php' method='post'> <table class='filterTable'> <tr> <td> <?php print __('Search'); ?> </td> <td> <input type='text' id='filter' size='25' value='<?php print get_request_var('filter'); ?> '> </td> <?php print html_host_filter(get_request_var('host_id')); ?> <td> <?php print __('Template'); ?> </td> <td> <select id='data_template_id' onChange='applyFilter()'> <option value='-1'><?php print __('Any'); ?> </option> <?php foreach ($data_templates as $row) { echo "<option value='" . $row['id'] . "'" . (isset_request_var('data_template_id') && $row['id'] == get_request_var('data_template_id') ? ' selected' : '') . '>' . $row['name'] . '</option>'; } ?> </select> </td> <td> <?php print __('State'); ?> </td> <td> <select id='state' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('state') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <option value='1'<?php if (get_request_var('state') == '1') { ?> selected<?php } ?> ><?php print __('Breached'); ?> </option> <option value='3'<?php if (get_request_var('state') == '3') { ?> selected<?php } ?> ><?php print __('Triggered'); ?> </option> <option value='2'<?php if (get_request_var('state') == '2') { ?> selected<?php } ?> ><?php print __('Enabled'); ?> </option> <option value='0'<?php if (get_request_var('state') == '0') { ?> selected<?php } ?> ><?php print __('Disabled'); ?> </option> </select> </td> <td> <input type='button' id='refresh' value='<?php print __('Go'); ?> ' title='<?php print __('Apply Filters'); ?> ' onClick='applyFilter()'> </td> <td> <input type='button' id='clear' value='<?php print __('Clear'); ?> ' title='<?php print __('Return to Defaults'); ?> ' onClick='clearFilter()'> </td> </tr> </table> <input type='hidden' name='search' value='search'> <input type='hidden' id='page' value='<?php print get_filter_request_var('page'); ?> '> </form> <script type='text/javascript'> function applyFilter() { strURL = 'thold.php?header=false&host_id=' + $('#host_id').val(); strURL += '&state=' + $('#state').val(); strURL += '&data_template_id=' + $('#data_template_id').val(); strURL += '&filter=' + $('#filter').val(); loadPageNoHeader(strURL); } function clearFilter() { strURL = 'thold.php?header=false&clear=1'; loadPageNoHeader(strURL); } $(function() { $('#listthold').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); $nav = html_nav_bar('thold.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 14, __('Thresholds'), 'page', 'main'); form_start('thold.php', 'chk'); print $nav; html_start_box('', '100%', '', '4', 'center', ''); $display_text = array('name' => array('display' => __('Name'), 'sort' => 'ASC', 'align' => 'left'), 'id' => array('display' => __('ID'), 'sort' => 'ASC', 'align' => 'right'), 'thold_type' => array('display' => __('Type'), 'sort' => 'ASC', 'align' => 'right'), 'data_source' => array('display' => __('DSName'), 'sort' => 'ASC', 'align' => 'right'), 'lastread' => array('display' => __('Current'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('The last measured value for the Data Source')), 'thold_hi' => array('display' => __('High'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('High Threshold values for Warning/Alert')), 'thold_low' => array('display' => __('Low'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('Low Threshold values for Warning/Alert')), 'nosort3' => array('display' => __('Trigger'), 'sort' => '', 'align' => 'right'), 'nosort4' => array('display' => __('Duration'), 'sort' => '', 'align' => 'right'), 'repeat_alert' => array('display' => __('Repeat'), 'sort' => 'ASC', 'align' => 'right'), 'thold_alert' => array('display' => __('Triggered'), 'sort' => 'ASC', 'align' => 'right'), 'template_enabled' => array('display' => __('Templated'), 'sort' => 'ASC', 'align' => 'right')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); $c = 0; $i = 0; if (sizeof($tholds)) { foreach ($tholds as $thold_data) { $c++; $grapharr = db_fetch_row('SELECT DISTINCT graph_templates_item.local_graph_id FROM graph_templates_item, data_template_rrd WHERE (data_template_rrd.local_data_id=' . $thold_data['local_data_id'] . ' AND data_template_rrd.id=graph_templates_item.task_item_id)'); $local_graph_id = $grapharr['local_graph_id']; $alertstat = __('No'); $bgcolor = 'green'; if ($thold_data['thold_type'] == 0) { if ($thold_data['thold_alert'] != 0) { $alertstat = __('Yes'); if ($thold_data['thold_fail_count'] >= $thold_data['thold_fail_trigger']) { $bgcolor = 'red'; } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['thold_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } elseif ($thold_data['thold_type'] == 2) { if ($thold_data['thold_alert'] != 0) { $alertstat = __('Yes'); if ($thold_data['thold_fail_count'] >= $thold_data['time_fail_trigger']) { $bgcolor = 'red'; } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['time_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } else { if ($thold_data['bl_alert'] == 1) { $alertstat = __('baseline-LOW'); $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow'; } elseif ($thold_data['bl_alert'] == 2) { $alertstat = __('baseline-HIGH'); $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow'; } } $data_source = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array($thold_data['data_template_rrd_id'])); if ($thold_data['thold_enabled'] == 'off') { print "<tr class='selectable " . $thold_states['grey']['class'] . "' id='line" . $thold_data['id'] . "'>\n"; } else { print "<tr class='selectable " . $thold_states[$bgcolor]['class'] . "' id='line" . $thold_data['id'] . "'>\n"; } form_selectable_cell(filter_value($thold_data['name'] != '' ? $thold_data['name'] : $thold_data['name_cache'] . ' [' . $thold_data['data_source_name'] . ']', get_request_var('filter'), 'thold.php?action=edit&id=' . $thold_data['id']) . '</a>', $thold_data['id'], '', 'text-align:left'); form_selectable_cell($thold_data['id'], $thold_data['id'], '', 'text-align:right'); form_selectable_cell($thold_types[$thold_data['thold_type']], $thold_data['id'], '', 'text-align:right'); form_selectable_cell($data_source, $thold_data['id'], '', 'text-align:right'); switch ($thold_data['thold_type']) { case 0: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['thold_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); break; case 1: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['bl_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell($timearray[$thold_data['bl_ref_time_range'] / 300], $thold_data['id'], '', 'text-align:right'); break; case 2: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['time_warning_hi']) . ' / ' . thold_format_number($thold_data['time_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['time_warning_low']) . ' / ' . thold_format_number($thold_data['time_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . __('%d Triggers', $thold_data['time_fail_trigger']) . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['time_fail_length'], 'time') . '</i>', $thold_data['id'], '', 'text-align:right'); break; default: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right'); form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); } form_selectable_cell($thold_data['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['repeat_alert'], 'repeat'), $thold_data['id'], '', 'text-align:right'); form_selectable_cell($alertstat, $thold_data['id'], '', 'text-align:right'); if ($thold_data['thold_template_id'] != 0) { form_selectable_cell($thold_data['template_enabled'] == '' ? __('No') : __('Yes'), $thold_data['id'], '', 'text-align:right'); } else { form_selectable_cell(__('No'), $thold_data['id'], '', 'text-align:right'); } form_checkbox_cell($thold_data['name'], $thold_data['id'], '', 'text-align:left'); form_end_row(); } } else { print "<tr class='even'><td colspan='14'><center>" . __('No Thresholds') . "</center></td></tr>\n"; } html_end_box(false); if (sizeof($tholds)) { print $nav; } thold_legend(); draw_actions_dropdown($thold_actions); if (isset($host_id) && $host_id != '') { print "<input type='hidden' name='host_id' value='{$host_id}'>"; } form_end(); bottom_footer(); }
function tholds() { global $config, $colors, $thold_bgcolors, $device_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("data_template_id")); input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("triggered")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear"])) { kill_session_var("sess_thold_current_page"); kill_session_var("sess_thold_filter"); kill_session_var("sess_thold_data_template_id"); kill_session_var("sess_thold_host_id"); kill_session_var("sess_thold_rows"); kill_session_var("sess_thold_triggered"); kill_session_var("sess_thold_sort_column"); kill_session_var("sess_thold_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["data_template_id"]); unset($_REQUEST["host_id"]); unset($_REQUEST["rows"]); unset($_REQUEST["triggered"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } else { /* if any of the settings changed, reset the page number */ $changed = 0; $changed += thold_request_check_changed('filter', 'sess_thold_filter'); $changed += thold_request_check_changed('data_template_id', 'sess_thold_data_template_id'); $changed += thold_request_check_changed('host_id', 'sess_thold_host_id'); $changed += thold_request_check_changed('rows', 'sess_thold_rows'); $changed += thold_request_check_changed('triggered', 'sess_thold_triggered'); $changed += thold_request_check_changed('sort_column', 'sess_thold_sort_column'); $changed += thold_request_check_changed('sort_direction', 'sess_thold_sort_direction'); if ($changed) { $_REQUEST['page'] = '1'; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_thold_current_page", "1"); load_current_session_value("filter", "sess_thold_filter", ""); load_current_session_value("triggered", "sess_thold_triggered", read_config_option("thold_filter_default")); load_current_session_value("data_template_id", "sess_thold_data_template_id", "-1"); load_current_session_value("host_id", "sess_thold_host_id", "-1"); load_current_session_value("rows", "sess_thold_rows", read_config_option("alert_num_rows")); load_current_session_value("sort_column", "sess_thold_sort_column", "thold_alert"); load_current_session_value("sort_direction", "sess_thold_sort_direction", "DESC"); /* if the number of rows is -1, set it to the default */ if ($_REQUEST["rows"] == -1 || !isset($_REQUEST["rows"])) { $_REQUEST["rows"] = read_config_option("alert_num_rows"); if ($_REQUEST["rows"] < 2) { $_REQUEST["rows"] = 30; } } ?> <script type="text/javascript"> <!-- function applyTHoldFilterChange(objForm) { strURL = '?tab=thold&triggered=' + objForm.triggered.value; strURL = strURL + '&data_template_id=' + objForm.data_template_id.value; strURL = strURL + '&host_id=' + objForm.host_id.value; strURL = strURL + '&rows=' + objForm.rows.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Threshold Status</strong>", "100%", $colors["header"], "3", "center", ""); form_thold_filter(); html_end_box(); /* build the SQL query and WHERE clause */ if ($_REQUEST['sort_column'] == 'lastread') { $sort = $_REQUEST['sort_column'] . "/1"; } else { $sort = $_REQUEST['sort_column']; } $limit = ' LIMIT ' . $_REQUEST["rows"] * ($_REQUEST['page'] - 1) . "," . $_REQUEST["rows"]; $sql_where = ''; /* triggered filter */ if ($_REQUEST['triggered'] == '-1') { /* return all rows */ } else { if ($_REQUEST['triggered'] == '0') { $sql_where = "WHERE thold_data.thold_enabled='off'"; } /*disabled*/ if ($_REQUEST['triggered'] == '2') { $sql_where = "WHERE thold_data.thold_enabled='on'"; } /* enabled */ if ($_REQUEST['triggered'] == '1') { $sql_where = "WHERE (thold_data.thold_alert!=0 OR thold_data.bl_alert>0)"; } /* breached */ if ($_REQUEST['triggered'] == '3') { $sql_where = "WHERE ((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))"; } /* triggered */ } if (strlen($_REQUEST["filter"])) { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " thold_data.name LIKE '%%" . $_REQUEST["filter"] . "%%'"; } /* data template id filter */ if ($_REQUEST['data_template_id'] != '-1') { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " thold_data.data_template=" . $_REQUEST['data_template_id']; } /* host id filter */ if ($_REQUEST['host_id'] != '-1') { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " thold_data.host_id=" . $_REQUEST['host_id']; } /* thold permissions */ $current_user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']); $sql_where .= (strlen($sql_where) ? " AND " : "WHERE ") . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']); $total_rows_sql = "SELECT * FROM thold_data\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON ((thold_data.graph_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=1\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.host_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.graph_template=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=4\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}"; $total_rows = sizeof(db_fetch_assoc($total_rows_sql)); /* get the thold records */ $sql = "SELECT * FROM thold_data\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON ((thold_data.graph_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=1\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.host_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.graph_template=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=4\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}\r\n\t\tORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit; $result = db_fetch_assoc($sql); html_start_box('', '100%', $colors['header'], '4', 'center', ''); if ($total_rows) { /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["rows"], $total_rows, "thold_graph.php?tab=thold"); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='13'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("thold_graph.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"] - 1)) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Rows " . ($_REQUEST["rows"] * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < $_REQUEST["rows"] * $_REQUEST["page"] ? $total_rows : $_REQUEST["rows"] * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>"; if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("thold_graph.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"] + 1)) . "'>"; } $nav .= "Next"; if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n"; } else { $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='13'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tNo Rows Found\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n"; } print $nav; $display_text = array('nosort' => array('Actions', ''), 'name' => array('Name', 'ASC'), 'id' => array('ID', 'ASC'), 'thold_type' => array('Type', 'ASC'), 'nosort2' => array('Trigger', 'ASC'), 'nosort3' => array('Duration', 'ASC'), 'repeat_alert' => array('Repeat', 'ASC'), 'nosort4' => array('Warn Hi/Lo', 'ASC'), 'nosort5' => array('Alert Hi/Lo', 'ASC'), 'nosort6' => array('BL Hi/Lo', 'ASC'), 'lastread' => array('Current', 'ASC'), 'thold_alert' => array('Triggered', 'ASC'), 'thold_enabled' => array('Enabled', 'ASC')); html_header_sort($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction']); $timearray = array(1 => '5 Minutes', 2 => '10 Minutes', 3 => '15 Minutes', 4 => '20 Minutes', 6 => '30 Minutes', 8 => '45 Minutes', 12 => 'Hour', 24 => '2 Hours', 36 => '3 Hours', 48 => '4 Hours', 72 => '6 Hours', 96 => '8 Hours', 144 => '12 Hours', 288 => '1 Day', 576 => '2 Days', 2016 => '1 Week', 4032 => '2 Weeks', 8640 => '1 Month'); $c = 0; $i = 0; $types = array('High/Low', 'Baseline Deviation', 'Time Based'); if (count($result)) { foreach ($result as $row) { $c++; $alertstat = 'no'; $bgcolor = 'green'; if ($row['thold_type'] == 0) { if ($row['thold_alert'] != 0) { $alertstat = 'yes'; if ($row['thold_fail_count'] >= $row['thold_fail_trigger']) { $bgcolor = 'red'; } elseif ($row['thold_warning_fail_count'] >= $row['thold_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } elseif ($row['thold_type'] == 2) { if ($row['thold_alert'] != 0) { $alertstat = 'yes'; if ($row['thold_fail_count'] >= $row['time_fail_trigger']) { $bgcolor = 'red'; } elseif ($row['thold_warning_fail_count'] >= $row['time_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } else { if ($row['bl_alert'] == 1) { $alertstat = 'baseline-LOW'; $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow'; } elseif ($row['bl_alert'] == 2) { $alertstat = 'baseline-HIGH'; $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow'; } } if ($row['thold_enabled'] == 'off') { form_alternate_row_color($thold_bgcolors['grey'], $thold_bgcolors['grey'], $i, 'line' . $row["id"]); $i++; } else { form_alternate_row_color($thold_bgcolors[$bgcolor], $thold_bgcolors[$bgcolor], $i, 'line' . $row["id"]); $i++; } print "<td width='1%' style='white-space:nowrap;' nowrap>"; if (api_user_realm_auth('thold_add.php')) { print '<a href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold.php?rra=' . $row["rra_id"] . '&view_rrd=' . $row["data_id"]) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/edit_object.png" border="0" alt="" title="Edit Threshold"></a>'; } if ($row["thold_enabled"] == 'on') { print '<a href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold.php?id=' . $row["id"] . '&action=disable') . '"><img src="' . $config['url_path'] . 'plugins/thold/images/disable_thold.png" border="0" alt="" title="Disable Threshold"></a>'; } else { print '<a href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold.php?id=' . $row["id"] . '&action=enable') . '"><img src="' . $config['url_path'] . 'plugins/thold/images/enable_thold.png" border="0" alt="" title="Enable Threshold"></a>'; } print "<a href='" . htmlspecialchars($config['url_path'] . "graph.php?local_graph_id=" . $row['graph_id'] . "&rra_id=all") . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_graphs.gif' border='0' alt='' title='View Graph'></a>"; print "<a href='" . htmlspecialchars($config['url_path'] . "plugins/thold/thold_graph.php?tab=log&threshold_id=" . $row["id"] . "&status=-1") . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_log.gif' border='0' alt='' title='View Threshold History'></a>"; print "</td>"; print "<td width='28%'>" . ($row['name'] != '' ? $row['name'] : 'No name set') . "</td>"; print "<td width='10'>" . $row["id"] . "</td>"; print "<td nowrap style='white-space:nowrap;' width='120'>" . $types[$row['thold_type']] . "</td>"; switch ($row['thold_type']) { case 0: print "<td nowrap style='white-space:nowrap;' width='80'><i>" . plugin_thold_duration_convert($row['rra_id'], $row['thold_fail_trigger'], 'alert') . "</i></td>"; print "<td width='80'>N/A</td>"; break; case 1: print "<td nowrap style='white-space:nowrap;' width='80'><i>" . plugin_thold_duration_convert($row['rra_id'], $row['bl_fail_trigger'], 'alert') . "</i></td>"; print "<td nowrap style='white-space:nowrap;' width='80'>" . $timearray[$row['bl_ref_time_range'] / 300] . "</td>"; break; case 2: print "<td nowrap style='white-space:nowrap;' width='80'><i>" . $row['time_fail_trigger'] . " Triggers</i></td>"; print "<td nowrap style='white-space:nowrap;' width='80'>" . plugin_thold_duration_convert($row['rra_id'], $row['time_fail_length'], 'time') . "</td>"; break; default: print "<td width='80'>N/A</td>"; print "<td width='80'>N/A</td>"; } print "<td nowrap style='white-space:nowrap;' width='80'>" . ($row['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($row['rra_id'], $row['repeat_alert'], 'repeat')) . "</td>"; print "<td nowrap style='white-space:nowrap;' width='80'>" . ($row['thold_type'] == 1 ? "N/A" : ($row['thold_type'] == 2 ? thold_format_number($row['time_warning_hi']) . '/' . thold_format_number($row['time_warning_low']) : thold_format_number($row['thold_warning_hi']) . '/' . thold_format_number($row['thold_warning_low']))) . "</td>"; print "<td width='80'>" . ($row['thold_type'] == 1 ? "N/A" : ($row['thold_type'] == 2 ? thold_format_number($row['time_hi']) . '/' . thold_format_number($row['time_low']) : thold_format_number($row['thold_hi']) . '/' . thold_format_number($row['thold_low']))) . "</td>"; print "<td width='80'>" . ($row['thold_type'] == 1 ? $row['bl_pct_up'] . (strlen($row['bl_pct_up']) ? '%' : '-') . '/' . $row['bl_pct_down'] . (strlen($row['bl_pct_down']) ? '%' : '-') : 'N/A') . "</td>"; print "<td width='80'>" . thold_format_number($row['lastread']) . "</td>"; print "<td width='80'>" . ($row['thold_alert'] ? "yes" : "no") . "</td>"; if ($row['thold_enabled'] == 'off') { print "<td width='40'><b>Disabled</b></td>"; } else { print "<td width='40'>Enabled</td>"; } form_end_row(); } } else { form_alternate_row_color($colors['alternate'], $colors['light'], 0); print '<td colspan=12><center>No Thresholds</center></td></tr>'; } print $nav; html_end_box(false); thold_legend(); //thold_display_rusage(); }
function list_tholds() { global $colors, $thold_bgcolors, $config, $hostid; $thold_actions = array(1 => 'Delete', 2 => 'Disable', 3 => 'Enable', 4 => 'Reapply Suggested Names'); thold_request_validation(); $statefilter = ''; if (isset($_REQUEST['state'])) { if ($_REQUEST['state'] == '-1') { $statefilter = ''; } else { if ($_REQUEST['state'] == '0') { $statefilter = "thold_data.thold_enabled='off'"; } if ($_REQUEST['state'] == '2') { $statefilter = "thold_data.thold_enabled='on'"; } if ($_REQUEST['state'] == '1') { $statefilter = '(thold_data.thold_alert!=0 OR thold_data.bl_alert>0)'; } if ($_REQUEST['state'] == '3') { $statefilter = '((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))'; } } } $alert_num_rows = read_config_option('alert_num_rows'); if ($alert_num_rows < 1 || $alert_num_rows > 999) { db_execute("REPLACE INTO settings VALUES ('alert_num_rows', 30)"); /* pull it again so it updates the cache */ $alert_num_rows = read_config_option('alert_num_rows', true); } include $config['include_path'] . '/top_header.php'; $sql_where = ''; $sort = $_REQUEST['sort_column']; $limit = ' LIMIT ' . $alert_num_rows * ($_REQUEST['page'] - 1) . ",{$alert_num_rows}"; if (!empty($_REQUEST['hostid']) && $_REQUEST['hostid'] != 'ALL') { $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.host_id = " . $_REQUEST['hostid']; } if (!empty($_REQUEST['template']) && $_REQUEST['template'] != 'ALL') { $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.data_template = " . $_REQUEST['template']; } if ($statefilter != '') { $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "{$statefilter}"; } /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $sql = "\r\n SELECT thold_data.* FROM thold_data\r\n INNER JOIN user_auth_perms ON thold_data.host_id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n {$sql_where}\r\n ORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit; } else { $current_user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']); $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']); $sql = "SELECT * FROM thold_data\r\n\t\tLEFT JOIN user_auth_perms on ((thold_data.graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") OR (thold_data.host_id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") OR (thold_data.graph_template=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}\r\n\t\tORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit; } /* modify for multi user end */ $result = db_fetch_assoc($sql); /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $hostresult = db_fetch_assoc("\r\n SELECT host.id, host.description, host.hostname FROM host \r\n INNER JOIN thold_data ON host.id = thold_data.host_id \r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'"); $data_templates = db_fetch_assoc("\r\n SELECT DISTINCT data_template.id, data_template.name FROM data_template\r\n INNER JOIN thold_data ON thold_data.data_template = data_template.id\r\n INNER JOIN host ON thold_data.host_id = host.id\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n ORDER BY data_template.name"); } else { $sql_where_hid = 'WHERE ' . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']); $hostresult = db_fetch_assoc("SELECT DISTINCT host.id, host.description, host.hostname\r\n\t\tFROM host\r\n\t\tINNER JOIN thold_data ON (host.id = thold_data.host_id)\r\n\t\tLEFT JOIN user_auth_perms on (thold_data.host_id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\t{$sql_where_hid}\r\n\t\tORDER BY description"); $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\r\n\t\tFROM data_template\r\n\t\tINNER JOIN thold_data ON (thold_data.data_template = data_template.id)\r\n\t\tORDER BY data_template.name"); } /* modify for multi user end */ ?> <script type="text/javascript"> <!-- function applyTHoldFilterChange(objForm) { strURL = '?hostid=' + objForm.hostid.value; strURL = strURL + '&state=' + objForm.state.value; strURL = strURL + '&template=' + objForm.template.value; document.location = strURL; } --> </script> <?php /* modify for multi user start */ if (check_resource_count(RESOURCE_THOLD) == TRUE) { html_start_box('<strong>Threshold Management</strong>', '100%', $colors['header'], '3', 'center', 'thold_add.php'); } else { html_start_box('<strong>Threshold Management</strong>', '100%', $colors['header'], '3', 'center', ''); } /* modify for multi user end */ ?> <tr bgcolor='#<?php print $colors["panel"]; ?> ' class='noprint'> <td class='noprint'> <form name='listthold' action='listthold.php' method='post'> <table cellpadding='0' cellspacing='0'> <tr class='noprint'> <td width='1'> Host: </td> <td width='1'> <select name='hostid' onChange='applyTHoldFilterChange(document.listthold)'> <option value='ALL'>Any</option> <?php foreach ($hostresult as $row) { echo "<option value='" . $row['id'] . "'" . (isset($_REQUEST['hostid']) && $row['id'] == $_REQUEST['hostid'] ? ' selected' : '') . '>' . $row['description'] . ' - (' . $row['hostname'] . ')' . '</option>'; } ?> </select> </td> <td width='1'> Template: </td> <td width='1'> <select name='template' onChange='applyTHoldFilterChange(document.listthold)'> <option value='ALL'>Any</option> <?php foreach ($data_templates as $row) { echo "<option value='" . $row['id'] . "'" . (isset($_REQUEST['template']) && $row['id'] == $_REQUEST['template'] ? ' selected' : '') . '>' . $row['name'] . '</option>'; } ?> </select> </td> <td width='1'> State: </td> <td width='1'> <select name='state' onChange='applyTHoldFilterChange(document.listthold)'> <option value='-1'<?php if ($_REQUEST["state"] == "-1") { ?> selected<?php } ?> >All</option> <option value='1'<?php if ($_REQUEST["state"] == "1") { ?> selected<?php } ?> >Breached</option> <option value='3'<?php if ($_REQUEST["state"] == "3") { ?> selected<?php } ?> >Triggered</option> <option value='2'<?php if ($_REQUEST["state"] == "2") { ?> selected<?php } ?> >Enabled</option> <option value='0'<?php if ($_REQUEST["state"] == "0") { ?> selected<?php } ?> >Disabled</option> </select> </td> <td nowrap style='white-space: nowrap;'> <input type='submit' name='clear' value='Clear' title='Return to Defaults'> </td> </tr> </table> <input type='hidden' name='search' value='search'> </form> </td> </tr> <?php html_end_box(); define('MAX_DISPLAY_PAGES', 21); /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $total_rows = db_fetch_cell("\r\n SELECT COUNT(thold_data.id) FROM thold_data\r\n INNER JOIN user_auth_perms ON thold_data.host_id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n {$sql_where}"); } else { $total_rows = count(db_fetch_assoc("SELECT thold_data.id\r\n\t\tFROM thold_data\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON ((thold_data.graph_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=1\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.host_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.graph_template=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=4\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}")); } /* modify for multi user end */ $url_page_select = get_page_list($_REQUEST['page'], MAX_DISPLAY_PAGES, $alert_num_rows, $total_rows, 'listthold.php?'); /* print checkbox form for validation */ print "<form name='chk' method='post' action='listthold.php'>\n"; html_start_box('', '100%', $colors['header'], '4', 'center', ''); if ($total_rows) { $nav = "<tr bgcolor='#" . $colors['header'] . "'>\r\n\t\t\t\t<td colspan='12'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("listthold.php?page=" . ($_REQUEST["page"] - 1)) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Rows " . ($alert_num_rows * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < $alert_num_rows || $total_rows < $alert_num_rows * $_REQUEST["page"] ? $total_rows : $alert_num_rows * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>"; if ($_REQUEST["page"] * $alert_num_rows < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("listthold.php?page=" . ($_REQUEST["page"] + 1)) . "'>"; } $nav .= "Next"; if ($_REQUEST["page"] * $alert_num_rows < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n"; } else { $nav = "<tr bgcolor='#" . $colors['header'] . "'>\r\n\t\t\t\t<td colspan='12'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tNo Rows Found\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n"; } print $nav; $display_text = array('name' => array('Name', 'ASC'), 'thold_type' => array('Type', 'ASC'), 'thold_hi' => array('High', 'ASC'), 'thold_low' => array('Low', 'ASC'), 'nosort3' => array('Trigger', ''), 'nosort4' => array('Duration', ''), 'repeat_alert' => array('Repeat', 'ASC'), 'lastread' => array('Current', 'ASC'), 'thold_alert' => array('Triggered', 'ASC'), 'thold_enabled' => array('Enabled', 'ASC')); html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false); $timearray = array(1 => '5 Minutes', 2 => '10 Minutes', 3 => '15 Minutes', 4 => '20 Minutes', 6 => '30 Minutes', 8 => '45 Minutes', 12 => 'Hour', 24 => '2 Hours', 36 => '3 Hours', 48 => '4 Hours', 72 => '6 Hours', 96 => '8 Hours', 144 => '12 Hours', 288 => '1 Day', 576 => '2 Days', 2016 => '1 Week', 4032 => '2 Weeks', 8640 => '1 Month'); $c = 0; $i = 0; $types = array('High/Low', 'Baseline Deviation', 'Time Based'); if (count($result)) { foreach ($result as $row) { $c++; $grapharr = db_fetch_row('SELECT DISTINCT graph_templates_item.local_graph_id FROM graph_templates_item, data_template_rrd WHERE (data_template_rrd.local_data_id=' . $row['rra_id'] . ' AND data_template_rrd.id=graph_templates_item.task_item_id)'); $graph_id = $grapharr['local_graph_id']; $alertstat = 'no'; $bgcolor = 'green'; if ($row['thold_type'] == 0) { if ($row['thold_alert'] != 0) { $alertstat = 'yes'; if ($row['thold_fail_count'] >= $row['thold_fail_trigger']) { $bgcolor = 'red'; } elseif ($row['thold_warning_fail_count'] >= $row['thold_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } elseif ($row['thold_type'] == 2) { if ($row['thold_alert'] != 0) { $alertstat = 'yes'; if ($row['thold_fail_count'] >= $row['time_fail_trigger']) { $bgcolor = 'red'; } elseif ($row['thold_warning_fail_count'] >= $row['time_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } else { if ($row['bl_alert'] == 1) { $alertstat = 'baseline-LOW'; $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow'; } elseif ($row['bl_alert'] == 2) { $alertstat = 'baseline-HIGH'; $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow'; } } if ($row['thold_enabled'] == 'off') { form_alternate_row_color($thold_bgcolors['grey'], $thold_bgcolors['grey'], $i, 'line' . $row["id"]); $i++; } else { form_alternate_row_color($thold_bgcolors[$bgcolor], $thold_bgcolors[$bgcolor], $i, 'line' . $row["id"]); $i++; } form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("thold.php?rra=" . $row['rra_id'] . "&view_rrd=" . $row['data_id']) . "'>" . ($row['name'] != '' ? $row['name'] : $row['name_cache'] . " [" . $row['data_source_name'] . ']') . '</a>', $row['id']); form_selectable_cell($types[$row['thold_type']], $row["id"]); switch ($row['thold_type']) { case 0: form_selectable_cell(thold_format_number($row['thold_hi']), $row["id"]); form_selectable_cell(thold_format_number($row['thold_low']), $row["id"]); form_selectable_cell("<i>" . plugin_thold_duration_convert($row['rra_id'], $row['thold_fail_trigger'], 'alert') . "</i>", $row["id"]); form_selectable_cell("", $row["id"]); break; case 1: form_selectable_cell(thold_format_number($row['thold_hi']), $row["id"]); form_selectable_cell(thold_format_number($row['thold_low']), $row["id"]); form_selectable_cell("<i>" . plugin_thold_duration_convert($row['rra_id'], $row['bl_fail_trigger'], 'alert') . "</i>", $row["id"]); form_selectable_cell($timearray[$row['bl_ref_time_range'] / 300], $row["id"]); break; case 2: form_selectable_cell(thold_format_number($row['time_hi']), $row["id"]); form_selectable_cell(thold_format_number($row['time_low']), $row["id"]); form_selectable_cell("<i>" . $row['time_fail_trigger'] . " Triggers</i>", $row["id"]); form_selectable_cell(plugin_thold_duration_convert($row['rra_id'], $row['time_fail_length'], 'time'), $row["id"]); break; default: form_selectable_cell("", $row["id"]); form_selectable_cell("", $row["id"]); form_selectable_cell("", $row["id"]); form_selectable_cell("", $row["id"]); } form_selectable_cell($row['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($row['rra_id'], $row['repeat_alert'], 'repeat'), $row["id"]); form_selectable_cell(thold_format_number($row['lastread']), $row["id"]); form_selectable_cell($alertstat, $row["id"]); form_selectable_cell($row['thold_enabled'] == 'off' ? "Disabled" : "Enabled", $row["id"]); form_checkbox_cell($row['name'], $row['id']); form_end_row(); } } else { form_alternate_row_color($colors['alternate'], $colors['light'], 0); print '<td colspan=12><center>No Thresholds</center></td></tr>'; } print $nav; html_end_box(false); thold_legend(); draw_actions_dropdown($thold_actions); if (isset($hostid) && $hostid != '') { print "<input type=hidden name=hostid value={$hostid}>"; } print "</form>\n"; include_once $config['include_path'] . '/bottom_footer.php'; }