Example #1
0
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();
}
Example #2
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();
}