Exemplo n.º 1
0
function tholds($header_label)
{
    global $item_rows, $config;
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    $thold_actions = array(1 => __('Associate'), 2 => __('Disassociate'));
    thold_request_validation();
    $statefilter = '';
    if (isset_request_var('state')) {
        if (get_request_var('state') == '-1') {
            $statefilter = '';
        } else {
            if (get_request_var('state') == '0') {
                $statefilter = "td.thold_enabled='off'";
            }
            if (get_request_var('state') == '2') {
                $statefilter = "td.thold_enabled='on'";
            }
            if (get_request_var('state') == '1') {
                $statefilter = '(td.thold_alert!=0 OR td.bl_alert>0)';
            }
            if (get_request_var('state') == '3') {
                $statefilter = '(td.thold_alert!=0 AND td.thold_fail_count >= td.thold_fail_trigger) OR (td.bl_alert>0 AND td.bl_fail_count >= td.bl_fail_trigger)';
            }
        }
    }
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    $sql_where = '';
    $sort = get_request_var('sort_column') . ' ' . get_request_var('sort_direction');
    $limit = $rows * (get_request_var('page') - 1) . ", {$rows}";
    if (!isempty_request_var('template') && get_request_var('template') != '-1') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . 'td.data_template_id = ' . get_request_var('template');
    }
    if (strlen(get_request_var('filter'))) {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . "td.name LIKE '%" . get_request_var('filter') . "%'";
    }
    if ($statefilter != '') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . $statefilter;
    }
    if (get_request_var('associated') == 'true') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . '(td.notify_warning=' . get_request_var('id') . ' OR td.notify_alert=' . get_request_var('id') . ')';
    }
    cacti_log($sql_where);
    $result = get_allowed_thresholds($sql_where, $sort, $limit, $total_rows);
    $data_templates = db_fetch_assoc('SELECT DISTINCT dt.id, dt.name
		FROM data_template AS dt
		INNER JOIN thold_data AS td
		ON td.data_template_id = dt.id
		ORDER BY dt.name');
    html_start_box(__('Associated Thresholds') . ' ' . htmlspecialchars($header_label), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form id='listthold' method='get' action='notify_lists.php'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var('filter'));
    ?>
' onChange='applyFilter()'>
					</td>
					<td>
						<?php 
    print __('Template');
    ?>
					</td>
					<td>
						<select id='template' onChange='applyFilter()'>
							<option value='-1'><?php 
    print __('Any');
    ?>
</option>
							<?php 
    foreach ($data_templates as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset_request_var('template') && $row['id'] == get_request_var('template') ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('State');
    ?>
					</td>
					<td>
						<select id='state' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('state') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('state') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Breached');
    ?>
</option>
							<option value='3'<?php 
    if (get_request_var('state') == '3') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Triggered');
    ?>
</option>
							<option value='2'<?php 
    if (get_request_var('state') == '2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Enabled');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('state') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Disabled');
    ?>
</option>
						</select>
					</td>
					<td>
						<?php 
    print __('Thresholds');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' id='associated' onChange='applyFilter()' <?php 
    print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'><?php 
    print __('Associated');
    ?>
</label>
					</td>
					<td>
						<input type='button' value='<?php 
    print __('Go');
    ?>
' onClick='applyFilter()' title='<?php 
    print __('Set/Refresh Filters');
    ?>
'>
					</td>
					<td>
						<input type='button' name='clearf' value='<?php 
    print __('Clear');
    ?>
' onClick='clearFilter()' title='<?php 
    print __('Clear Filters');
    ?>
'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
			<input type='hidden' id='tab' value='tholds'>
			<input type='hidden' id='id' value='<?php 
    print get_request_var('id');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL  = 'notify_lists.php?header=false&action=edit&tab=tholds&id=<?php 
    print get_request_var('id');
    ?>
'
			strURL += '&associated=' + $('#associated').is(':checked');;
			strURL += '&state=' + $('#state').val();
			strURL += '&rows=' + $('#rows').val();
			strURL += '&template=' + $('#template').val();
			strURL += '&filter=' + $('#filter').val();
			loadPageNoHeader(strURL);
		}

		function clearFilter() {
			strURL = 'notify_lists.php?header=false&action=edit&tab=tholds&id=<?php 
    print get_request_var('id');
    ?>
&clearf=true'
			loadPageNoHeader(strURL);
		}

		$(function() {
			$('#listthold').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
	
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    $nav = html_nav_bar('notify_lists.php?action=edit&tab=tholds', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Thresholds'), 'page', 'main');
    form_start('notify_lists.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '4', 'center', '');
    $display_text = array('name' => array(__('Name'), 'ASC'), 'id' => array(__('ID'), 'ASC'), 'nosort1' => array(__('Warning Lists'), 'ASC'), 'nosort2' => array(__('Alert Lists'), 'ASC'), 'thold_type' => array(__('Type'), 'ASC'), 'thold_alert' => array(__('Triggered'), 'ASC'), 'thold_enabled' => array(__('Enabled'), 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'notify_lists.php?action=edit&tab=tholds&id=' . get_filter_request_var('id'));
    $c = 0;
    $i = 0;
    if (count($result)) {
        foreach ($result as $row) {
            $c++;
            $alertstat = 'no';
            $bgcolor = 'green';
            if ($row['thold_type'] != 1) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'yes';
                }
            } else {
                if ($row['bl_alert'] == 1) {
                    $alertstat = 'baseline-LOW';
                } elseif ($row['bl_alert'] == 2) {
                    $alertstat = 'baseline-HIGH';
                }
            }
            /* show alert stats first */
            $alert_stat = '';
            $list = db_fetch_cell('SELECT count(*) FROM plugin_thold_threshold_contact WHERE thold_id=' . $row['id']);
            if ($list > 0) {
                $alert_stat = "<span style='font-weight:bold;color:green;'>" . __('Select Users') . "</span>";
            }
            if (strlen($row['notify_extra'])) {
                $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>";
            }
            if (!empty($row['notify_alert'])) {
                if (get_request_var('id') == $row['notify_alert']) {
                    $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>";
                } else {
                    $alert_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_alert']);
                    $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $alert_list . '</span>';
                }
            }
            if (!strlen($alert_stat)) {
                $alert_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>";
            }
            /* show warning stats first */
            $warn_stat = '';
            if (strlen($row['notify_warning_extra'])) {
                $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>";
            }
            if (!empty($row['notify_warning'])) {
                if (get_request_var('id') == $row['notify_warning']) {
                    $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>";
                } else {
                    $warn_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_warning']);
                    $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $warn_list . '</span>';
                }
            }
            if (!strlen($warn_stat) && ($row['thold_type'] == 0 && $row['thold_warning_hi'] == '' && $row['thold_warning_low'] == '' || $row['thold_type'] == 2 && $row['time_warning_hi'] == '' && $row['time_warning_low'] == '')) {
                $warn_stat = "<span style='font-weight:bold;color:red;'>" . __('None') . "</span>";
            } elseif (!strlen($warn_stat)) {
                $warn_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>";
            }
            if ($row['name'] != '') {
                $name = $row['name'];
            } else {
                $name = $row['name_cache'] . ' [' . $row['data_source_name'] . ']';
            }
            form_alternate_row('line' . $row['id'], true);
            form_selectable_cell(filter_value($name, get_request_var('filter')), $row['id']);
            form_selectable_cell($row['id'], $row['id']);
            form_selectable_cell($warn_stat, $row['id']);
            form_selectable_cell($alert_stat, $row['id']);
            form_selectable_cell($thold_types[$row['thold_type']], $row['id']);
            form_selectable_cell($alertstat, $row['id']);
            form_selectable_cell($row['thold_enabled'] == 'off' ? __('Disabled') : __('Enabled'), $row['id']);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
    } else {
        print "<tr class='even' <td colspan='8'><i>" . __('No Thresholds') . "</i></td></tr>\n";
    }
    html_end_box(false);
    if (count($result)) {
        print $nav;
    }
    form_hidden_box('tab', 'tholds', '');
    form_hidden_box('id', get_request_var('id'), '');
    form_hidden_box('save_tholds', '1', '');
    draw_actions_dropdown($thold_actions);
    form_end();
}
Exemplo n.º 2
0
function tholds()
{
    global $config, $device_actions, $item_rows, $thold_classes, $thold_states;
    /* ================= input validation and session storage ================= */
    $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'name', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')), 'data_template_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'host_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'));
    validate_store_request_vars($filters, 'sess_thold');
    /* ================= input validation ================= */
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    html_start_box(__('Threshold Status'), '100%', '', '3', 'center', '');
    form_thold_filter();
    html_end_box();
    /* build the SQL query and WHERE clause */
    if (get_request_var('sort_column') == 'lastread') {
        $sort = get_request_var('sort_column') . "/1";
    } else {
        $sort = get_request_var('sort_column');
    }
    $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows;
    $sql_where = '';
    /* status filter */
    if (get_request_var('status') == '-1') {
        /* return all rows */
    } else {
        if (get_request_var('status') == '0') {
            $sql_where = "(td.thold_enabled='off'";
        }
        /*disabled*/
        if (get_request_var('status') == '2') {
            $sql_where = "(td.thold_enabled='on'";
        }
        /* enabled */
        if (get_request_var('status') == '1') {
            $sql_where = "((td.thold_alert!=0 OR td.bl_alert>0)";
        }
        /* breached */
        if (get_request_var('status') == '3') {
            $sql_where = "(((td.thold_alert!=0 AND td.thold_fail_count >= td.thold_fail_trigger) OR (td.bl_alert>0 AND td.bl_fail_count >= td.bl_fail_trigger))";
        }
        /* status */
    }
    if (strlen(get_request_var('filter'))) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '(') . " td.name LIKE '%" . get_request_var('filter') . "%'";
    }
    /* data template id filter */
    if (get_request_var('data_template_id') != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : '(') . ' td.data_template_id=' . get_request_var('data_template_id');
    }
    /* host id filter */
    if (get_request_var('host_id') != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : '(') . ' td.host_id=' . get_request_var('host_id');
    }
    if ($sql_where != '') {
        $sql_where .= ')';
    }
    $tholds = get_allowed_thresholds($sql_where, $sort . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ", {$rows}", $total_rows);
    $nav = html_nav_bar('thold_graph.php?action=thold', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 13, 'Thresholds', 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '4', 'center', '');
    $display_text = array('nosort' => array('display' => __('Actions'), 'sort' => '', 'align' => 'left'), 'name' => array('display' => __('Name'), 'sort' => 'ASC', 'align' => 'left'), 'id' => array('display' => __('ID'), 'sort' => 'ASC', 'align' => 'right'), 'thold_type' => array('display' => __('Type'), 'sort' => 'ASC', 'align' => 'left'), 'lastread' => array('display' => __('Current'), 'sort' => 'ASC', 'align' => 'right'), 'nosort4' => array('display' => __('Warn Hi/Lo'), 'sort' => 'ASC', 'align' => 'right'), 'nosort5' => array('display' => __('Alert Hi/Lo'), 'sort' => 'ASC', 'align' => 'right'), 'nosort6' => array('display' => __('BL Hi/Lo'), 'sort' => 'ASC', 'align' => 'right'), 'nosort2' => array('display' => __('Trigger'), 'sort' => 'ASC', 'align' => 'right'), 'nosort3' => array('display' => __('Duration'), 'sort' => 'ASC', 'align' => 'right'), 'repeat_alert' => array('display' => __('Repeat'), 'sort' => 'ASC', 'align' => 'right'), 'thold_alert' => array('display' => __('Triggered'), 'sort' => 'ASC', 'align' => 'right'));
    html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'thold_graph.php?action=thold');
    $step = read_config_option('poller_interval');
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    $c = 0;
    $i = 0;
    if (sizeof($tholds)) {
        foreach ($tholds as $row) {
            $c++;
            $alertstat = 'No';
            $bgcolor = 'green';
            if ($row['thold_type'] == 0) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = __('Yes');
                    if ($row['thold_fail_count'] >= $row['thold_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($row['thold_warning_fail_count'] >= $row['thold_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } elseif ($row['thold_type'] == 2) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'Yes';
                    if ($row['thold_fail_count'] >= $row['time_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($row['thold_warning_fail_count'] >= $row['time_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } else {
                if ($row['bl_alert'] == 1) {
                    $alertstat = __('Baseline-LOW');
                    $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow';
                } elseif ($row['bl_alert'] == 2) {
                    $alertstat = __('Baseline-HIGH');
                    $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow';
                }
            }
            if ($row['thold_enabled'] == 'off') {
                print "<tr class='selectable " . $thold_states['grey']['class'] . "' id='line" . $row['id'] . "'>\n";
            } else {
                print "<tr class='selectable " . $thold_states[$bgcolor]['class'] . "' id='line" . $row['id'] . "'>\n";
            }
            print "<td width='1%' style='white-space:nowrap;'>";
            if (api_user_realm_auth('thold.php')) {
                print '<a href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold.php?action=edit&id=' . $row['id']) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/edit_object.png" border="0" alt="" title="' . __('Edit Threshold') . '"></a>';
            }
            if ($row['thold_enabled'] == 'on') {
                print '<a class="hyperLink" href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold_graph.php?action=disable&id=' . $row['id']) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/disable_thold.png" border="0" alt="" title="' . __('Disable Threshold') . '"></a>';
            } else {
                print '<a class="hyperLink" href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold_graph.php?action=enable&id=' . $row['id']) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/enable_thold.png" border="0" alt="" title="' . __('Enable Threshold') . '"></a>';
            }
            print "<a href='" . htmlspecialchars($config['url_path'] . 'graph.php?local_graph_id=' . $row['local_graph_id'] . '&rra_id=all') . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_graphs.gif' border='0' alt='' title='" . __('View Graph') . "'></a>";
            print "<a class='hyperLink' href='" . htmlspecialchars($config['url_path'] . 'plugins/thold/thold_graph.php?action=log&threshold_id=' . $row['id'] . '&status=-1') . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_log.gif' border='0' alt='' title='" . __('View Threshold History') . "'></a>";
            print '</td>';
            print "<td class='left nowrap'>" . ($row['name'] != '' ? $row['name'] : 'No name set') . '</td>';
            print "<td class='right'>" . $row['id'] . '</td>';
            print "<td class='left nowrap'>" . $thold_types[$row['thold_type']] . '</td>';
            print "<td class='right'>" . thold_format_number($row['lastread']) . '</td>';
            print "<td class='right nowrap'>" . ($row['thold_type'] == 1 ? __('N/A') : ($row['thold_type'] == 2 ? thold_format_number($row['time_warning_hi']) . '/' . thold_format_number($row['time_warning_low']) : thold_format_number($row['thold_warning_hi']) . '/' . thold_format_number($row['thold_warning_low']))) . '</td>';
            print "<td class='right'>" . ($row['thold_type'] == 1 ? __('N/A') : ($row['thold_type'] == 2 ? thold_format_number($row['time_hi']) . '/' . thold_format_number($row['time_low']) : thold_format_number($row['thold_hi']) . '/' . thold_format_number($row['thold_low']))) . '</td>';
            print "<td class='right'>" . ($row['thold_type'] == 1 ? $row['bl_pct_up'] . (strlen($row['bl_pct_up']) ? '%' : '-') . '/' . $row['bl_pct_down'] . (strlen($row['bl_pct_down']) ? '%' : '-') : __('N/A')) . '</td>';
            switch ($row['thold_type']) {
                case 0:
                    print "<td class='right nowrap'><i>" . plugin_thold_duration_convert($row['local_data_id'], $row['thold_fail_trigger'], 'alert') . '</i></td>';
                    print "<td class='right'>" . __('N/A') . "</td>";
                    break;
                case 1:
                    print "<td class='right nowrap'><i>" . plugin_thold_duration_convert($row['local_data_id'], $row['bl_fail_trigger'], 'alert') . '</i></td>';
                    print "<td class='right nowrap'>" . $timearray[$row['bl_ref_time_range'] / 300] . '</td>';
                    break;
                case 2:
                    print "<td class='right nowrap'><i>" . $row['time_fail_trigger'] . ' Triggers</i></td>';
                    print "<td class='right nowrap'>" . plugin_thold_duration_convert($row['local_data_id'], $row['time_fail_length'], 'time') . '</td>';
                    break;
                default:
                    print "<td class='right'>" . __('N/A') . "</td>";
                    print "<td class='right'>" . __('N/A') . "</td>";
            }
            print "<td class='right nowrap'>" . ($row['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($row['local_data_id'], $row['repeat_alert'], 'repeat')) . '</td>';
            print "<td class='right'>" . $alertstat . '</td>';
            form_end_row();
        }
    } else {
        print '<tr class="even"><td class="center" colspan="13">' . __('No Thresholds') . '</td></tr>';
    }
    html_end_box(false);
    if (sizeof($tholds)) {
        print $nav;
    }
    thold_legend();
    //thold_display_rusage();
}
Exemplo n.º 3
0
function list_tholds()
{
    global $thold_states, $config, $host_id, $timearray, $thold_types;
    $thold_actions = array(1 => __('Delete'), 2 => __('Disable'), 3 => __('Enable'), 4 => __('Reapply Suggested Names'), 5 => __('Propagate Template'));
    thold_request_validation();
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    $statefilter = '';
    if (isset_request_var('state')) {
        if (get_request_var('state') == '-1') {
            $statefilter = '';
        } else {
            if (get_request_var('state') == '0') {
                $statefilter = "thold_data.thold_enabled='off'";
            }
            if (get_request_var('state') == '2') {
                $statefilter = "thold_data.thold_enabled='on'";
            }
            if (get_request_var('state') == '1') {
                $statefilter = '(thold_data.thold_alert!=0 OR thold_data.bl_alert>0)';
            }
            if (get_request_var('state') == '3') {
                $statefilter = '((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))';
            }
        }
    }
    top_header();
    $sql_where = '';
    $sort = get_request_var('sort_column');
    $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ", {$rows}";
    if (!isempty_request_var('host_id') && get_request_var('host_id') != '-1') {
        $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.host_id = " . get_request_var('host_id');
    }
    if (!isempty_request_var('data_template_id') && get_request_var('data_template_id') != '-1') {
        $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.data_template_id = " . get_request_var('data_template_id');
    }
    if ($statefilter != '') {
        $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "{$statefilter}";
    }
    if ($sql_where != '') {
        $sql_where .= ')';
    }
    $tholds = get_allowed_thresholds($sql_where, $sort . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ", {$rows}", $total_rows);
    $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\tFROM data_template\n\t\tINNER JOIN thold_data \n\t\tON thold_data.data_template_id = data_template.id\n\t\tORDER BY data_template.name");
    html_start_box(__('Threshold Management'), '100%', '', '3', 'center', 'thold.php?action=add');
    ?>
	<tr class='even'>
		<td>
		<form id='listthold' action='thold.php' method='post'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print get_request_var('filter');
    ?>
'>
					</td>
					<?php 
    print html_host_filter(get_request_var('host_id'));
    ?>
					<td>
						<?php 
    print __('Template');
    ?>
					</td>
					<td>
						<select id='data_template_id' onChange='applyFilter()'>
							<option value='-1'><?php 
    print __('Any');
    ?>
</option>
							<?php 
    foreach ($data_templates as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset_request_var('data_template_id') && $row['id'] == get_request_var('data_template_id') ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('State');
    ?>
					</td>
					<td>
						<select id='state' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('state') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('state') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Breached');
    ?>
</option>
							<option value='3'<?php 
    if (get_request_var('state') == '3') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Triggered');
    ?>
</option>
							<option value='2'<?php 
    if (get_request_var('state') == '2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Enabled');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('state') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Disabled');
    ?>
</option>
						</select>
					</td>
					<td>
						<input type='button' id='refresh' value='<?php 
    print __('Go');
    ?>
' title='<?php 
    print __('Apply Filters');
    ?>
' onClick='applyFilter()'>
					</td>
					<td>
						<input type='button' id='clear' value='<?php 
    print __('Clear');
    ?>
' title='<?php 
    print __('Return to Defaults');
    ?>
' onClick='clearFilter()'>
					</td>
				</tr>
			</table>
			<input type='hidden' name='search' value='search'>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL  = 'thold.php?header=false&host_id=' + $('#host_id').val();
			strURL += '&state=' + $('#state').val();
			strURL += '&data_template_id=' + $('#data_template_id').val();
			strURL += '&filter=' + $('#filter').val();
			loadPageNoHeader(strURL);
		}

		function clearFilter() {
			strURL  = 'thold.php?header=false&clear=1';
			loadPageNoHeader(strURL);
		}

		$(function() {
			$('#listthold').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
	
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    $nav = html_nav_bar('thold.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 14, __('Thresholds'), 'page', 'main');
    form_start('thold.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '4', 'center', '');
    $display_text = array('name' => array('display' => __('Name'), 'sort' => 'ASC', 'align' => 'left'), 'id' => array('display' => __('ID'), 'sort' => 'ASC', 'align' => 'right'), 'thold_type' => array('display' => __('Type'), 'sort' => 'ASC', 'align' => 'right'), 'data_source' => array('display' => __('DSName'), 'sort' => 'ASC', 'align' => 'right'), 'lastread' => array('display' => __('Current'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('The last measured value for the Data Source')), 'thold_hi' => array('display' => __('High'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('High Threshold values for Warning/Alert')), 'thold_low' => array('display' => __('Low'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('Low Threshold values for Warning/Alert')), 'nosort3' => array('display' => __('Trigger'), 'sort' => '', 'align' => 'right'), 'nosort4' => array('display' => __('Duration'), 'sort' => '', 'align' => 'right'), 'repeat_alert' => array('display' => __('Repeat'), 'sort' => 'ASC', 'align' => 'right'), 'thold_alert' => array('display' => __('Triggered'), 'sort' => 'ASC', 'align' => 'right'), 'template_enabled' => array('display' => __('Templated'), 'sort' => 'ASC', 'align' => 'right'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
    $c = 0;
    $i = 0;
    if (sizeof($tholds)) {
        foreach ($tholds as $thold_data) {
            $c++;
            $grapharr = db_fetch_row('SELECT DISTINCT graph_templates_item.local_graph_id
				FROM graph_templates_item, data_template_rrd
				WHERE (data_template_rrd.local_data_id=' . $thold_data['local_data_id'] . ' 
				AND data_template_rrd.id=graph_templates_item.task_item_id)');
            $local_graph_id = $grapharr['local_graph_id'];
            $alertstat = __('No');
            $bgcolor = 'green';
            if ($thold_data['thold_type'] == 0) {
                if ($thold_data['thold_alert'] != 0) {
                    $alertstat = __('Yes');
                    if ($thold_data['thold_fail_count'] >= $thold_data['thold_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['thold_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } elseif ($thold_data['thold_type'] == 2) {
                if ($thold_data['thold_alert'] != 0) {
                    $alertstat = __('Yes');
                    if ($thold_data['thold_fail_count'] >= $thold_data['time_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['time_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } else {
                if ($thold_data['bl_alert'] == 1) {
                    $alertstat = __('baseline-LOW');
                    $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow';
                } elseif ($thold_data['bl_alert'] == 2) {
                    $alertstat = __('baseline-HIGH');
                    $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow';
                }
            }
            $data_source = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array($thold_data['data_template_rrd_id']));
            if ($thold_data['thold_enabled'] == 'off') {
                print "<tr class='selectable " . $thold_states['grey']['class'] . "' id='line" . $thold_data['id'] . "'>\n";
            } else {
                print "<tr class='selectable " . $thold_states[$bgcolor]['class'] . "' id='line" . $thold_data['id'] . "'>\n";
            }
            form_selectable_cell(filter_value($thold_data['name'] != '' ? $thold_data['name'] : $thold_data['name_cache'] . ' [' . $thold_data['data_source_name'] . ']', get_request_var('filter'), 'thold.php?action=edit&id=' . $thold_data['id']) . '</a>', $thold_data['id'], '', 'text-align:left');
            form_selectable_cell($thold_data['id'], $thold_data['id'], '', 'text-align:right');
            form_selectable_cell($thold_types[$thold_data['thold_type']], $thold_data['id'], '', 'text-align:right');
            form_selectable_cell($data_source, $thold_data['id'], '', 'text-align:right');
            switch ($thold_data['thold_type']) {
                case 0:
                    form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['thold_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right');
                    break;
                case 1:
                    form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['bl_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell($timearray[$thold_data['bl_ref_time_range'] / 300], $thold_data['id'], '', 'text-align:right');
                    break;
                case 2:
                    form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['time_warning_hi']) . ' / ' . thold_format_number($thold_data['time_hi']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['time_warning_low']) . ' / ' . thold_format_number($thold_data['time_low']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('<i>' . __('%d Triggers', $thold_data['time_fail_trigger']) . '</i>', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['time_fail_length'], 'time') . '</i>', $thold_data['id'], '', 'text-align:right');
                    break;
                default:
                    form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right');
            }
            form_selectable_cell($thold_data['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['repeat_alert'], 'repeat'), $thold_data['id'], '', 'text-align:right');
            form_selectable_cell($alertstat, $thold_data['id'], '', 'text-align:right');
            if ($thold_data['thold_template_id'] != 0) {
                form_selectable_cell($thold_data['template_enabled'] == '' ? __('No') : __('Yes'), $thold_data['id'], '', 'text-align:right');
            } else {
                form_selectable_cell(__('No'), $thold_data['id'], '', 'text-align:right');
            }
            form_checkbox_cell($thold_data['name'], $thold_data['id'], '', 'text-align:left');
            form_end_row();
        }
    } else {
        print "<tr class='even'><td colspan='14'><center>" . __('No Thresholds') . "</center></td></tr>\n";
    }
    html_end_box(false);
    if (sizeof($tholds)) {
        print $nav;
    }
    thold_legend();
    draw_actions_dropdown($thold_actions);
    if (isset($host_id) && $host_id != '') {
        print "<input type='hidden' name='host_id' value='{$host_id}'>";
    }
    form_end();
    bottom_footer();
}