예제 #1
0
function thold_add_select_host()
{
    global $config;
    $host_id = get_filter_request_var('host_id');
    $local_graph_id = get_filter_request_var('local_graph_id');
    $data_template_rrd_id = get_filter_request_var('data_template_rrd_id');
    $hosts = get_allowed_devices();
    top_header();
    form_start('thold.php?action=save', 'tholdform');
    html_start_box(__('Threshold Creation Wizard'), '50%', '', '3', 'center', '');
    if ($host_id == '') {
        print '<tr><td class="center">' . __('Please select a Device') . '</td></tr>';
    } else {
        if ($local_graph_id == '') {
            print '<tr><td class="center">' . __('Please select a Graph') . '</td></tr>';
        } else {
            if ($data_template_rrd_id == '') {
                print '<tr><td class="center">' . __('Please select a Data Source') . '</td></tr>';
            } else {
                print '<tr><td class="center">' . __('Please press \'Create\' to activate your Threshold') . '</td></tr>';
            }
        }
    }
    html_end_box();
    html_start_box('', '50%', '', '3', 'center', '');
    /* display the host dropdown */
    ?>
	<tr><td><table class='filterTable' align='center'>
		<tr>
			<?php 
    print html_host_filter(get_request_var('host_id'));
    ?>
		</tr><?php 
    if ($host_id != '') {
        $graphs = get_allowed_graphs('gl.host_id=' . $host_id);
        ?>
		<tr>
			<td>
				<?php 
        print __('Graph');
        ?>
			</td>
			<td>
				<select id='local_graph_id' name='local_graph_id' onChange='applyFilter("graph")'>
					<option value=''></option><?php 
        foreach ($graphs as $row) {
            echo "<option value='" . $row['local_graph_id'] . "'" . ($row['local_graph_id'] == $local_graph_id ? ' selected' : '') . '>' . htmlspecialchars($row['title_cache'], ENT_QUOTES) . '</option>';
        }
        ?>
				</select>
			</td>
		</tr><?php 
    } else {
        ?>
		<tr>
			<td>
				<input type='hidden' id='local_graph_id' name='local_graph_id' value=''>
			</td>
		</tr><?php 
    }
    if ($local_graph_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 = ' . $local_graph_id;
        $local_data_id = db_fetch_cell($dt_sql);
        $dss = db_fetch_assoc('SELECT DISTINCT id, data_source_name
			FROM data_template_rrd
			WHERE local_data_id IN (' . $dt_sql . ') ORDER BY data_source_name');
        /* show the data source options */
        ?>
		<tr>
			<td>
				<?php 
        print __('Data Source');
        ?>
			</td>
			<td>
				<input type='hidden' id='local_data_id' name='local_data_id' value='<?php 
        print $local_data_id;
        ?>
'>
				<select id='data_template_rrd_id' name='data_template_rrd_id' onChange='applyFilter("ds")'>
					<option value=''></option><?php 
        foreach ($dss as $row) {
            echo "<option value='" . $row['id'] . "'" . ($row['id'] == $data_template_rrd_id ? ' selected' : '') . '>' . htmlspecialchars($row['data_source_name'], ENT_QUOTES) . '</option>';
        }
        ?>
				</select>
			</td>
		</tr></table></td></tr><?php 
    } else {
        ?>
		<tr>
			<td>
				<input type='hidden' id='data_template_rrd_id' name='data_template_rrd_id' value=''>
			</td>
		</tr></table></td></tr><?php 
    }
    if ($data_template_rrd_id != '') {
        echo "<tr><td class='center' colspan='2'><input type='hidden' name='save' id='save' value='save'><input id='go' type='button' value='" . __('Create') . "' title='" . __('Create Threshold') . "'></td></tr>";
    } else {
        echo "<tr><td class='center' colspan='2'></td></tr>";
    }
    html_end_box();
    form_end();
    html_start_box('', '50%', '', '3', 'center', '');
    if ($local_graph_id != '') {
        print "<tr><td style='text-align:center'><img id='graphi' src='../../graph_image.php?local_graph_id={$local_graph_id}&rra_id=0'></td></tr>";
    }
    html_end_box();
    ?>
	<script type='text/javascript'>

	function applyFilter(target) {
		strURL = 'thold.php?action=add&header=false&host_id=' + $('#host_id').val();
		if (target != 'host_id') {
			strURL += '&local_graph_id=' + $('#local_graph_id').val();
		}
		if (target == 'ds') {
			strURL += '&data_template_rrd_id=' + $('#data_template_rrd_id').val();
		}
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#go').button().click(function() {
            strURL = $('#tholdform').attr('action');
            json   = $('input, select').serializeObject();
            $.post(strURL, json).done(function(data) {
                $('#main').html(data);
                applySkin();
                window.scrollTo(0, 0);
            });
		});
	});

	</script>
	<?php 
}
예제 #2
0
파일: auth.php 프로젝트: MrWnn/cacti
function get_host_array()
{
    $hosts = get_allowed_devices();
    foreach ($hosts as $host) {
        $return_devices[] = $host['description'] . ' (' . $host['hostname'] . ')';
    }
    return $return_devices;
}
예제 #3
0
파일: graphs.php 프로젝트: MrWnn/cacti
function ajax_hosts($include_any = true, $include_none = true)
{
    $return = array();
    $term = $_REQUEST['term'];
    $sql_where = "hostname LIKE '%{$term}%' OR description LIKE '%{$term}%' OR notes LIKE '%{$term}%'";
    $hosts = get_allowed_devices($sql_where, 'description', 30);
    if ($_REQUEST['term'] == '') {
        if ($include_any) {
            $return[] = array('label' => 'Any', 'value' => 'Any', 'id' => '-1');
        }
        if ($include_none) {
            $return[] = array('label' => 'None', 'value' => 'None', 'id' => '0');
        }
    }
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            $return[] = array('label' => $host['description'], 'value' => $host['description'], 'id' => $host['id']);
        }
    }
    print json_encode($return);
}
예제 #4
0
function hosts()
{
    global $config, $device_actions, $item_rows;
    /* ================= 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' => 'description', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')), 'host_template_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'host_status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-4'));
    validate_store_request_vars($filters, 'sess_thold_hstatus');
    /* ================= 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(__('Device Status'), '100%', '', '3', 'center', '');
    form_host_filter();
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = '';
    if (get_request_var('filter') != '') {
        $sql_where = "((h.hostname LIKE '%" . get_request_var('filter') . "%' OR h.description LIKE '%" . get_request_var('filter') . "%')";
    }
    if (get_request_var('host_status') == '-1') {
        /* Show all items */
    } elseif (get_request_var('host_status') == '-2') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "h.disabled='on'";
    } elseif (get_request_var('host_status') == '-3') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "h.disabled=''";
    } elseif (get_request_var('host_status') == '-4') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "(h.status!='3' OR h.disabled='on')";
    } elseif (get_request_var('host_status') == '-5') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "(h.availability_method=0)";
    } elseif (get_request_var('host_status') == '3') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "(h.availability_method!=0 AND h.status=3 AND h.disabled='')";
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "(h.status=" . get_request_var('host_status') . " AND h.disabled = '')";
    }
    if (get_request_var('host_template_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('host_template_id') == '0') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "h.host_template_id=0'";
    } elseif (!isempty_request_var('host_template_id')) {
        $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "h.host_template_id=" . get_request_var('host_template_id');
    }
    $sql_where .= strlen($sql_where) ? ')' : '';
    $sortby = get_request_var('sort_column');
    if ($sortby == 'hostname') {
        $sortby = 'INET_ATON(hostname)';
    }
    $host_graphs = array_rekey(db_fetch_assoc('SELECT host_id, count(*) as graphs FROM graph_local GROUP BY host_id'), 'host_id', 'graphs');
    $host_data_sources = array_rekey(db_fetch_assoc('SELECT host_id, count(*) as data_sources FROM data_local GROUP BY host_id'), 'host_id', 'data_sources');
    $hosts = get_allowed_devices($sql_where, $sortby . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ',' . $rows, $total_rows);
    $nav = html_nav_bar('thold_graph.php?action=hoststat', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 12, __('Devices'), 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('nosort' => array('display' => __('Actions'), 'align' => 'left', 'sort' => '', 'tip' => __('Hover over icons for help')), 'description' => array('display' => __('Description'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('A description for the Device')), 'id' => array('display' => __('ID'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('A Cacti unique identifier for the Device')), 'nosort1' => array('display' => __('Graphs'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The number of Graphs for this Device')), 'nosort2' => array('display' => __('Data Sources'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The number of Data Sources for this Device')), 'status' => array('display' => __('Status'), 'align' => 'center', 'sort' => 'ASC', 'tip' => __('The status for this Device as of the last time it was polled')), 'nosort3' => array('display' => __('In State'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The last time Cacti found an issues with this Device.  It can be higher than the Uptime for the the Device, if it was rebooted between Cacti polling cycles')), 'snmp_sysUpTimeInstance' => array('display' => __('Uptime'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The official uptime of the Device as reported by SNMP')), 'hostname' => array('display' => __('Hostname'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The official hostname for this Device')), 'cur_time' => array('display' => __('Current (ms)'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The current response time for the Cacti Availability check')), 'avg_time' => array('display' => __('Average (ms)'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The average response time for the Cacti Availability check')), 'availability' => array('display' => __('Availability'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The overall Availability of this Device since the last counter reset in Cacti')));
    html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'thold_graph.php?action=hoststat');
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            if ($host['disabled'] == '' && ($host['status'] == HOST_RECOVERING || $host['status'] == HOST_UP) && ($host['availability_method'] != AVAIL_NONE && $host['availability_method'] != AVAIL_PING)) {
                $snmp_uptime = $host['snmp_sysUpTimeInstance'];
                $days = intval($snmp_uptime / (60 * 60 * 24 * 100));
                $remainder = $snmp_uptime % (60 * 60 * 24 * 100);
                $hours = intval($remainder / (60 * 60 * 100));
                $remainder = $remainder % (60 * 60 * 100);
                $minutes = intval($remainder / (60 * 100));
                $uptime = $days . 'd:' . substr('00' . $hours, -2) . 'h:' . substr('00' . $minutes, -2) . 'm';
            } else {
                $uptime = __('N/A');
            }
            if (isset($host_graphs[$host['id']])) {
                $graphs = $host_graphs[$host['id']];
            } else {
                $graphs = 0;
            }
            if (isset($host_data_sources[$host['id']])) {
                $ds = $host_data_sources[$host['id']];
            } else {
                $ds = 0;
            }
            if ($host['availability_method'] != 0) {
                form_host_status_row_color($host['status'], $host['disabled']);
                print "<td width='1%' class='nowrap'>";
                if (api_user_realm_auth('host.php')) {
                    print '<a href="' . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $host['id']) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/edit_object.png" border="0" alt="" title="' . __('Edit Device') . '"></a>';
                }
                print "<a href='" . htmlspecialchars($config['url_path'] . 'graph_view.php?action=preview&graph_template_id=0&filter=&host_id=' . $host['id']) . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_graphs.gif' border='0' alt='' title='" . __('View Graphs') . "'></a>";
                print '</td>';
                ?>
				<td style='text-align:left'>
					<?php 
                print filter_value($host['description'], get_request_var('filter'));
                ?>
				</td>
				<td style='text-align:right'><?php 
                print round($host['id'], 2);
                ?>
</td>
				<td style='text-align:right'><i><?php 
                print number_format_i18n($graphs);
                ?>
</i></td>
				<td style='text-align:right'><i><?php 
                print number_format_i18n($ds);
                ?>
</i></td>
				<td style='text-align:center'><?php 
                print get_uncolored_device_status($host['disabled'] == 'on' ? true : false, $host['status']);
                ?>
</td>
				<td style='text-align:right'><?php 
                print get_timeinstate($host);
                ?>
</td>
				<td style='text-align:right'><?php 
                print $uptime;
                ?>
</td>
				<td style='text-align:right'><?php 
                print filter_value($host['hostname'], get_request_var('filter'));
                ?>
</td>
				<td style='text-align:right'><?php 
                print round($host['cur_time'], 2);
                ?>
</td>
				<td style='text-align:right'><?php 
                print round($host['avg_time'], 2);
                ?>
</td>
				<td style='text-align:right'><?php 
                print round($host['availability'], 2);
                ?>
 %</td>
				<?php 
            } else {
                print "<tr class='deviceNotMonFull'>\n";
                print "<td width='1%' class='nowrap'>\n";
                if (api_user_realm_auth('host.php')) {
                    print '<a href="' . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $host["id"]) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/edit_object.png" border="0" alt="" title="' . __('Edit Device') . '"></a>';
                }
                print "<a href='" . htmlspecialchars($config['url_path'] . "graph_view.php?action=preview&graph_template_id=0&filter=&host_id=" . $host["id"]) . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_graphs.gif' border='0' alt='' title='" . __('View Graphs') . "'></a>";
                print "</td>";
                ?>
				<td style='text-align:left'>
					<?php 
                print filter_value($host['description'], get_request_var('filter'));
                ?>
				</td>
				<td style='text-align:right'><?php 
                print $host['id'];
                ?>
</td>
				<td style='text-align:right'><i><?php 
                print number_format_i18n($graphs);
                ?>
</i></td>
				<td style='text-align:right'><i><?php 
                print number_format_i18n($ds);
                ?>
</i></td>
				<td style='text-align:center'><?php 
                print 'Not Monitored';
                ?>
</td>
				<td style='text-align:right'><?php 
                print 'N/A';
                ?>
</td>
				<td style='text-align:right'><?php 
                print $uptime;
                ?>
</td>
				<td style='text-align:right'><?php 
                print filter_value($host['hostname'], get_request_var('filter'));
                ?>
</td>
				<td style='text-align:right'><?php 
                print 'N/A';
                ?>
</td>
				<td style='text-align:right'><?php 
                print 'N/A';
                ?>
</td>
				<td style='text-align:right'><?php 
                print 'N/A';
                ?>
</td>
				<?php 
            }
            form_end_row();
        }
    } else {
        print '<tr><td class="center" colspan="12">' . __('No Devices') . '</td></tr>';
    }
    html_end_box(false);
    if (sizeof($hosts)) {
        print $nav;
    }
    host_legend();
    //thold_display_rusage();
}
예제 #5
0
파일: graph_view.php 프로젝트: MrWnn/cacti
			<table cellpadding='2' cellspacing='0' border='0'>
				<tr class='noprint'>
					<td width='50'>
						Device
					</td>
					<td>
						<select id='host_id' name='host_id' onChange='applyFilter()'>
							<option value='0'<?php 
        if (get_request_var_request('host_id') == '0') {
            ?>
 selected<?php 
        }
        ?>
>Any</option>
							<?php 
        $hosts = get_allowed_devices();
        if (sizeof($hosts) > 0) {
            foreach ($hosts as $host) {
                print "<option value='" . $host['id'] . "'";
                if (get_request_var_request('host_id') == $host['id']) {
                    print ' selected';
                }
                print '>' . htmlspecialchars($host['description']) . "</option>\n";
            }
        }
        ?>
						</select>
					</td>
					<td>
						Template
					</td>