function tholds($header_label) { global $colors, $thold_bgcolors, $item_rows, $config; $thold_actions = array(1 => 'Associate', 2 => 'Disassociate'); 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 > 5000) { 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); } $sql_where = "WHERE template_enabled='off'"; $sort = $_REQUEST['sort_column']; $limit = ' LIMIT ' . $alert_num_rows * ($_REQUEST['page'] - 1) . ",{$alert_num_rows}"; if (!empty($_REQUEST['template']) && $_REQUEST['template'] != 'ALL') { $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.data_template = " . $_REQUEST['template']; } if (strlen($_REQUEST['filter'])) { $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.name LIKE '%" . $_REQUEST['filter'] . "%'"; } if ($statefilter != '') { $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "{$statefilter}"; } if ($_REQUEST["associated"] == 'true') { $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "(notify_warning=" . get_request_var_request('id') . " OR notify_alert=" . get_request_var_request('id') . ")"; } $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\n\t\tLEFT JOIN user_auth_perms \n\t\tON ((thold_data.graph_id=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=1 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") \n\t\tOR (thold_data.host_id=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=3 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") \n\t\tOR (thold_data.graph_template=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=4 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\n\t\t{$sql_where}\n\t\tORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit; $result = db_fetch_assoc($sql); $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\tFROM data_template\n\t\tINNER JOIN thold_data ON (thold_data.data_template = data_template.id)\n\t\tORDER BY data_template.name"); ?> <script type="text/javascript"> <!-- function applyTHoldFilterChange(objForm) { strURL = '?action=edit&tab=tholds&id=<?php print get_request_var_request('id'); ?> ' strURL = strURL + '&associated=' + objForm.associated.checked; strURL = strURL + '&state=' + objForm.state.value; strURL = strURL + '&rows=' + objForm.rows.value; strURL = strURL + '&template=' + objForm.template.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } function clearTHoldFilterChange(objForm) { strURL = '?action=edit&tab=tholds&id=<?php print get_request_var_request('id'); ?> &clearf=true' document.location = strURL; } --> </script> <?php html_start_box('<strong>Associated Thresholds</strong> ' . htmlspecialchars($header_label), '100%', $colors['header'], '3', 'center', ''); ?> <tr bgcolor='#<?php print $colors["panel"]; ?> ' class='noprint'> <td class='noprint'> <form name="listthold" method="get" action="notify_lists.php"> <table cellpadding='0' cellspacing='0'> <tr class='noprint'> <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 nowrap style='white-space: nowrap;' width="20"> Search: </td> <td width="1"> <input type="text" name="filter" size="20" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> " onChange="applyTHoldFilterChange(document.listthold)"> </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;' width="50"> Rows: </td> <td width="1"> <select name="rows" onChange="applyTHoldFilterChange(document.listthold)"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type='checkbox' name='associated' id='associated' onChange='applyTHoldFilterChange(document.listthold)' <?php print $_REQUEST['associated'] == 'true' || $_REQUEST['associated'] == 'on' ? 'checked' : ''; ?> > </td> <td> <label for='associated'>Associated</label> </td> <td nowrap> <input type="button" value="Go" onClick='applyTHoldFilterChange(document.listthold)' title="Set/Refresh Filters"> </td> <td nowrap> <input type="button" name="clearf" value="Clear" onClick='clearTHoldFilterChange(document.listthold)' title="Clear Filters"> </td> </tr> </table> <input type='hidden' name='page' value='1'> <input type='hidden' name='action' value='edit'> <input type='hidden' name='tab' value='tholds'> <input type='hidden' name='id' value='<?php print get_request_var_request('id'); ?> '> </form> </td> </tr> <?php html_end_box(); $total_rows = count(db_fetch_assoc("SELECT thold_data.id \n\t\tFROM thold_data\n\t\tLEFT JOIN user_auth_perms \n\t\tON ((thold_data.graph_id=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=1 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") \n\t\tOR (thold_data.host_id=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=3 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") \n\t\tOR (thold_data.graph_template=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=4 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\n\t\t{$sql_where}")); $url_page_select = get_page_list($_REQUEST['page'], MAX_DISPLAY_PAGES, $alert_num_rows, $total_rows, 'notify_lists.php?action=edit&tab=tholds'); /* print checkbox form for validation */ print "<form name='chk' method='post' action='notify_lists.php'>\n"; html_start_box('', '100%', $colors['header'], '4', 'center', ''); if ($total_rows) { $nav = "<tr bgcolor='#" . $colors['header'] . "'>\n\t\t\t\t<td colspan='8'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("notify_lists.php?page=" . ($_REQUEST["page"] - 1)) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\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}]\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t<strong>"; if ($_REQUEST["page"] * $alert_num_rows < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("notify_lists.php?page=" . ($_REQUEST["page"] + 1)) . "'>"; } $nav .= "Next"; if ($_REQUEST["page"] * $alert_num_rows < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n"; } else { $nav = "<tr bgcolor='#" . $colors['header'] . "'>\n\t\t\t\t<td colspan='8'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\tNo Rows Found\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n"; } print $nav; $display_text = array('name' => array('Name', 'ASC'), 'id' => array('ID', 'ASC'), 'nosort1' => array('Warning Lists', 'ASC'), 'nosort2' => array('Alert Lists', 'ASC'), 'thold_type' => array('Type', 'ASC'), 'thold_alert' => array('Triggered', 'ASC'), 'thold_enabled' => array('Enabled', 'ASC')); html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false); $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'] != 1) { if ($row['thold_alert'] != 0) { $alertstat = 'yes'; } } else { if ($row['bl_alert'] == 1) { $alertstat = 'baseline-LOW'; } elseif ($row['bl_alert'] == 2) { $alertstat = 'baseline-HIGH'; } } /* show alert stats first */ $alert_stat = ''; $list = db_fetch_cell("SELECT count(*) FROM plugin_thold_threshold_contact WHERE thold_id=" . $row["id"]); if ($list > 0) { $alert_stat = "<span style='font-weight:bold;color:green;'>Select Users</span>"; } if (strlen($row["notify_extra"])) { $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:purple;'>Specific Emails</span>"; } if (!empty($row["notify_alert"])) { if (get_request_var_request('id') == $row["notify_alert"]) { $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:green;'>Current List</span>"; } else { $alert_list = db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . $row["notify_alert"]); $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:red;'>" . $alert_list . "</span>"; } } if (!strlen($alert_stat)) { $alert_stat = "<span style='font-weight:bold;color:blue;'>Log Only</span>"; } /* show warning stats first */ $warn_stat = ''; if (strlen($row["notify_warning_extra"])) { $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:purple;'>Specific Emails</span>"; } if (!empty($row["notify_warning"])) { if (get_request_var_request('id') == $row["notify_warning"]) { $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:green;'>Current List</span>"; } else { $warn_list = db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . $row["notify_warning"]); $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:red;'>" . $warn_list . "</span>"; } } if (!strlen($warn_stat) && ($row["thold_type"] == 0 && $row["thold_warning_hi"] == '' && $row["thold_warning_low"] == '' || $row["thold_type"] == 2 && $row["time_warning_hi"] == '' && $row["time_warning_low"] == '')) { $warn_stat = "<span style='font-weight:bold;color:red;'>None</span>"; } elseif (!strlen($warn_stat)) { $warn_stat = "<span style='font-weight:bold;color:blue;'>Log Only</span>"; } if ($row['name'] != '') { $name = $row['name']; } else { $name = $row['name_cache'] . " [" . $row['data_source_name'] . "]"; } form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $row["id"]); $i++; form_selectable_cell(strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($name)) : htmlspecialchars($name), $row['id']); form_selectable_cell($row['id'], $row["id"]); form_selectable_cell($warn_stat, $row["id"]); form_selectable_cell($alert_stat, $row["id"]); form_selectable_cell($types[$row['thold_type']], $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(); } print $nav; } else { form_alternate_row_color($colors['alternate'], $colors['light'], 0); print '<td colspan="8"><i>No Thresholds</i></td></tr>'; } html_end_box(false); form_hidden_box("action", "edit", ""); form_hidden_box("tab", "tholds", ""); form_hidden_box("id", get_request_var_request("id"), ""); form_hidden_box("save_tholds", "1", ""); draw_actions_dropdown($thold_actions); print "</form>\n"; }
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($header_label) { global $item_rows, $config; include $config['base_path'] . '/plugins/thold/includes/arrays.php'; $thold_actions = array(1 => __('Associate'), 2 => __('Disassociate')); thold_request_validation(); $statefilter = ''; if (isset_request_var('state')) { if (get_request_var('state') == '-1') { $statefilter = ''; } else { if (get_request_var('state') == '0') { $statefilter = "td.thold_enabled='off'"; } if (get_request_var('state') == '2') { $statefilter = "td.thold_enabled='on'"; } if (get_request_var('state') == '1') { $statefilter = '(td.thold_alert!=0 OR td.bl_alert>0)'; } if (get_request_var('state') == '3') { $statefilter = '(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)'; } } } /* 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'); } $sql_where = ''; $sort = get_request_var('sort_column') . ' ' . get_request_var('sort_direction'); $limit = $rows * (get_request_var('page') - 1) . ", {$rows}"; if (!isempty_request_var('template') && get_request_var('template') != '-1') { $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . 'td.data_template_id = ' . get_request_var('template'); } if (strlen(get_request_var('filter'))) { $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . "td.name LIKE '%" . get_request_var('filter') . "%'"; } if ($statefilter != '') { $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . $statefilter; } if (get_request_var('associated') == 'true') { $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . '(td.notify_warning=' . get_request_var('id') . ' OR td.notify_alert=' . get_request_var('id') . ')'; } cacti_log($sql_where); $result = get_allowed_thresholds($sql_where, $sort, $limit, $total_rows); $data_templates = db_fetch_assoc('SELECT DISTINCT dt.id, dt.name FROM data_template AS dt INNER JOIN thold_data AS td ON td.data_template_id = dt.id ORDER BY dt.name'); html_start_box(__('Associated Thresholds') . ' ' . htmlspecialchars($header_label), '100%', '', '3', 'center', ''); ?> <tr class='even'> <td> <form id='listthold' method='get' action='notify_lists.php'> <table class='filterTable'> <tr> <td> <?php print __('Search'); ?> </td> <td> <input type='text' id='filter' size='25' value='<?php print htmlspecialchars(get_request_var('filter')); ?> ' onChange='applyFilter()'> </td> <td> <?php print __('Template'); ?> </td> <td> <select id='template' onChange='applyFilter()'> <option value='-1'><?php print __('Any'); ?> </option> <?php foreach ($data_templates as $row) { echo "<option value='" . $row['id'] . "'" . (isset_request_var('template') && $row['id'] == get_request_var('template') ? ' 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> <?php print __('Thresholds'); ?> </td> <td> <select id='rows' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('rows') == '-1') { ?> selected<?php } ?> ><?php print __('Default'); ?> </option> <?php if (sizeof($item_rows)) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type='checkbox' id='associated' onChange='applyFilter()' <?php print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : ''; ?> > </td> <td> <label for='associated'><?php print __('Associated'); ?> </label> </td> <td> <input type='button' value='<?php print __('Go'); ?> ' onClick='applyFilter()' title='<?php print __('Set/Refresh Filters'); ?> '> </td> <td> <input type='button' name='clearf' value='<?php print __('Clear'); ?> ' onClick='clearFilter()' title='<?php print __('Clear Filters'); ?> '> </td> </tr> </table> <input type='hidden' id='page' value='<?php print get_filter_request_var('page'); ?> '> <input type='hidden' id='tab' value='tholds'> <input type='hidden' id='id' value='<?php print get_request_var('id'); ?> '> </form> <script type='text/javascript'> function applyFilter() { strURL = 'notify_lists.php?header=false&action=edit&tab=tholds&id=<?php print get_request_var('id'); ?> ' strURL += '&associated=' + $('#associated').is(':checked');; strURL += '&state=' + $('#state').val(); strURL += '&rows=' + $('#rows').val(); strURL += '&template=' + $('#template').val(); strURL += '&filter=' + $('#filter').val(); loadPageNoHeader(strURL); } function clearFilter() { strURL = 'notify_lists.php?header=false&action=edit&tab=tholds&id=<?php print get_request_var('id'); ?> &clearf=true' loadPageNoHeader(strURL); } $(function() { $('#listthold').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); $nav = html_nav_bar('notify_lists.php?action=edit&tab=tholds', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Thresholds'), 'page', 'main'); form_start('notify_lists.php', 'chk'); print $nav; html_start_box('', '100%', '', '4', 'center', ''); $display_text = array('name' => array(__('Name'), 'ASC'), 'id' => array(__('ID'), 'ASC'), 'nosort1' => array(__('Warning Lists'), 'ASC'), 'nosort2' => array(__('Alert Lists'), 'ASC'), 'thold_type' => array(__('Type'), 'ASC'), 'thold_alert' => array(__('Triggered'), 'ASC'), 'thold_enabled' => array(__('Enabled'), 'ASC')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'notify_lists.php?action=edit&tab=tholds&id=' . get_filter_request_var('id')); $c = 0; $i = 0; if (count($result)) { foreach ($result as $row) { $c++; $alertstat = 'no'; $bgcolor = 'green'; if ($row['thold_type'] != 1) { if ($row['thold_alert'] != 0) { $alertstat = 'yes'; } } else { if ($row['bl_alert'] == 1) { $alertstat = 'baseline-LOW'; } elseif ($row['bl_alert'] == 2) { $alertstat = 'baseline-HIGH'; } } /* show alert stats first */ $alert_stat = ''; $list = db_fetch_cell('SELECT count(*) FROM plugin_thold_threshold_contact WHERE thold_id=' . $row['id']); if ($list > 0) { $alert_stat = "<span style='font-weight:bold;color:green;'>" . __('Select Users') . "</span>"; } if (strlen($row['notify_extra'])) { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>"; } if (!empty($row['notify_alert'])) { if (get_request_var('id') == $row['notify_alert']) { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>"; } else { $alert_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_alert']); $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $alert_list . '</span>'; } } if (!strlen($alert_stat)) { $alert_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>"; } /* show warning stats first */ $warn_stat = ''; if (strlen($row['notify_warning_extra'])) { $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>"; } if (!empty($row['notify_warning'])) { if (get_request_var('id') == $row['notify_warning']) { $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>"; } else { $warn_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_warning']); $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $warn_list . '</span>'; } } if (!strlen($warn_stat) && ($row['thold_type'] == 0 && $row['thold_warning_hi'] == '' && $row['thold_warning_low'] == '' || $row['thold_type'] == 2 && $row['time_warning_hi'] == '' && $row['time_warning_low'] == '')) { $warn_stat = "<span style='font-weight:bold;color:red;'>" . __('None') . "</span>"; } elseif (!strlen($warn_stat)) { $warn_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>"; } if ($row['name'] != '') { $name = $row['name']; } else { $name = $row['name_cache'] . ' [' . $row['data_source_name'] . ']'; } form_alternate_row('line' . $row['id'], true); form_selectable_cell(filter_value($name, get_request_var('filter')), $row['id']); form_selectable_cell($row['id'], $row['id']); form_selectable_cell($warn_stat, $row['id']); form_selectable_cell($alert_stat, $row['id']); form_selectable_cell($thold_types[$row['thold_type']], $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 { print "<tr class='even' <td colspan='8'><i>" . __('No Thresholds') . "</i></td></tr>\n"; } html_end_box(false); if (count($result)) { print $nav; } form_hidden_box('tab', 'tholds', ''); form_hidden_box('id', get_request_var('id'), ''); form_hidden_box('save_tholds', '1', ''); draw_actions_dropdown($thold_actions); form_end(); }
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'; }