__('Disabled'),
1 => __('Low'),
2 => __('Medium'),
3 => __('High'),
4 => __('Mission Critical')
);
$iclasses = array(
0 => 'deviceUnknown',
1 => 'deviceDown',
2 => 'deviceRecovering',
3 => 'deviceUp',
4 => 'deviceThreshold',
5 => 'deviceDownMuted',
6 => 'deviceUnmonitored',
7 => 'deviceWarning',
8 => 'deviceAlert',
);
$icolorsdisplay = array(
0 => __('Unknown'),
1 => __('Down'),
2 => __('Recovering'),
3 => __('Up'),
4 => __('Triggered'),
5 => __('Down (Muted/Acked)'),
6 => __('No Availability Check'),
7 => __('Warning Ping'),
8 => __('Alert Ping'),
);
$classes = array(
'monitor_exsmall' => __('Extra Small'),
'monitor_small' => __('Small'),
'monitor_medium' => __('Medium'),
'monitor_large' => __('Large')
);
global $thold_alerts, $thold_hosts;
if (!isset($_SESSION['muted_hosts'])) {
$_SESSION['muted_hosts'] = array();
}
validate_request_vars(true);
check_tholds();
switch(get_nfilter_request_var('action')) {
case 'ajax_status':
ajax_status();
break;
case 'ajax_mute_all':
mute_all_hosts();
draw_page();
break;
case 'ajax_unmute_all':
unmute_all_hosts();
draw_page();
break;
case 'save':
save_settings();
break;
default:
draw_page();
}
exit;
function draw_page() {
global $config, $iclasses, $icolorsdisplay;
find_down_hosts();
general_header();
draw_filter_and_status();
if (file_exists($config['base_path'] . '/plugins/monitor/themes/' . get_selected_theme() . '/monitor.css')) {
print " \n";
}else{
print " \n";
}
print "
\n";
// Default with permissions = default_by_permissions
// Tree = group_by_tree
$function = 'render_' . get_request_var('grouping');
if (function_exists($function)) {
print $function();
} else {
print render_default();
}
print '
';
if (read_user_setting('monitor_legend', read_config_option('monitor_legend'))) {
print "\n";
foreach($iclasses as $index => $class) {
print "" . $icolorsdisplay[$index] . " \n";
}
print "
\n";
}
// If the host is down, we need to insert the embedded wav file
$monitor_sound = get_monitor_sound();
if (is_monitor_audible()) {
print " \n";
}
?>
0 AND thold_enabled = "on"', FALSE);
if (count($result)) {
foreach ($result as $row) {
$thold_alerts[] = $row['rra_id'];
}
if (count($thold_alerts) > 0) {
$result = db_fetch_assoc('SELECT id, host_id FROM data_local');
foreach ($result as $h) {
if (in_array($h['id'], $thold_alerts)) {
$thold_hosts[] = $h['host_id'];
}
}
}
}
}
}
function get_filter_text() {
$filter = '';
switch(get_request_var('status')) {
case '-1':
$filter = __('All Monitored Devices');
break;
case '0':
$filter = __('Monitored Devices either Down or Recovering');
break;
case '1':
$filter = __('Monitored Devices either Down, Recovering, with Breached Thresholds');
break;
}
switch(get_request_var('crit')) {
case '0':
$filter .= __(', and All Criticalities');
break;
case '1':
$filter .= __(', and of Low Criticality or Higher');
break;
case '2':
$filter .= __(', and of Medium Criticality or Higher');
break;
case '3':
$filter .= __(', and of High Criticality or Higher');
break;
case '4':
$filter .= __(', and of Mission Critical Status');
break;
}
$filter .= __('Remember to first select eligible Devices to be Monitored from the Devices page! ');
return $filter;
}
function draw_filter_and_status() {
global $criticalities, $page_refresh_interval, $classes;
print '
' . NL;
// Display the Current Time
print 'Filter Settings Saved
';
print '' . __('Last Refresh: %s', date('g:i:s a', time())) . (get_request_var('refresh') < 99999 ? ', ' . __('Refresh Again in %d Seconds', get_request_var('refresh')):'') . '
';
print '' . get_filter_text() . '
';
}
function get_mute_text() {
if (is_monitor_audible()) {
return __('Mute');
} else {
return __('Acknowledge');
}
}
function get_unmute_text() {
if (is_monitor_audible()) {
return __('Un-Mute');
} else {
return __('Reset');
}
}
function save_settings() {
validate_request_vars();
if (sizeof($_REQUEST)) {
foreach($_REQUEST as $var => $value) {
switch($var) {
case 'refresh':
set_user_setting('monitor_refresh', get_request_var('refresh'));
break;
case 'grouping':
set_user_setting('monitor_grouping', get_request_var('grouping'));
break;
case 'view':
set_user_setting('monitor_view', get_request_var('view'));
break;
case 'crit':
set_user_setting('monitor_crit', get_request_var('crit'));
break;
case 'mute':
set_user_setting('monitor_mute', get_request_var('mute'));
break;
case 'size':
set_user_setting('monitor_size', get_request_var('size'));
break;
case 'status':
set_user_setting('monitor_status', get_request_var('status'));
break;
case 'tree':
set_user_setting('monitor_tree', get_request_var('tree'));
break;
}
}
}
validate_request_vars(true);
}
function validate_request_vars($force = false) {
/* ================= input validation and session storage ================= */
$filters = array(
'refresh' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_user_setting('monitor_refresh', read_config_option('monitor_refresh'), $force)
),
'mute' => array(
'filter' => FILTER_CALLBACK,
'options' => array('options' => 'sanitize_search_string'),
'default' => read_user_setting('monitor_mute', 'false', $force)
),
'grouping' => array(
'filter' => FILTER_CALLBACK,
'options' => array('options' => 'sanitize_search_string'),
'default' => read_user_setting('monitor_grouping', read_config_option('monitor_grouping'), $force)
),
'view' => array(
'filter' => FILTER_CALLBACK,
'options' => array('options' => 'sanitize_search_string'),
'default' => read_user_setting('monitor_view', read_config_option('monitor_view'), $force)
),
'size' => array(
'filter' => FILTER_CALLBACK,
'options' => array('options' => 'sanitize_search_string'),
'default' => read_user_setting('monitor_size', 'monior_medium', $force)
),
'crit' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_user_setting('monitor_crit', '-1', $force)
),
'status' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_user_setting('monitor_status', '-1', $force)
),
'tree' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_user_setting('monitor_tree', '-1', $force)
),
'id' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_monitor');
/* ================= input validation ================= */
}
function render_where_join(&$sql_where, &$sql_join) {
if (get_request_var('crit') > 0) {
$crit = ' AND h.monitor_criticality>=' . get_request_var('crit');
} else {
$crit = '';
}
if (get_request_var('status') == '0') {
$sql_join = '';
$sql_where = 'WHERE h.disabled = ""
AND h.monitor = "on"
AND h.status < 3
AND (availability_method>0
OR snmp_version>0
OR (cur_time >= monitor_warn
AND monitor_warn > 0)
OR (cur_time >= monitor_alert
AND monitor_alert > 0)
)' . $crit;
}elseif (get_request_var('status') == '1') {
$sql_join = 'LEFT JOIN thold_data AS td ON td.host_id=h.id';
$sql_where = 'WHERE h.disabled = ""
AND h.monitor = "on"
AND (h.status < 3
OR (td.thold_enabled="on" AND td.thold_alert>0)
OR ((availability_method>0 OR snmp_version>0)
AND ((cur_time > monitor_warn AND monitor_warn > 0)
OR (cur_time > monitor_alert AND monitor_alert > 0))
))' . $crit;
} else {
$sql_join = 'LEFT JOIN thold_data AS td ON td.host_id=h.id';
$sql_where = 'WHERE h.disabled = ""
AND h.monitor = "on"
AND (availability_method>0 OR snmp_version>0
OR (td.thold_enabled="on" AND td.thold_alert>0)
)' . $crit;
}
}
/* Render functions */
function render_default() {
$result = '';
$sql_where = '';
$sql_join = '';
render_where_join($sql_where, $sql_join);
$hosts = db_fetch_assoc("SELECT DISTINCT h.*
FROM host AS h
$sql_join
$sql_where
ORDER BY description");
if (sizeof($hosts)) {
// Determine the correct width of the cell
$maxlen = db_fetch_cell("SELECT MAX(LENGTH(description))
FROM host AS h
$sql_join
$sql_where");
foreach($hosts as $host) {
$result .= render_host($host, true, $maxlen);
}
}
return $result;
}
function render_perms() {
global $row_stripe;
// Get the list of allowed devices first
$hosts = get_allowed_devices();
if (sizeof($hosts)) {
foreach($hosts as $host) {
$host_ids[] = $host['id'];
}
$sql_where = '';
$sql_join = '';
render_where_join($sql_where, $sql_join);
// Now query for the hosts in that list that should be displayed
$hosts = db_fetch_assoc("SELECT DISTINCT h.*
FROM host AS h
$sql_join
$sql_where
AND h.id IN(" . implode(',', $host_ids) . ")
ORDER BY description");
// Determine the correct width of the cell
$maxlen = db_fetch_cell("SELECT MAX(LENGTH(description))
FROM host AS h
WHERE id IN (" . implode(',', $host_ids) . ")");
foreach ($host as $host) {
$result .= render_host($host, true, $maxlen);
}
}
return $result;
}
function render_template() {
$result = '';
$sql_where = '';
$sql_join = '';
render_where_join($sql_where, $sql_join);
$hosts = db_fetch_assoc("SELECT DISTINCT
h.*, ht.name AS host_template_name
FROM host AS h
INNER JOIN host_template AS ht
ON h.host_template_id=ht.id
$sql_join
$sql_where
ORDER BY ht.name, h.description");
$ctemp = -1;
$ptemp = -1;
if (get_request_var('view') == 'tiles') {
$offset = 0;
$offset2 = 0;
} else {
$offset = 52;
$offset2 = 38;
}
if (sizeof($hosts)) {
foreach($hosts as $host) {
$host_ids[] = $host['id'];
}
// Determine the correct width of the cell
$maxlen = db_fetch_cell("SELECT MAX(LENGTH(description))
FROM host AS h
WHERE id IN (" . implode(',', $host_ids) . ")");
$class = get_request_var('size');
foreach($hosts as $host) {
$ctemp = $host['host_template_id'];
if ($ctemp != $ptemp && $ptemp > 0) {
$result .= "\n";
}
if ($ctemp != $ptemp) {
$result .= "\n";
}
$result .= render_host($host, true, $maxlen);
if ($ctemp != $ptemp) {
$ptemp = $ctemp;
}
}
if ($ptemp == $ctemp) {
$result .= "
\n";
}
}
return $result;
}
function render_tree() {
$result = '';
$leafs = array();
if (get_request_var('tree') > 0) {
$sql_where = 'gt.id=' . get_request_var('tree');
} else {
$sql_where = '';
}
if (get_request_var('tree') != -2) {
$tree_list = get_allowed_trees(false, false, $sql_where);
} else {
$tree_list = array();
}
if (sizeof($tree_list)) {
$ptree = '';
foreach($tree_list as $tree) {
$tree_ids[$tree['id']] = $tree['id'];
}
$branchWhost = db_fetch_assoc("SELECT DISTINCT gti.graph_tree_id, gti.parent
FROM graph_tree_items AS gti
WHERE gti.host_id>0
AND gti.parent > 0
AND gti.graph_tree_id IN (" . implode(',', $tree_ids) . ")
ORDER BY gti.graph_tree_id");
if (sizeof($branchWhost)) {
foreach($branchWhost as $b) {
$titles[$b['graph_tree_id'] . ':' . $b['parent']] = db_fetch_cell_prepared('SELECT title
FROM graph_tree_items
WHERE id = ? AND graph_tree_id = ?',
array($b['parent'], $b['graph_tree_id']));
}
asort($titles);
foreach($titles as $index => $title) {
list($graph_tree_id, $parent) = explode(':', $index);
$oid = $parent;
$sql_where = '';
$sql_join = '';
render_where_join($sql_where, $sql_join);
$hosts = db_fetch_assoc_prepared("SELECT DISTINCT h.*
FROM host AS h
INNER JOIN graph_tree_items AS gti
ON h.id=gti.host_id
$sql_join
$sql_where
AND parent = ?", array($oid));
if (sizeof($hosts)) {
foreach($hosts as $host) {
$host_ids[] = $host['id'];
}
$class = get_request_var('size');
// Determine the correct width of the cell
$maxlen = db_fetch_cell("SELECT MAX(LENGTH(description))
FROM host AS h
WHERE id IN (" . implode(',', $host_ids) . ")");
$tree_name = db_fetch_cell_prepared('SELECT name FROM graph_tree WHERE id = ?', array($b['graph_tree_id']));
if ($ptree != $tree_name) {
if ($ptree != '') {
$result .= '';
}
$result .= '';
$ptree = $tree_name;
}
$title = $title !='' ? $title:'Root Folder';
$result .= '
';
foreach($hosts as $host) {
$result .= render_host($host, true, $maxlen);
}
$result .= '
';
}
}
}
$result .= '
';
}
/* begin others - lets get the monitor items that are not associated with any tree */
if (get_request_var('tree') < 0) {
$hosts = get_host_non_tree_array();
if (sizeof($hosts)) {
foreach($hosts as $host) {
$host_ids[] = $host['id'];
}
// Determine the correct width of the cell
if (sizeof($host_ids)) {
$maxlen = db_fetch_cell("SELECT MAX(LENGTH(description))
FROM host AS h
WHERE id IN (" . implode(',', $host_ids) . ")");
}else{
$maxlen = 100;
}
$result .= '';
foreach($hosts as $leaf) {
$result .= render_host($leaf, true, $maxlen);
}
$result .= '
';
}
}
return $result;
}
/* Branch rendering */
function render_branch($leafs, $title = '') {
global $render_style;
global $row_stripe;
$row_stripe=false;
if ($title == '') {
foreach ($leafs as $row) {
/* get our proper branch title */
$title = $row['branch_name'];
break;
}
}
if ($title == '') {
/* Insert a default title */
$title = 'Items';
$title .= ' (' . sizeof($leafs) . ')';
}
//$branch_percentup = '%' . leafs_percentup($leafs);
//$title .= " - $branch_percentup";
/* select function to render here */
$function = "render_branch_$render_style";
if (function_exists($function)) {
/* Call the custom render_branch_ function */
return $function($leafs, $title);
} else {
return render_branch_tree($leafs, $title);
}
}
function get_host_status($host) {
/* If the host has been muted, show the muted Icon */
if (in_array($host['id'], $_SESSION['muted_hosts']) && $host['status'] == 1) {
$host['status'] = 5;
}elseif ($host['status'] == 3) {
if ($host['cur_time'] > $host['monitor_alert'] && !empty($host['monitor_alert'])) {
$host['status'] = 8;
}elseif ($host['cur_time'] > $host['monitor_warn'] && !empty($host['monitor_warn'])) {
$host['status'] = 7;
}
}
return $host['status'];
}
/*Single host rendering */
function render_host($host, $float = true, $maxlen = 0) {
global $thold, $thold_hosts, $config, $icolorsdisplay, $iclasses, $classes;
//throw out tree root items
if (array_key_exists('name', $host)) {
return;
}
if (!is_device_allowed($host['id'])) {
return;
}
if ($host['id'] <= 0) {
return;
}
$host['anchor'] = $config['url_path'] . 'graph_view.php?action=preview&reset=1&host_id=' . $host['id'];
if ($thold) {
if ($host['status'] == 3 && in_array($host['id'], $thold_hosts)) {
$host['status'] = 4;
if (file_exists($config['base_path'] . '/plugins/thold/thold_graph.php')) {
$host['anchor'] = $config['url_path'] . 'plugins/thold/thold_graph.php';
} else {
$host['anchor'] = $config['url_path'] . 'plugins/thold/graph_thold.php';
}
}
}
$host['status'] = get_host_status($host);
$host['iclass'] = $iclasses[$host['status']];
$dt = '';
if ($host['status'] < 2 || $host['status'] == 5) {
$dt = monitor_print_host_time($host['status_fail_date']);
}
$function = 'render_host_' . get_request_var('view');
if (function_exists($function)) {
/* Call the custom render_host_ function */
$result = $function($host);
} else {
$iclass = get_status_icon($host['status']);
$fclass = get_request_var('size');
if ($host['status'] <= 2 || $host['status'] == 5) {
$result = "\n";
} else {
$result = "\n";
}
}
return $result;
}
function get_status_icon($status) {
if ($status == 1 && read_user_setting('monitor_sound') == 'First Orders Suite.mp3') {
return 'fa-first-order fa-spin';
} else {
return 'fa-server';
}
}
function monitor_print_host_time($status_time, $seconds = false) {
// If the host is down, make a downtime since message
$dt = '';
if (is_numeric($status_time)) {
$sfd = round($status_time / 100,0);
} else {
$sfd = time() - strtotime($status_time);
}
$dt_d = floor($sfd/86400);
$dt_h = floor(($sfd - ($dt_d * 86400))/3600);
$dt_m = floor(($sfd - ($dt_d * 86400) - ($dt_h * 3600))/60);
$dt_s = $sfd - ($dt_d * 86400) - ($dt_h * 3600) - ($dt_m * 60);
if ($dt_d > 0 ) {
$dt .= $dt_d . 'd:' . $dt_h . 'h:' . $dt_m . 'm' . ($seconds ? ':' . $dt_s . 's':'');
} else if ($dt_h > 0 ) {
$dt .= $dt_h . 'h:' . $dt_m . 'm' . ($seconds ? ':' . $dt_s . 's':'');
} else if ($dt_m > 0 ) {
$dt .= $dt_m . 'm' . ($seconds ? ':' . $dt_s . 's':'');;
} else {
$dt .= ($seconds ? $dt_s . 's':__('Just Up'));
}
return $dt;
}
function ajax_status() {
global $thold, $thold_hosts, $config, $icolorsdisplay, $iclasses, $criticalities;
if (isset_request_var('id') && get_filter_request_var('id')) {
$id = get_request_var('id');
$host = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($id));
$host['anchor'] = $config['url_path'] . 'graph_view.php?action=preview&reset=1&host_id=' . $host['id'];
if ($thold) {
if ($host['status'] == 3 && in_array($host['id'], $thold_hosts)) {
$host['status'] = 4;
if (file_exists($config['base_path'] . '/plugins/thold/thold_graph.php')) {
$host['anchor'] = $config['url_path'] . 'plugins/thold/thold_graph.php';
} else {
$host['anchor'] = $config['url_path'] . 'plugins/thold/graph_thold.php';
}
}
}
if ($host['availability_method'] == 0) {
$host['status'] = 6;
}
$host['status'] = get_host_status($host);
if (sizeof($host)) {
if (api_plugin_user_realm_auth('host.php')) {
$host_link = htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $host['id']);
}
// Get the number of graphs
$graphs = db_fetch_cell_prepared('SELECT count(*) FROM graph_local WHERE host_id = ?', array($host['id']));
if ($graphs > 0) {
$graph_link = htmlspecialchars($config['url_path'] . 'graph_view.php?action=preview&reset=1&host_id=' . $host['id']);
}
// Get the number of thresholds
if (api_plugin_is_enabled('thold')) {
$tholds = db_fetch_cell_prepared('SELECT count(*) FROM thold_data WHERE host_id = ?', array($host['id']));
if ($tholds > 0) {
$thold_link = htmlspecialchars($config['url_path'] . 'plugins/thold/thold_graph.php?action=thold&reset=1&status=-1&host_id=' . $host['id']);
}
} else {
$tholds = 0;
}
// Get the number of syslogs
if (api_plugin_is_enabled('syslog') && api_plugin_user_realm_auth('syslog.php')) {
include($config['base_path'] . '/plugins/syslog/config.php');
include_once($config['base_path'] . '/plugins/syslog/functions.php');
$syslog_logs = syslog_db_fetch_cell_prepared('SELECT count(*) FROM syslog_logs WHERE host = ?', array($host['hostname']));
$syslog_host = syslog_db_fetch_cell_prepared('SELECT host_id FROM syslog_hosts WHERE host = ?', array($host['hostname']));
if ($syslog_logs && $syslog_host) {
$syslog_log_link = htmlspecialchars($config['url_path'] . 'plugins/syslog/syslog/syslog.php?reset=1&tab=alerts&host_id=' . $syslog_host);
}
if ($syslog_host) {
$syslog_link = htmlspecialchars($config['url_path'] . 'plugins/syslog/syslog/syslog.php?reset=1&tab=syslog&host_id=' . $syslog_host);
}
} else {
$syslog_logs = 0;
$syslog_host = 0;
}
$links = '';
if (isset($host_link)) {
$links .= '' . __('Edit Device') . ' ';
}
if (isset($graph_link)) {
$links .= ($links != '' ? ', ':'') . '' . __('View Graphs') . ' ';
}
if (isset($thold_link)) {
$links .= ($links != '' ? ', ':'') . '' . __('View Thresholds') . ' ';
}
if (isset($syslog_log_link)) {
$links .= ($links != '' ? ', ':'') . '' . __('View Syslog Alerts') . ' ';
}
if (isset($syslog_link)) {
$links .= ($links != '' ? ', ':'') . '' . __('View Syslog Messages') . ' ';
}
$iclass = $iclasses[$host['status']];
$sdisplay = $icolorsdisplay[$host['status']];
print "
" . __('Device:') . "
" . $host['description'] . "
" . (isset($host['monitor_criticality']) && $host['monitor_criticality'] > 0 ? "
" . __('Criticality:') . "
" . $criticalities[$host['monitor_criticality']] . "
":"") . "
" . __('Status:') . "
$sdisplay
" . ($host['status'] < 3 || $host['status'] == 5 ? "
" . __('Admin Note:') . "
" . $host['monitor_text'] . "
":"") . ($host['availability_method'] > 0 ? "
" . __('IP/Hostname:') . "
" . $host['hostname'] . "
":"") . ($host['notes'] != '' ? "
" . __('Notes:') . "
" . $host['notes'] . "
":"") . (($graphs || $syslog_logs || $syslog_host || $tholds) ? "
" . __('Links:') . "
" . $links . "
":"") . ($host['availability_method'] > 0 ? "
" . __('Curr/Avg:') . "
" . __('%d ms', $host['cur_time']) . ' / ' . __('%d ms', $host['avg_time']) . "
":"") . (isset($host['monitor_warn']) && ($host['monitor_warn'] > 0 || $host['monitor_alert'] > 0) ? "
" . __('Warn/Alert:') . "
" . __('%0.2d ms', $host['monitor_warn']) . ' / ' . __('%0.2d ms', $host['monitor_alert']) . "
":"") . "
" . __('Last Fail:') . "
" . $host['status_fail_date'] . "
" . __('Time In State:') . "
" . get_timeinstate($host) . "
" . __('Availability:') . "
" . round($host['availability'],2) . " %
" . ($host['snmp_version'] > 0 && ($host['status'] == 3 || $host['status'] == 2) ? "
" . __('Agent Uptime:') . "
" . ($host['status'] == 3 || $host['status'] == 5 ? monitor_print_host_time($host['snmp_sysUpTimeInstance']):'N/A') . "
" . __('Sys Description:') . "
" . $host['snmp_sysDescr'] . "
" . __('Location:') . "
" . $host['snmp_sysLocation'] . "
" . __('Contact:') . "
" . $host['snmp_sysContact'] . "
":"") . "
\n";
}
}
}
function render_host_tiles($host) {
$class = get_status_icon($host['status']);
$fclass = get_request_var('size');
if (!is_device_allowed($host['id'])) {
return;
}
$result = "
";
return $result;
}
function render_host_tilesadt($host) {
$dt = '';
if (!is_device_allowed($host['id'])) {
return;
}
$class = get_status_icon($host['status']);
$fclass = get_request_var('size');
if ($host['status'] < 2 || $host['status'] == 5) {
$dt = monitor_print_host_time($host['status_fail_date']);
$result = "
\n";
return $result;
} else {
if ($host['status_rec_date'] != '0000-00-00 00:00:00') {
$dt = monitor_print_host_time($host['status_rec_date']);
} else {
$dt = __('Never');
}
$result = "
\n";
return $result;
}
}
function get_hosts_down_by_permission() {
global $render_style;
$result = array();
if (get_request_var('crit') > 0) {
$sql_add_where = ' AND monitor_criticality >= ' . get_request_var('crit');
}else{
$sql_add_where = '';
}
if (get_request_var('grouping') == 'tree') {
if (get_request_var('tree') > 0) {
$devices = db_fetch_cell_prepared('SELECT GROUP_CONCAT(host_id) AS hosts
FROM graph_tree_items
WHERE host_id > 0
AND graph_tree_id = ?',
array(get_request_var('tree')));
$sql_add_where .= ' AND h.id IN(' . $devices . ')';
}
}
if ($render_style == 'default') {
$hosts = get_allowed_devices("h.monitor='on' $sql_add_where AND h.disabled='' AND h.status < 2 AND (h.availability_method>0 OR h.snmp_version>0)");
// do a quick loop through to pull the hosts that are down
if (sizeof($hosts)) {
foreach($hosts as $host) {
$host_down = true;
$result[] = $host['id'];
sort($result);
}
}
} else {
/* Only get hosts */
$hosts = get_allowed_devices("h.monitor='on' $sql_add_where AND h.disabled='' AND h.status < 2 AND (h.availability_method>0 OR h.snmp_version>0)");
if (sizeof($hosts) > 0) {
foreach ($hosts as $host) {
$host_down = true;
$result[] = $host['id'];
sort($result);
}
}
}
return $result;
}
function get_host_tree_array() {
return $leafs;
}
function get_host_non_tree_array() {
$leafs = array();
$sql_where = '';
$sql_join = '';
render_where_join($sql_where, $sql_join);
//$sql_where .= " AND ((host.disabled = '' AND host.monitor = 'on' AND (host.availability_method>0 OR host.snmp_version>0)) OR (title != ''))";
$heirarchy = db_fetch_assoc("SELECT DISTINCT
h.*, gti.title, gti.host_id, gti.host_grouping_type, gti.graph_tree_id
FROM host AS h
LEFT JOIN graph_tree_items AS gti
ON h.id=gti.host_id
$sql_join
$sql_where
AND gti.graph_tree_id IS NULL
ORDER BY h.description");
if (sizeof($heirarchy) > 0) {
$leafs = array();
$branchleafs = 0;
foreach ($heirarchy as $leaf) {
$leafs[$branchleafs] = $leaf;
$branchleafs++;
}
}
return $leafs;
}
/* Supporting functions */
function get_status_color($status=3) {
$color = '#183C8F';
switch ($status) {
case 0: //error
$color = '#993333';
break;
case 1: //error
$color = '#993333';
break;
case 2: //recovering
$color = '#7293B9';
break;
case 3: //ok
$color = '#669966';
break;
case 4: //threshold
$color = '#c56500';
break;
case 5: //muted
$color = '#996666';
break;
default: //unknown
$color = '#999999';
break;
}
return $color;
}
function leafs_status_min($leafs) {
global $thold;
global $thold_hosts;
$thold_breached = 0;
$result = 3;
foreach ($leafs as $row) {
$status = intval($row['status']);
if ($result > $status) {
$result = $status;
}
if ($thold) {
if ($status == 3 && in_array($row['id'], $thold_hosts)) {
$thold_breached = 1;
}
}
}
if ($result == 3 && $thold_breached) {
$result = 4;
}
return $result;
}
function leafs_percentup($leafs) {
$result = 0;
$countup = 0;
$count = sizeof($leafs);
foreach ($leafs as $row) {
$status = intval($row['status']);
if ($status >= 3) {
$countup++;
}
}
if ($countup>=$count){
return 100;
}
$result = round($countup/$count*100,0);
return $result;
}