} $item = db_fetch_assoc("SELECT * FROM thold_data WHERE data_id=" . $template_data_rrd["id"]); $item = count($item) > 0 ? $item[0] : $item; $cur_setting = ''; if (count($item) == 0) { $cur_setting .= "<span style='color:red;'>n/a</span>"; } else { $cur_setting = "Last: " . ($item["lastread"] == "" ? "<span style='color:red;'>n/a</span>" : "<span style='color:blue;'>" . thold_format_number($item["lastread"], 2) . "</span>"); if ($item["thold_type"] != 1) { $cur_setting .= " WHi: " . ($item["thold_warning_hi"] == "" ? "<span style='color:red;'>n/a</span>" : "<span style='color:green;'>" . thold_format_number($item["thold_warning_hi"], 2) . "</span>"); $cur_setting .= " WLo: " . ($item["thold_warning_low"] == "" ? "<span style='color:red;'>n/a</span>" : "<span style='color:green;'>" . thold_format_number($item["thold_warning_low"], 2) . "</span>"); $cur_setting .= " AHi: " . ($item["thold_hi"] == "" ? "<span style='color:red;'>n/a</span>" : "<span style='color:green;'>" . thold_format_number($item["thold_hi"], 2) . "</span>"); $cur_setting .= " ALo: " . ($item["thold_low"] == "" ? "<span style='color:red;'>n/a</span>" : "<span style='color:green;'>" . thold_format_number($item["thold_low"], 2) . "</span>"); } else { $cur_setting .= " AHi: " . ($item["thold_hi"] == "" ? "<span style='color:red;'>n/a</span>" : "<span style='color:green;'>" . thold_format_number($item["thold_hi"], 2) . "</span>"); $cur_setting .= " ALo: " . ($item["thold_low"] == "" ? "<span style='color:red;'>n/a</span>" : "<span style='color:green;'>" . thold_format_number($item["thold_low"], 2) . "</span>"); $cur_setting .= " BL: (Up " . $item["bl_pct_up"] . "%/Down " . $item["bl_pct_down"] . "%)"; } } $tab_len = max(strlen($cur_setting), strlen($template_data_rrd["data_source_name"])); $i++; echo "\t<td bgcolor=" . ($template_data_rrd["id"] == $_GET["view_rrd"] ? "'silver'" : "'#DFDFDF'"); echo " nowrap='nowrap' align='center' class='tab'>"; echo "<span class='textEditTitle'><a href='" . htmlspecialchars("thold.php?rra=" . $template_data_rrd["local_data_id"] . "&view_rrd=" . $template_data_rrd["id"]) . "'>{$i}: " . $template_data_rrd["data_source_name"] . "</a><br>"; echo "<span class='textEditTitle' style='white-space:nowrap;color:black;'>" . $cur_setting . "</span>"; echo "</span>\n</td>\n<td width='1'></td>\n"; unset($thold_item_data); } print "\r\n\t\t<td></td>\n\r\n\t\t</tr>\r\n\t\t</table>\n"; } elseif (sizeof($template_data_rrds) == 1) { $_GET["view_rrd"] = $template_data_rrds[0]["id"];
function templates() { global $colors, $thold_actions, $item_rows; template_request_validation(); ?> <script type="text/javascript"> <!-- function applyTHoldFilterChange(objForm) { strURL = '?rows=' + objForm.rows.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } function importTemplate() { strURL = '?action=import'; document.location = strURL; } --> </script> <?php html_start_box('<strong>Threshold Templates</strong>', '100%', $colors['header'], '3', 'center', 'thold_templates.php?action=add'); ?> <tr bgcolor='#<?php print $colors["panel"]; ?> ' class='noprint'> <td class='noprint'> <form name='listthold' action='thold_templates.php'> <table cellpadding='0' cellspacing='0'> <tr class='noprint'> <td width='20'> Search: </td> <td width='144'> <input type='text' name='filter' size='20' value='<?php print $_REQUEST["filter"]; ?> '> </td> <td width='1'> Rows: </td> <td width='1'> <select name='rows' onChange='applyTHoldFilterChange(document.listthold)'> <option value='-1'<?php if ($_REQUEST["rows"] == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows)) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if ($_REQUEST["rows"] == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> <td width='1'> <input type="submit" value="Go"> </td> <td width='1'> <input id="clear" name="clear" type="submit" value="Clear"> </td> <td width='1'> <input id="import" name="import" type="button" value="Import" onClick="importTemplate()"> </td> </tr> </table> </form> </td> </tr> <?php html_end_box(); $sql_where = ''; $limit = ' LIMIT ' . $_REQUEST["rows"] * ($_REQUEST['page'] - 1) . "," . $_REQUEST["rows"]; $order = "ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction']; if (strlen($_REQUEST["filter"])) { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " thold_template.name LIKE '%%" . $_REQUEST["filter"] . "%%'"; } define('MAX_DISPLAY_PAGES', 21); $total_rows = db_fetch_cell("SELECT count(*) FROM thold_template"); $template_list = db_fetch_assoc("SELECT * FROM thold_template {$sql_where} {$order} {$limit}"); if ($total_rows) { /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["rows"], $total_rows, "thold_templates.php?tab=thold"); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='10'>\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_templates.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_templates.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='10'>\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 checkbox form for validation */ print "<form name='chk' method='post' action='thold_templates.php'>\n"; html_start_box('', '100%', $colors['header'], '3', 'center', ''); print $nav; html_header_sort_checkbox(array('name' => array('Name', 'ASC'), 'data_template_name' => array('Data Template', 'ASC'), 'data_source_name' => array('DS Name', 'ASC'), 'thold_type' => array('Type', 'ASC'), 'nosort1' => array('High/Up', ''), 'nosort2' => array('Low/Down', ''), 'nosort3' => array('Trigger', ''), 'nosort4' => array('Duration', ''), 'nosort5' => array('Repeat', '')), $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false); $i = 0; $types = array('High/Low', 'Baseline Deviation', 'Time Based'); if (sizeof($template_list)) { foreach ($template_list as $template) { switch ($template['thold_type']) { case 0: # hi/lo $value_hi = thold_format_number($template['thold_hi']); $value_lo = thold_format_number($template['thold_low']); $value_trig = $template['thold_fail_trigger']; $value_duration = ''; $value_warning_hi = thold_format_number($template['thold_warning_hi']); $value_warning_lo = thold_format_number($template['thold_warning_low']); $value_warning_trig = $template['thold_warning_fail_trigger']; $value_warning_duration = ''; break; case 1: # baseline $value_hi = $template['bl_pct_up'] . (strlen($template['bl_pct_up']) ? '%' : '-'); $value_lo = $template['bl_pct_down'] . (strlen($template['bl_pct_down']) ? '%' : '-'); $value_trig = $template['bl_fail_trigger']; $step = db_fetch_cell("SELECT rrd_step \r\n\t\t\t\t\t\tFROM data_template_data \r\n\t\t\t\t\t\tWHERE data_template_id=" . $template['data_template_id'] . "\r\n\t\t\t\t\t\tLIMIT 1"); $value_duration = $template['bl_ref_time_range'] / $step; break; case 2: #time $value_hi = thold_format_number($template['time_hi']); $value_lo = thold_format_number($template['time_low']); $value_trig = $template['time_fail_trigger']; $value_duration = $template['time_fail_length']; break; } form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $template["id"]); $i++; form_selectable_cell('<a class="linkEditMain" href="' . htmlspecialchars('thold_templates.php?action=edit&id=' . $template['id']) . '">' . ($template['name'] == '' ? $template['data_template_name'] . ' [' . $template['data_source_name'] . ']' : $template['name']) . '</a>', $template["id"]); form_selectable_cell($template['data_template_name'], $template["id"]); form_selectable_cell($template['data_source_name'], $template["id"]); form_selectable_cell($types[$template['thold_type']], $template["id"]); form_selectable_cell($value_hi, $template["id"]); form_selectable_cell($value_lo, $template["id"]); $trigger = plugin_thold_duration_convert($template['data_template_id'], $value_trig, 'alert', 'data_template_id'); form_selectable_cell(strlen($trigger) ? "<i>" . $trigger . "</i>" : "-", $template["id"]); $duration = plugin_thold_duration_convert($template['data_template_id'], $value_duration, 'time', 'data_template_id'); form_selectable_cell(strlen($duration) ? $duration : "-", $template["id"]); form_selectable_cell(plugin_thold_duration_convert($template['data_template_id'], $template['repeat_alert'], 'repeat', 'data_template_id'), $template['id']); form_checkbox_cell($template['data_template_name'], $template["id"]); form_end_row(); } print $nav; } else { print "<tr><td><em>No Threshold Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($thold_actions); print "</form>\n"; }
function thold_show_log() { global $config, $item_rows, $thold_log_states, $thold_status, $thold_types, $thold_log_retention; $step = read_config_option('poller_interval'); /* ================= 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' => 'time', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'DESC', 'options' => array('options' => 'sanitize_search_string')), 'threshold_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_log'); /* ================= 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'); } $days = read_config_option('thold_log_storage'); if (isset($thold_log_retention[$days])) { $days = $thold_log_retention[$days]; } else { $days = __('%d Days', $days); } html_start_box(__('Threshold Log for [ %s ]', $days), '100%', '', '3', 'center', ''); form_thold_log_filter(); html_end_box(); $sql_where = ''; if (get_request_var('host_id') == '-1') { /* Show all items */ } elseif (get_request_var('host_id') == '0') { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' h.id IS NULL'; } elseif (!isempty_request_var('host_id')) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.host_id=' . get_request_var('host_id'); } if (get_request_var('threshold_id') == '-1') { /* Show all items */ } elseif (get_request_var('threshold_id') == '0') { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' td.id IS NULL'; } elseif (!isempty_request_var('threshold_id')) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.threshold_id=' . get_request_var('threshold_id'); } if (get_request_var('status') == '-1') { /* Show all items */ } else { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.status=' . get_request_var('status'); } if (strlen(get_request_var('filter'))) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . " tl.description LIKE '%" . get_request_var('filter') . "%'"; } $sortby = get_request_var('sort_column') . ' ' . get_request_var('sort_direction'); $limit = $rows * (get_request_var('page') - 1) . ',' . $rows; $logs = get_allowed_threshold_logs($sql_where, $sortby, $limit, $total_rows); $nav = html_nav_bar('thold_graph.php?action=log', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 8, __('Log Entries'), 'page', 'main'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('hdescription' => array('display' => __('Device'), 'sort' => 'ASC', 'align' => 'left'), 'time' => array('display' => __('Time'), 'sort' => 'ASC', 'align' => 'left'), 'type' => array('display' => __('Type'), 'sort' => 'DESC', 'align' => 'left'), 'description' => array('display' => __('Event Description'), 'sort' => 'ASC', 'align' => 'left'), 'threshold_value' => array('display' => __('Alert Value'), 'sort' => 'ASC', 'align' => 'right'), 'current' => array('display' => __('Measured Value'), 'sort' => 'ASC', 'align' => 'right')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'thold_graph.php?action=log'); $i = 0; if (sizeof($logs)) { foreach ($logs as $l) { ?> <tr class='<?php print $thold_log_states[$l['status']]['class']; ?> '> <td class='left nowrap'><?php print $l['hdescription']; ?> </td> <td class='left nowrap'><?php print date('Y-m-d H:i:s', $l['time']); ?> </td> <td class='left nowrap'><?php print $thold_types[$l['type']]; ?> </td> <td class='left nowrap'><?php print strlen($l['description']) ? $l['description'] : __('Restoral Event'); ?> </td> <td class='right'><?php print $l['threshold_value'] != '' ? thold_format_number($l['threshold_value']) : __('N/A'); ?> </td> <td class='right'><?php print $l['current'] != '' ? thold_format_number($l['current']) : __('N/A'); ?> </td> <?php form_end_row(); } } else { print '<tr><td class="center" colspan="8">' . __('No Threshold Logs Found') . '</td></tr>'; } html_end_box(false); if (sizeof($logs)) { print $nav; } log_legend(); }
function thold_show_log() { global $config, $colors, $item_rows; $thold_log = array('Alarm' => 'F21924', 'Warning' => 'FB4A14', 'Re-Trigger' => 'FF7A30', 'Alert Trigger' => 'FAFD9E', 'Warn Trigger' => 'FAFD9E', 'Restoral' => 'CCFFCC', 'Restore' => 'CDCFC4', 'Alarm2Warn' => 'FACD6E'); $thold_status = array('0' => 'Restore', '1' => 'Alert Trigger', '2' => 'Re-Trigger', '3' => 'Warning', '4' => 'Alarm', '5' => 'Restoral', '6' => 'Warn Trigger', '7' => 'Alarm-Warn'); $types = array('High/Low', 'Baseline Deviation', 'Time Based'); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("threshold_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("status")); 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_log_current_page"); kill_session_var("sess_thold_log_filter"); kill_session_var("sess_thold_log_threshold_id"); kill_session_var("sess_thold_log_host_id"); kill_session_var("sess_thold_log_status"); kill_session_var("sess_thold_log_rows"); kill_session_var("sess_thold_log_sort_column"); kill_session_var("sess_thold_log_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_id"]); unset($_REQUEST["threshold_id"]); unset($_REQUEST["status"]); unset($_REQUEST["rows"]); 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_log_filter'); $changed += thold_request_check_changed('threshold_id', 'sess_thold_log_threshold_id'); $changed += thold_request_check_changed('host_id', 'sess_thold_log_host_id'); $changed += thold_request_check_changed('status', 'sess_thold_log_status'); $changed += thold_request_check_changed('rows', 'sess_thold_log_rows'); $changed += thold_request_check_changed('sort_column', 'sess_thold_log_sort_column'); $changed += thold_request_check_changed('sort_direction', 'sess_thold_log_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_log_current_page", "1"); load_current_session_value("filter", "sess_thold_log_filter", ""); load_current_session_value("threshold_id", "sess_thold_log_threshold_id", "-1"); load_current_session_value("host_id", "sess_thold_log_host_id", "-1"); load_current_session_value("status", "sess_thold_log_status", "-1"); load_current_session_value("rows", "sess_thold_log_rows", read_config_option("num_rows_device")); load_current_session_value("sort_column", "sess_thold_log_sort_column", "time"); load_current_session_value("sort_direction", "sess_thold_log_sort_direction", "DESC"); /* if the number of rows is -1, set it to the default */ if ($_REQUEST["rows"] == -1) { $_REQUEST["rows"] = read_config_option("num_rows_device"); } ?> <script type="text/javascript"> <!-- function filterChange(objForm) { strURL = '?tab=log&status=' + objForm.status.value; strURL = strURL + '&threshold_id=' + objForm.threshold_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 Log</strong> [last 30 days]", "100%", $colors["header"], "3", "center", ""); form_thold_log_filter(); html_end_box(); $sql_where = ''; if ($_REQUEST["host_id"] == "-1") { /* Show all items */ } elseif ($_REQUEST["host_id"] == "0") { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " host.id IS NULL"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.host_id=" . $_REQUEST["host_id"]; } if ($_REQUEST["threshold_id"] == "-1") { /* Show all items */ } elseif ($_REQUEST["threshold_id"] == "0") { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " thold_data.id IS NULL"; } elseif (!empty($_REQUEST["threshold_id"])) { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.threshold_id=" . $_REQUEST["threshold_id"]; } if ($_REQUEST["status"] == "-1") { /* Show all items */ } else { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.status=" . $_REQUEST["status"]; } if (strlen($_REQUEST["filter"])) { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.description LIKE '%" . $_REQUEST["filter"] . "%'"; } html_start_box("", "100%", $colors["header"], "3", "center", ""); $sortby = $_REQUEST["sort_column"]; $current_user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']); $sql_where .= ' AND ' . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']); $total_rows = db_fetch_cell("SELECT\r\n\t\tCOUNT(*)\r\n\t\tFROM plugin_thold_log\r\n\t\tLEFT JOIN host ON plugin_thold_log.host_id=host.id\r\n\t\tLEFT JOIN thold_data ON plugin_thold_log.threshold_id=thold_data.id\r\n\t\tLEFT JOIN graph_templates_graph AS gtg ON plugin_thold_log.graph_id=gtg.local_graph_id\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON (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\t{$sql_where}"); $sql_query = "SELECT plugin_thold_log.*, host.description AS hdescription, thold_data.name AS name, gtg.title_cache\r\n\t\tFROM plugin_thold_log\r\n\t\tLEFT JOIN host ON plugin_thold_log.host_id=host.id\r\n\t\tLEFT JOIN thold_data ON plugin_thold_log.threshold_id=thold_data.id\r\n\t\tLEFT JOIN graph_templates_graph AS gtg ON plugin_thold_log.graph_id=gtg.local_graph_id\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON (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\t{$sql_where}\r\n\t\tORDER BY " . $sortby . " " . $_REQUEST["sort_direction"] . "\r\n\t\tLIMIT " . $_REQUEST["rows"] * ($_REQUEST["page"] - 1) . "," . $_REQUEST["rows"]; //print $sql_query; $logs = db_fetch_assoc($sql_query); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["rows"], $total_rows, "thold_graph.php?tab=log"); if ($total_rows) { $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\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?tab=log&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?tab=log&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='11'>\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("hdescription" => array("<br>Host", "ASC"), "name" => array("<br>Threshold", "ASC"), "time" => array("<br>Time", "ASC"), "threshold_value" => array("Alarm<br>Value", "ASC"), "current" => array("Current<br>Value", "ASC"), "status" => array("<br>Status", "DESC"), "type" => array("<br>Type", "DESC"), "description" => array("<br>Event Description", "ASC")); html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($logs)) { foreach ($logs as $l) { ?> <tr style='background-color:#<?php print $thold_log[$thold_status[$l['status']]]; ?> '> <td style='white-space:nowrap;'><?php print $l["hdescription"]; ?> </td> <td style='white-space:nowrap;'><?php print $l["name"]; ?> </td> <td style='white-space:nowrap;'><?php print date("Y-m-d H:i:s", $l["time"]); ?> </td> <td><?php print $l["threshold_value"] != '' ? thold_format_number($l["threshold_value"]) : 'N/A'; ?> </td> <td><?php print $l["current"] != '' ? thold_format_number($l["current"]) : 'N/A'; ?> </td> <td nowrap style='white-space:nowrap;'><?php print $thold_status[$l["status"]]; ?> </td> <td nowrap style='white-space:nowrap;'><?php print $types[$l["type"]]; ?> </td> <td style='white-space:nowrap;'><?php print strlen($l["description"]) ? $l["description"] : "Restoral Event"; ?> </td> <?php form_end_row(); } } else { print "<tr><td><em>No Threshold Logs Found</em></td></tr>"; } /* put the nav bar on the bottom as well */ print $nav; html_end_box(false); log_legend(); //thold_display_rusage(); }
function thold_edit() { global $config; if (isset_request_var('id')) { $thold_data = db_fetch_row_prepared('SELECT * FROM thold_data WHERE id = ?', array(get_request_var('id'))); } elseif (isset_request_var('local_data_id') && isset_request_var('local_graph_id') && isset_request_var('host_id') && isset_request_var('data_template_id') && isset_request_var('data_template_rrd_id')) { $thold_data['id'] = '0'; $thold_data['local_data_id'] = get_filter_request_var('local_data_id'); $thold_data['local_graph_id'] = get_filter_request_var('local_graph_id'); $thold_data['data_template_id'] = get_filter_request_var('data_template_id'); $thold_data['host_id'] = get_filter_request_var('host_id'); $thold_data['data_template_rrd_id'] = get_filter_request_var('data_template_rrd_id'); $thold_data['thold_template_id'] = get_filter_request_var('thold_template_id'); } else { exit; } $desc = db_fetch_cell_prepared('SELECT name_cache FROM data_template_data WHERE local_data_id = ? LIMIT 1', array($thold_data['local_data_id'])); $rrdsql = array_rekey(db_fetch_assoc_prepared("SELECT id \n\t\tFROM data_template_rrd \n\t\tWHERE local_data_id = ? ORDER BY id", array($thold_data['local_data_id'])), 'id', 'id'); $grapharr = db_fetch_assoc('SELECT DISTINCT local_graph_id FROM graph_templates_item WHERE task_item_id IN (' . implode(', ', $rrdsql) . ') AND graph_template_id>0'); if (empty($thold_data['local_graph_id'])) { $thold_data['local_graph_id'] = db_fetch_cell_prepared('SELECT gl.id FROM graph_local AS gl INNER JOIN graph_templates_item AS gti ON gl.id=gti.local_graph_id INNER JOIN data_template_rrd AS dtr ON gti.task_item_id=dtr.id WHERE dtr.local_data_id = ? LIMIT 1', array($thold_data['local_data_id'])); } if (empty($thold_data['data_template_rrd_id'])) { $thold_data['data_template_rrd_id'] = db_fetch_cell_prepared('SELECT id FROM data_template_rrd AS dtr WHERE local_data_id = ? LIMIT 1', array($thold_data['local_data_id'])); } $dt_sql = 'SELECT DISTINCT dtr.local_data_id FROM data_template_rrd AS dtr LEFT JOIN graph_templates_item AS gti ON gti.task_item_id=dtr.id LEFT JOIN graph_local AS gl ON gl.id=gti.local_graph_id WHERE gl.id=' . $thold_data['local_graph_id']; $template_data_rrds = db_fetch_assoc("SELECT td.id AS thold_id, dtr.id, dtr.data_source_name, dtr.local_data_id \n\t\tFROM data_template_rrd AS dtr\n\t\tLEFT JOIN thold_data AS td\n\t\tON dtr.id=td.data_template_rrd_id\n\t\tWHERE dtr.local_data_id IN ({$dt_sql}) \n\t\tORDER BY dtr.id"); form_start('thold.php', 'thold'); html_start_box(__('Graph Data'), '100%', '', '3', 'center', ''); ?> <tr> <td class='textArea'> <?php if (isset($banner)) { echo $banner . '<br><br>'; } ?> <?php print __('Data Source Description:'); ?> <br><?php echo $desc; ?> <br><br> <?php print __('Associated Graph (graphs that use this RRD):'); ?> <br> <select name='element'> <?php foreach ($grapharr as $g) { $graph_desc = db_fetch_row_prepared('SELECT local_graph_id, title, title_cache FROM graph_templates_graph WHERE local_graph_id = ?', array($g['local_graph_id'])); echo "<option value='" . $graph_desc['local_graph_id'] . "'"; if ($graph_desc['local_graph_id'] == $thold_data['local_graph_id']) { echo ' selected'; } echo '>' . $graph_desc['local_graph_id'] . ' - ' . $graph_desc['title_cache'] . " </option>\n"; } ?> </select> <br> <br> </td> <td class='textArea'> <img id='graphimage' src='<?php echo htmlspecialchars($config['url_path'] . 'graph_image.php?local_graph_id=' . $thold_data['local_graph_id'] . '&rra_id=0&graph_start=-32400&graph_height=140&graph_width=500'); ?> '> </td> </tr> <?php html_end_box(); $template_rrd = db_fetch_row_prepared('SELECT * FROM data_template_rrd WHERE id = ?', array($thold_data['data_template_rrd_id'])); //----------------------------- // Tabs (if more than one item) //----------------------------- $i = 0; $ds = 0; if (isset($template_data_rrds)) { if (sizeof($template_data_rrds)) { /* draw the data source tabs on the top of the page */ print "<br><div class='tabs'><nav><ul>\n"; foreach ($template_data_rrds as $template_data_rrd) { if ($template_data_rrd['id'] == $thold_data['data_template_rrd_id']) { $ds = $template_data_rrd['data_source_name']; } if (!empty($template_data_rrd['thold_id'])) { $td = db_fetch_row('SELECT * FROM thold_data WHERE id=' . $template_data_rrd['thold_id']); } else { $td = array(); } $cur_setting = ''; if (!sizeof($td)) { $cur_setting .= "<span style='padding-right:4px;'>" . __('N/A') . "</span>"; } else { $cur_setting = '<span style="padding-right:4px;">' . __('Last:') . '</span>' . ($td['lastread'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceDown'>" . thold_format_number($td['lastread'], 4) . "</span>"); if ($td['thold_type'] != 1) { if ($td['thold_warning_fail_trigger'] != 0) { if ($td['thold_warning_hi'] != '') { $cur_setting .= '<span style="padding:4px">' . __('WHi:') . '</span>' . ($td['thold_warning_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_warning_hi'], 2) . '</span>'); } if ($td['thold_warning_low'] != '') { $cur_setting .= '<span style="padding:4px">' . __('WLo:') . '</span>' . ($td['thold_warning_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_warning_low'], 2) . '</span>'); } } if ($td['thold_fail_trigger'] != 0) { if ($td['thold_hi'] != '') { $cur_setting .= '<span style="padding:4px">' . __('AHi:') . '</span>' . ($td['thold_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_hi'], 2) . '</span>'); } if ($td['thold_low'] != '') { $cur_setting .= '<span style="padding:4px">' . __('ALo:') . '</span>' . ($td['thold_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_low'], 2) . '</span>'); } } } else { $cur_setting .= '<span style="padding:4px">' . __('AHi:') . '</span>' . ($td['thold_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span clas='deviceRecovering'>" . thold_format_number($td['thold_hi'], 2) . '</span>'); $cur_setting .= '<span style="padding:4px">' . __('ALo:') . '</span>' . ($td['thold_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_low'], 2) . '</span>'); $cur_setting .= '<span>' . __('BL: (Up %s %/Down %s %)', $td['bl_pct_up'], $td['bl_pct_down']) . '</span>'; } } if ($template_data_rrd['id'] == $thold_data['data_template_rrd_id']) { $selected = 'selected'; } else { $selected = ''; } if (!empty($template_data_rrd['thold_id'])) { echo "<li class='textEditTitle'><a class='hyperLink {$selected}' href='" . htmlspecialchars('thold.php?action=edit&id=' . $template_data_rrd['thold_id']) . "'>" . $template_data_rrd['data_source_name'] . '<br>' . $cur_setting . '</a></li>'; } else { echo "<li class='textEditTitle'><a class='hyperLink {$selected}' href='" . htmlspecialchars('thold.php?action=edit&local_data_id=' . $template_data_rrd['local_data_id'] . '&data_template_rrd_id=' . $template_data_rrd['id']) . '&local_graph_id=' . $thold_data['local_graph_id'] . '&host_id=' . $thold_data['host_id'] . '&data_template_id=' . $thold_data['data_template_id'] . '&thold_template_id=0' . "'>" . $template_data_rrd['data_source_name'] . '<br>' . $cur_setting . '</a></li>'; } } echo "<li class='textEditTitle'><a class='hyperLink' href='" . htmlspecialchars('thold.php?action=add' . '&local_graph_id=' . $thold_data['local_graph_id'] . '&host_id=' . $thold_data['host_id']) . "'>new thold<br>n/a</a></li>"; print "</ul></nav></div>\n"; } elseif (sizeof($template_data_rrds) == 1) { set_request_var('data_template_rrd_id', $template_data_rrds[0]['id']); } } //---------------------- // Data Source Item Form //---------------------- $thold_data_cdef = isset($thold_data['cdef']) ? $thold_data['cdef'] : 0; if (isset($thold_data['template'])) { $thold_data['template_name'] = db_fetch_cell_prepared('SELECT name FROM thold_template WHERE id = ?', array($thold_data['thold_template_id'])); } $header_text = __('Data Source Item [%s] ' . ' - Current value: [%s]', isset($template_rrd) ? $template_rrd['data_source_name'] : '', get_current_value($thold_data['local_data_id'], $ds, $thold_data_cdef)); html_start_box($header_text, '100%', '', '3', 'center', ''); $send_notification_array = array(); $users = db_fetch_assoc("SELECT plugin_thold_contacts.id, plugin_thold_contacts.data,\n\t\tplugin_thold_contacts.type, user_auth.full_name\n\t\tFROM plugin_thold_contacts, user_auth\n\t\tWHERE user_auth.id=plugin_thold_contacts.user_id\n\t\tAND plugin_thold_contacts.data!=''\n\t\tORDER BY user_auth.full_name ASC, plugin_thold_contacts.type ASC"); if (!empty($users)) { foreach ($users as $user) { $send_notification_array[$user['id']] = $user['full_name'] . ' - ' . ucfirst($user['type']); } } if (isset($thold_data['id'])) { $sql = 'SELECT contact_id as id FROM plugin_thold_threshold_contact WHERE thold_id=' . $thold_data['id']; $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $thold_data['local_data_id'], FALSE); } else { $sql = 'SELECT contact_id as id FROM plugin_thold_threshold_contact WHERE thold_id=0'; $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $thold_data['local_data_id'], FALSE); } include $config['base_path'] . '/plugins/thold/includes/arrays.php'; $data_fields = array(); $reference_types = get_reference_types($thold_data['local_data_id'], $step, $timearray); $temp = db_fetch_assoc('SELECT id, local_data_template_rrd_id, data_source_name, data_input_field_id FROM data_template_rrd WHERE local_data_id=' . $thold_data['local_data_id']); foreach ($temp as $d) { if ($d['data_input_field_id'] != 0) { $name = db_fetch_cell('SELECT name FROM data_input_fields WHERE id=' . $d['data_input_field_id']); } else { $name = $d['data_source_name']; } if ($d['id'] != $thold_data['data_template_rrd_id']) { $data_fields[$d['data_source_name']] = $name; } } $replacements = db_fetch_assoc_prepared('SELECT DISTINCT field_name FROM data_local AS dl INNER JOIN host_snmp_cache AS hsc ON dl.snmp_query_id=hsc.snmp_query_id AND dl.host_id=hsc.host_id WHERE dl.id = ?', array($thold_data['data_template_id'])); $nr = array(); if (sizeof($replacements)) { foreach ($replacements as $r) { $nr[] = "<span class='deviceUp'>|query_" . $r['field_name'] . "|</span>"; } } $vhf = explode('|', trim(VALID_HOST_FIELDS, '()')); if (sizeof($vhf)) { foreach ($vhf as $r) { $nr[] = "<span class='deviceUp'>|" . $r . "|</span>"; } } $replacements = "<br>" . __('Replacement Fields: %s', implode(", ", $nr)); $dss = db_fetch_assoc_prepared('SELECT data_source_name FROM data_template_rrd WHERE local_data_id = ?', array($thold_data['local_data_id'])); if (sizeof($dss)) { foreach ($dss as $ds) { $dsname[] = "<span class='deviceUp'>|ds:" . $ds["data_source_name"] . "|</span>"; } } $datasources = "<br>" . __('Data Sources: %s', implode(", ", $dsname)); $form_array = array('template_header' => array('friendly_name' => __('Template Settings'), 'method' => 'spacer'), 'template_enabled' => array('friendly_name' => __('Template Propagation Enabled'), 'method' => 'checkbox', 'default' => '', 'description' => __('Whether or not these settings will be propagates from the threshold template.'), 'value' => !empty($thold_data['template_enabled']) ? $thold_data['template_enabled'] : ''), 'template_name' => array('friendly_name' => __('Template Name'), 'method' => 'custom', 'default' => '', 'description' => __('Name of the Threshold Template the threshold was created from.'), 'value' => isset($thold_data['template_name']) ? $thold_data['template_name'] : 'N/A'), 'general_header' => array('friendly_name' => __('General Settings'), 'method' => 'spacer'), 'name' => array('friendly_name' => __('Threshold Name'), 'method' => 'textbox', 'max_length' => 100, 'size' => '70', 'default' => $desc . ' [' . $template_rrd['data_source_name'] . ']', 'description' => __('Provide the Thresholds a meaningful name'), 'value' => isset($thold_data['name']) ? $thold_data['name'] : ''), 'thold_enabled' => array('friendly_name' => __('Threshold Enabled'), 'method' => 'checkbox', 'default' => 'on', 'description' => __('Whether or not this threshold will be checked and alerted upon.'), 'value' => isset($thold_data['thold_enabled']) ? $thold_data['thold_enabled'] : ''), 'exempt' => array('friendly_name' => __('Weekend Exemption'), 'description' => __('If this is checked, this Threshold will not alert on weekends.'), 'method' => 'checkbox', 'default' => '', 'value' => isset($thold_data['exempt']) ? $thold_data['exempt'] : ''), 'restored_alert' => array('friendly_name' => __('Disable Restoration Email'), 'description' => __('If this is checked, Thold will not send an alert when the threshold has returned to normal status.'), 'method' => 'checkbox', 'default' => '', 'value' => isset($thold_data['restored_alert']) ? $thold_data['restored_alert'] : ''), 'thold_type' => array('friendly_name' => __('Threshold Type'), 'method' => 'drop_array', 'on_change' => 'changeTholdType()', 'array' => $thold_types, 'default' => read_config_option('thold_type'), 'description' => __('The type of Threshold that will be monitored.'), 'value' => isset($thold_data['thold_type']) ? $thold_data['thold_type'] : ''), 'repeat_alert' => array('friendly_name' => __('Re-Alert Cycle'), 'method' => 'drop_array', 'array' => $repeatarray, 'default' => read_config_option('alert_repeat'), 'description' => __('Repeat alert after this amount of time has pasted since the last alert.'), 'value' => isset($thold_data['repeat_alert']) ? $thold_data['repeat_alert'] : ''), 'thold_warning_header' => array('friendly_name' => __('Warning - High / Low Settings'), 'method' => 'spacer'), 'thold_warning_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, warning will be triggered'), 'value' => isset($thold_data['thold_warning_hi']) ? $thold_data['thold_warning_hi'] : ''), 'thold_warning_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, warning will be triggered'), 'value' => isset($thold_data['thold_warning_low']) ? $thold_data['thold_warning_low'] : ''), 'thold_warning_fail_trigger' => array('friendly_name' => __('Breach Duration'), 'method' => 'drop_array', 'array' => $alertarray, 'description' => __('The amount of time the data source must be in breach of the threshold for a warning to be raised.'), 'value' => isset($thold_data['thold_warning_fail_trigger']) ? $thold_data['thold_warning_fail_trigger'] : read_config_option('alert_trigger')), 'thold_header' => array('friendly_name' => __('Alert - High / Low Settings'), 'method' => 'spacer'), 'thold_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['thold_hi']) ? $thold_data['thold_hi'] : ''), 'thold_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['thold_low']) ? $thold_data['thold_low'] : ''), 'thold_fail_trigger' => array('friendly_name' => __('Breach Duration'), 'method' => 'drop_array', 'array' => $alertarray, 'description' => __('The amount of time the data source must be in breach of the threshold for an alert to be raised.'), 'value' => isset($thold_data['thold_fail_trigger']) ? $thold_data['thold_fail_trigger'] : read_config_option('alert_trigger')), 'time_warning_header' => array('friendly_name' => __('Warning - Time Based Settings'), 'method' => 'spacer'), 'time_warning_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, warning will be triggered'), 'value' => isset($thold_data['time_warning_hi']) ? $thold_data['time_warning_hi'] : ''), 'time_warning_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, warning will be triggered'), 'value' => isset($thold_data['time_warning_low']) ? $thold_data['time_warning_low'] : ''), 'time_warning_fail_trigger' => array('friendly_name' => __('Breach Count'), 'method' => 'textbox', 'max_length' => 5, 'size' => 10, 'description' => __('The number of times the data source must be in breach of the threshold.'), 'value' => isset($thold_data['time_warning_fail_trigger']) ? $thold_data['time_warning_fail_trigger'] : read_config_option('thold_warning_time_fail_trigger')), 'time_warning_fail_length' => array('friendly_name' => __('Breach Window'), 'method' => 'drop_array', 'array' => $timearray, 'description' => __('The amount of time in the past to check for threshold breaches.'), 'value' => isset($thold_data['time_warning_fail_length']) ? $thold_data['time_warning_fail_length'] : (read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1)), 'time_header' => array('friendly_name' => __('Alert - Time Based Settings'), 'method' => 'spacer'), 'time_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['time_hi']) ? $thold_data['time_hi'] : ''), 'time_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['time_low']) ? $thold_data['time_low'] : ''), 'time_fail_trigger' => array('friendly_name' => __('Breach Count'), 'method' => 'textbox', 'max_length' => 5, 'size' => 10, 'default' => read_config_option('thold_time_fail_trigger'), 'description' => __('The number of times the data source must be in breach of the threshold.'), 'value' => isset($thold_data['time_fail_trigger']) ? $thold_data['time_fail_trigger'] : read_config_option('thold_time_fail_trigger')), 'time_fail_length' => array('friendly_name' => __('Breach Window'), 'method' => 'drop_array', 'array' => $timearray, 'description' => __('The amount of time in the past to check for threshold breaches.'), 'value' => isset($thold_data['time_fail_length']) ? $thold_data['time_fail_length'] : (read_config_option('thold_time_fail_length') > 0 ? read_config_option('thold_time_fail_length') : 1)), 'baseline_header' => array('friendly_name' => __('Baseline Settings'), 'method' => 'spacer'), 'bl_ref_time_range' => array('friendly_name' => __('Time range'), 'method' => 'drop_array', 'array' => $reference_types, 'description' => __('Specifies the point in the past (based on rrd resolution) that will be used as a reference'), 'value' => isset($thold_data['bl_ref_time_range']) ? $thold_data['bl_ref_time_range'] : read_config_option('alert_bl_timerange_def')), 'bl_pct_up' => array('friendly_name' => __('Deviation UP'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Specifies allowed deviation in percentage for the upper bound threshold. If not set, upper bound threshold will not be checked at all.'), 'value' => isset($thold_data['bl_pct_up']) ? $thold_data['bl_pct_up'] : ''), 'bl_pct_down' => array('friendly_name' => __('Deviation DOWN'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Specifies allowed deviation in percentage for the lower bound threshold. If not set, lower bound threshold will not be checked at all.'), 'value' => isset($thold_data['bl_pct_down']) ? $thold_data['bl_pct_down'] : ''), 'bl_fail_trigger' => array('friendly_name' => __('Baseline Trigger Count'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Number of consecutive times the data source must be in breach of the baseline threshold for an alert to be raised.<br>Leave empty to use default value (<b>Default: %s cycles</b>)', read_config_option('alert_bl_trigger')), 'value' => isset($thold_data['bl_fail_trigger']) ? $thold_data['bl_fail_trigger'] : read_config_option("alert_bl_trigger")), 'data_manipulation' => array('friendly_name' => __('Data Manipulation'), 'method' => 'spacer'), 'data_type' => array('friendly_name' => __('Data Type'), 'method' => 'drop_array', 'on_change' => 'changeDataType()', 'array' => $data_types, 'default' => read_config_option('data_type'), 'description' => __('Special formatting for the given data.'), 'value' => isset($thold_data['data_type']) ? $thold_data['data_type'] : ''), 'cdef' => array('friendly_name' => __('Threshold CDEF'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Apply this CDEF before returning the data.'), 'value' => isset($thold_data['cdef']) ? $thold_data['cdef'] : 0, 'array' => thold_cdef_select_usable_names()), 'percent_ds' => array('friendly_name' => __('Percent Datasource'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Second Datasource Item to use as total value to calculate percentage from.'), 'value' => isset($thold_data['percent_ds']) ? $thold_data['percent_ds'] : 0, 'array' => $data_fields), 'expression' => array('friendly_name' => __('RPN Expression'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 80, 'default' => '', 'description' => __('An RPN Expression is an RRDtool Compatible RPN Expression. Syntax includes all functions below in addition to both Device and Data Query replacement expressions such as <span class="deviceUp">|query_ifSpeed|</span>. To use a Data Source in the RPN Expression, you must use the syntax: <span class="deviceUp">|ds:dsname|</span>. For example, <span class="deviceUp">|ds:traffic_in|</span> will get the current value of the traffic_in Data Source for the RRDfile(s) associated with the Graph. Any Data Source for a Graph can be included.<br><br>Math Operators: <span class="deviceUp">+, -, /, *, %, ^</span><br>Functions: <span class="deviceUp">SIN, COS, TAN, ATAN, SQRT, FLOOR, CEIL, DEG2RAD, RAD2DEG, ABS, EXP, LOG, ATAN, ADNAN</span><br>Flow Operators: <span class="deviceUp">UN, ISINF, IF, LT, LE, GT, GE, EQ, NE</span><br>Comparison Functions: <span class="deviceUp">MAX, MIN, INF, NEGINF, NAN, UNKN, COUNT, PREV</span>%s %s', $replacements, $datasources), 'value' => isset($thold_data['expression']) ? $thold_data['expression'] : '', 'max_length' => '255', 'size' => '80'), 'other_header' => array('friendly_name' => __('Other Settings'), 'method' => 'spacer'), 'notify_warning' => array('friendly_name' => __('Warning Notification List'), 'method' => 'drop_sql', 'description' => __('You may specify choose a Notification List to receive Warnings for this Data Source'), 'value' => isset($thold_data['notify_warning']) ? $thold_data['notify_warning'] : '', 'none_value' => __('None'), 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'), 'notify_alert' => array('friendly_name' => __('Alert Notification List'), 'method' => 'drop_sql', 'description' => __('You may specify choose a Notification List to receive Alerts for this Data Source'), 'value' => isset($thold_data['notify_alert']) ? $thold_data['notify_alert'] : '', 'none_value' => __('None'), 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name')); if (read_config_option("thold_alert_snmp") == 'on') { $extra = array('snmp_event_category' => array('friendly_name' => __('SNMP Notification - Event Category'), 'method' => 'textbox', 'description' => __('To allow a NMS to categorize different SNMP notifications more easily please fill in the category SNMP notifications for this template should make use of. E.g.: "disk_usage", "link_utilization", "ping_test", "nokia_firewall_cpu_utilization" ...'), 'value' => isset($thold_data['snmp_event_category']) ? $thold_data['snmp_event_category'] : '', 'default' => '', 'max_length' => '255'), 'snmp_event_severity' => array('friendly_name' => __('SNMP Notification - Alert Event Severity'), 'method' => 'drop_array', 'default' => '3', 'description' => __('Severity to be used for alerts. (low impact -> critical impact)'), 'value' => isset($thold_data['snmp_event_severity']) ? $thold_data['snmp_event_severity'] : 3, 'array' => array(1 => __('Low'), 2 => __('Medium'), 3 => __('High'), 4 => __('Critical')))); $form_array += $extra; if (read_config_option('thold_alert_snmp_warning') != 'on') { $extra = array('snmp_event_warning_severity' => array('friendly_name' => __('SNMP Notification - Warning Event Severity'), 'method' => 'drop_array', 'default' => '2', 'description' => __('Severity to be used for warnings. (Low impact -> Critical impact).<br>Note: The severity of warnings has to be equal or lower than the severity being defined for alerts.'), 'value' => isset($thold_data['snmp_event_warning_severity']) ? $thold_data['snmp_event_warning_severity'] : 2, 'array' => array(1 => __('Low'), 2 => __('Medium'), 3 => __('High'), 4 => __('Critical')))); } $form_array += $extra; } if (read_config_option('thold_disable_legacy') != 'on') { $extra = array('notify_accounts' => array('friendly_name' => __('Notify accounts'), 'method' => 'drop_multi', 'description' => __('This is a listing of accounts that will be notified when this threshold is breached.<br><br><br><br>'), 'array' => $send_notification_array, 'sql' => $sql), 'notify_extra' => array('friendly_name' => __('Alert Emails'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => __('You may specify here extra Emails to receive alerts for this data source (comma separated)'), 'value' => isset($thold_data['notify_extra']) ? $thold_data['notify_extra'] : ''), 'notify_warning_extra' => array('friendly_name' => __('Warning Emails'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => __('You may specify here extra Emails to receive warnings for this data source (comma separated)'), 'value' => isset($thold_data['notify_warning_extra']) ? $thold_data['notify_warning_extra'] : '')); $form_array += $extra; } else { $extra = array('notify_accounts' => array('method' => 'hidden', 'value' => 'ignore'), 'notify_extra' => array('method' => 'hidden', 'value' => isset($thold_data['notify_extra']) ? $thold_data['notify_extra'] : ''), 'notify_warning_extra' => array('method' => 'hidden', 'value' => isset($thold_data['notify_warning_extra']) ? $thold_data['notify_warning_extra'] : '')); $form_array += $extra; } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array + array('id' => array('method' => 'hidden', 'value' => !empty($thold_data['id']) ? $thold_data['id'] : '0'), 'data_template_rrd_id' => array('method' => 'hidden', 'value' => isset($template_rrd) ? $template_rrd['id'] : '0'), 'host_id' => array('method' => 'hidden', 'value' => $thold_data['host_id']), 'local_data_id' => array('method' => 'hidden', 'value' => $thold_data['local_data_id'])))); html_end_box(); if (isset($_SESSION['data_return'])) { $ajax = false; } else { $ajax = true; } form_save_button('thold.php' . (!empty($thold_data['id']) ? '?id=' . $thold_data['id'] : ''), 'return', 'id', $ajax); ?> <script type='text/javascript'> function templateEnableDisable() { var status = $('#template_enabled').is(':checked'); $('#name').prop('disabled', status); $('#thold_type').prop('disabled', status); $('#thold_hi').prop('disabled', status); $('#thold_low').prop('disabled', status); $('#thold_fail_trigger').prop('disabled', status); $('#thold_warning_hi').prop('disabled', status); $('#thold_warning_low').prop('disabled', status); $('#thold_warning_fail_trigger').prop('disabled', status); $('#repeat_alert').prop('disabled', status); $('#notify_extra').prop('disabled', status); $('#notify_warning_extra').prop('disabled', status); $('#notify_warning').prop('disabled', status); $('#notify_alert').prop('disabled', status); $('#cdef').prop('disabled', status); $('#thold_enabled').prop('disabled', status); if ($('#notify_accounts')) $('#notify_accounts').prop('disabled', status); $('#time_hi').prop('disabled', status); $('#time_low').prop('disabled', status); $('#time_fail_trigger').prop('disabled', status); $('#time_fail_length').prop('disabled', status); $('#time_warning_hi').prop('disabled', status); $('#time_warning_low').prop('disabled', status); $('#time_warning_fail_trigger').prop('disabled', status); $('#time_warning_fail_length').prop('disabled', status); $('#data_type').prop('disabled', status); $('#percent_ds').prop('disabled', status); $('#expression').prop('disabled', status); $('#exempt').prop('disabled', status); $('#restored_alert').prop('disabled', status); if ($('#snmp_event_category')) $('#snmp_event_category').prop('disabled', status); if ($('#snmp_event_severity')) $('#snmp_event_severity').prop('disabled', status); if ($('#snmp_event_warning_severity')) $('#snmp_event_warning_severity').prop('disabled', status); } function changeTholdType() { switch($('#thold_type').val()) { case '0': thold_toggle_hilow(''); thold_toggle_baseline('none'); thold_toggle_time('none'); break; case '1': thold_toggle_hilow('none'); thold_toggle_baseline(''); thold_toggle_time('none'); break; case '2': thold_toggle_hilow('none'); thold_toggle_baseline('none'); thold_toggle_time(''); break; } } function changeDataType () { switch($('#data_type').val()) { case '0': $('#row_cdef').hide(); $('#row_percent_ds').hide(); $('#row_expression').hide(); break; case '1': $('#row_cdef').show(); $('#row_percent_ds').hide(); $('#row_expression').hide(); break; case '2': $('#row_cdef').hide() $('#row_percent_ds').show(); $('#row_expression').hide(); break; case '3': $('#row_expression').show(); $('#row_cdef').hide(); $('#row_percent_ds').hide(); break; } } function thold_toggle_hilow (status) { if (status == '') { $('#row_thold_header, #row_thold_hi, #row_thold_low, #row_thold_fail_trigger').show(); $('#row_thold_warning_header, #row_thold_warning_hi').show(); $('#row_thold_warning_low, #row_thold_warning_fail_trigger').show(); }else{ $('#row_thold_header, #row_thold_hi, #row_thold_low, #row_thold_fail_trigger').hide(); $('#row_thold_warning_header, #row_thold_warning_hi').hide(); $('#row_thold_warning_low, #row_thold_warning_fail_trigger').hide(); } } function thold_toggle_baseline(status) { if (status == '') { $('#row_baseline_header, #row_bl_ref_time_range').show(); $('#row_bl_pct_up, #row_bl_pct_down, #row_bl_fail_trigger').show(); }else{ $('#row_baseline_header, #row_bl_ref_time_range').hide(); $('#row_bl_pct_up, #row_bl_pct_down, #row_bl_fail_trigger').hide(); } } function thold_toggle_time(status) { if (status == '') { $('#row_time_header, #row_time_hi, #row_time_low, #row_time_fail_trigger, #row_time_fail_length').show(); $('#row_time_warning_header, #row_time_warning_hi, #row_time_warning_low').show(); $('#row_time_warning_fail_trigger, #row_time_warning_fail_length').show(); }else{ $('#row_time_header, #row_time_hi, #row_time_low, #row_time_fail_trigger, #row_time_fail_length').hide(); $('#row_time_warning_header, #row_time_warning_hi, #row_time_warning_low').hide(); $('#row_time_warning_fail_trigger, #row_time_warning_fail_length').hide(); } } function graphImage() { var id = $('#element').val(); $('#graphimage').attr(src, '../../graph_image.php?local_graph_id=' + id + '&rra_id=0&graph_start=-32400&graph_height=100&graph_width=300&graph_nolegend=true').change(); } $(function() { if ('<?php print $thold_data['thold_template_id']; ?> ' == '0') { $('#template_enabled').prop('disabled', true); } if ($('#notify_accounts option').length == 0) { $('#row_notify_accounts').hide(); } if ($('#notify_warning option').length == 0) { $('#row_notify_warning').hide(); } if ($('#notify_alert option').length == 0) { $('#row_notify_alert').hide(); } $('#notify_accounts').multiselect({ minWidth: '400', noneSelectedText: '<?php print __('Select Users(s)'); ?> ', selectedText: function(numChecked, numTotal, checkedItems) { myReturn = numChecked + ' <?php print __('Users Selected'); ?> '; $.each(checkedItems, function(index, value) { if (value.value == '0') { myReturn='<?php print __('All Users Selected'); ?> '; return false; } }); return myReturn; }, checkAllText: 'All', uncheckAllText: 'None', uncheckall: function() { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).prop('checked', true); }); }, open: function() { size = $('#notify_accounts option').length * 18 + 20; if (size > 100) { size = 100; } $('ul.ui-multiselect-checkboxes').css('height', size + 'px'); }, click: function(event, ui) { checked=$(this).multiselect('widget').find('input:checked').length; if (ui.value == '0') { if (ui.checked == true) { $('#host').multiselect('uncheckAll'); $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).prop('checked', true); }); } }else if (checked == 0) { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).click(); }); }else if ($(this).multiselect('widget').find('input:checked:first').val() == '0') { if (checked > 0) { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).click(); $(this).prop('disable', true); }); } } } }).multiselectfilter( { label: 'Search', width: '150' }); templateEnableDisable(); $('#template_enabled').click(function() { templateEnableDisable(); }); <?php if (!isset($thold_data['thold_template_id']) || $thold_data['thold_template_id'] == '') { ?> $('#templated_enabled').prop('disabled', true); <?php } ?> changeTholdType (); changeDataType (); $('#element').change(function() { graphImage; }); }); </script> <?php }
function templates() { global $config, $thold_actions, $item_rows; include $config['base_path'] . '/plugins/thold/includes/arrays.php'; template_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'); } html_start_box(__('Threshold Templates'), '100%', '', '3', 'center', 'thold_templates.php?action=add'); ?> <tr class='even'> <td> <form id='listthold' action='thold_templates.php'> <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> <td> <?php print __('Templates'); ?> </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 '>' . $value . "</option>\n"; } } ?> </select> </td> <td> <input id='refresh' type='button' value='<?php print __('Go'); ?> ' onClick='applyFilter()'> </td> <td> <input id='clear' type='button' value='<?php print __('Clear'); ?> ' onClick='clearFilter()'> </td> <td> <input id='import' type='button' value='<?php print __('Import'); ?> ' onClick='importTemplate()'> </td> </tr> </table> </form> <script type='text/javascript'> function applyFilter() { strURL = 'thold_templates.php?header=false&rows=' + $('#rows').val(); strURL += '&filter=' + $('#filter').val(); loadPageNoHeader(strURL); } function clearFilter() { strURL = 'thold_templates.php?header=false&clear=1'; loadPageNoHeader(strURL); } function importTemplate() { strURL = 'thold_templates.php?header=false&action=import'; loadPageNoHeader(strURL); } $(function() { $('#listthold').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); $sql_where = ''; $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows; $order = 'ORDER BY ' . get_request_var('sort_column') . ' ' . get_request_var('sort_direction'); if (strlen(get_request_var('filter'))) { $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " thold_template.name LIKE '%" . get_request_var('filter') . "%'"; } $total_rows = db_fetch_cell('SELECT count(*) FROM thold_template'); $template_list = db_fetch_assoc("SELECT * FROM thold_template {$sql_where} {$order} {$limit}"); $nav = html_nav_bar('thold_templates.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Templates'), 'page', 'main'); form_start('thold_templates.php', 'chk'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('name' => array(__('Name'), 'ASC'), 'data_template_name' => array(__('Data Template'), 'ASC'), 'data_source_name' => array(__('DS Name'), 'ASC'), 'thold_type' => array(__('Type'), 'ASC'), 'nosort1' => array(__('High/Up'), ''), 'nosort2' => array(__('Low/Down'), ''), 'nosort3' => array(__('Trigger'), ''), 'nosort4' => array(__('Duration'), ''), 'nosort5' => array(__('Repeat'), '')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); $i = 0; if (sizeof($template_list)) { foreach ($template_list as $template) { switch ($template['thold_type']) { case 0: # hi/lo $value_hi = thold_format_number($template['thold_hi']); $value_lo = thold_format_number($template['thold_low']); $value_trig = $template['thold_fail_trigger']; $value_duration = ''; $value_warning_hi = thold_format_number($template['thold_warning_hi']); $value_warning_lo = thold_format_number($template['thold_warning_low']); $value_warning_trig = $template['thold_warning_fail_trigger']; $value_warning_duration = ''; break; case 1: # baseline $value_hi = $template['bl_pct_up'] . (strlen($template['bl_pct_up']) ? '%' : '-'); $value_lo = $template['bl_pct_down'] . (strlen($template['bl_pct_down']) ? '%' : '-'); $value_trig = $template['bl_fail_trigger']; $step = db_fetch_cell_prepared('SELECT rrd_step FROM data_template_data WHERE data_template_id = ? LIMIT 1', array($template['data_template_id'])); $value_duration = $template['bl_ref_time_range'] / $step; break; case 2: #time $value_hi = thold_format_number($template['time_hi']); $value_lo = thold_format_number($template['time_low']); $value_trig = $template['time_fail_trigger']; $value_duration = $template['time_fail_length']; break; } $name = $template['name'] == '' ? $template['data_template_name'] . ' [' . $template['data_source_name'] . ']' : $template['name']; $name = filter_value($name, get_request_var('filter')); form_alternate_row('line' . $template['id']); form_selectable_cell('<a class="linkEditMain" href="' . htmlspecialchars('thold_templates.php?action=edit&id=' . $template['id']) . '">' . $name . '</a>', $template['id']); form_selectable_cell(filter_value($template['data_template_name'], get_request_var('filter')), $template['id']); form_selectable_cell($template['data_source_name'], $template['id']); form_selectable_cell($thold_types[$template['thold_type']], $template['id']); form_selectable_cell($value_hi, $template['id']); form_selectable_cell($value_lo, $template['id']); $trigger = plugin_thold_duration_convert($template['data_template_id'], $value_trig, 'alert', 'data_template_id'); form_selectable_cell(strlen($trigger) ? '<i>' . $trigger . '</i>' : '-', $template['id']); $duration = plugin_thold_duration_convert($template['data_template_id'], $value_duration, 'time', 'data_template_id'); form_selectable_cell(strlen($duration) ? $duration : '-', $template['id']); form_selectable_cell(plugin_thold_duration_convert($template['data_template_id'], $template['repeat_alert'], 'repeat', 'data_template_id'), $template['id']); form_checkbox_cell($template['data_template_name'], $template['id']); form_end_row(); } } else { print "<tr><td><em>" . __('No Threshold Templates') . "</em></td></tr>\n"; } html_end_box(false); if (sizeof($template_list)) { print $nav; } /* draw the dropdown containing a list of available actions for this form */ 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'; }