예제 #1
0
function thold_request_validation()
{
    global $title, $colors, $rows_selector, $config, $reset_multi;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('rows'));
    input_validate_input_number(get_request_var_request('page'));
    /* ==================================================== */
    /* clean up sort solumn */
    if (isset($_REQUEST['sort_column'])) {
        $_REQUEST['sort_column'] = sanitize_search_string(get_request_var('sort_column'));
    }
    /* clean up sort direction */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var('sort_direction'));
    }
    /* clean up associated */
    if (isset($_REQUEST['associated'])) {
        $_REQUEST['associated'] = sanitize_search_string(get_request_var('associated'));
    }
    /* clean up filter */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var('filter'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clearf'])) {
        kill_session_var('sess_thold_nlt_rows');
        kill_session_var('sess_thold_nlt_page');
        kill_session_var('sess_thold_nlt_sort_column');
        kill_session_var('sess_thold_nlt_sort_direction');
        kill_session_var('sess_thold_nlt_associated');
        kill_session_var('sess_thold_nlt_filter');
        kill_session_var('sess_thold_nlt_state');
        kill_session_var('sess_thold_nlt_template');
        $_REQUEST['page'] = 1;
        unset($_REQUEST['rows']);
        unset($_REQUEST['page']);
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
        unset($_REQUEST['associated']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['template']);
        unset($_REQUEST['state']);
        $reset_multi = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = 0;
        $changed += thold_request_check_changed('rows', 'sess_thold_nlt_rows');
        $changed += thold_request_check_changed('sort_column', 'sess_thold_nlt_sort_column');
        $changed += thold_request_check_changed('sort_direction', 'sess_thold_nlt_sort_direction');
        $changed += thold_request_check_changed('state', 'sess_thold_nlt_state');
        $changed += thold_request_check_changed('associated', 'sess_thold_nlt_associated');
        $changed += thold_request_check_changed('filter', 'sess_thold_nlt_filter');
        $changed += thold_request_check_changed('template', 'sess_thold_nlt_template');
        if ($changed) {
            $_REQUEST['page'] = '1';
        }
        $reset_multi = false;
    }
    /* remember search fields in session vars */
    load_current_session_value('rows', 'sess_thold_nlt_rows', read_config_option('num_rows_thold'));
    load_current_session_value('page', 'sess_thold_nlt_current_page', '1');
    load_current_session_value('associated', 'sess_thold_nlt_associated', 'true');
    load_current_session_value('filter', 'sess_thold_nlt_filter', '');
    load_current_session_value('sort_column', 'sess_thold_nlt_sort_column', 'thold_alert');
    load_current_session_value('sort_direction', 'sess_thold_nlt_sort_direction', 'DESC');
    load_current_session_value('state', 'sess_thold_nlt_state', read_config_option('thold_filter_default'));
    load_current_session_value('template', 'sess_thold_nlt_template', '');
}
예제 #2
0
function template_request_validation()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("page"));
    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_tt_current_page");
        kill_session_var("sess_tt_filter");
        kill_session_var("sess_tt_rows");
        kill_session_var("sess_tt_sort_column");
        kill_session_var("sess_tt_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        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_tt_filter');
        $changed += thold_request_check_changed('rows', 'sess_tt_rows');
        $changed += thold_request_check_changed('sort_column', 'sess_tt_sort_column');
        $changed += thold_request_check_changed('sort_direction', 'sess_tt_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_tt_current_page", "1");
    load_current_session_value("filter", "sess_tt_filter", "");
    load_current_session_value("rows", "sess_tt_rows", read_config_option("alert_num_rows"));
    load_current_session_value("sort_column", "sess_tt_sort_column", "name");
    load_current_session_value("sort_direction", "sess_tt_sort_direction", "ASC");
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST["rows"] == -1) {
        $_REQUEST["rows"] = read_config_option("alert_num_rows");
        if ($_REQUEST["rows"] < 2) {
            $_REQUEST["rows"] = 30;
        }
    }
}
예제 #3
0
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>&lt;&lt; ";
        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 .= " &gt;&gt;</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();
}