move and optimize away some sql queries, remove obsolete code

git-svn-id: http://www.observium.org/svn/observer/trunk@2638 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-10-03 13:40:37 +00:00
parent 95bc8e3eef
commit 16a0989316
7 changed files with 51 additions and 47 deletions

View File

@@ -3,33 +3,11 @@
$service_alerts = dbFetchCell("SELECT COUNT(service_id) FROM services WHERE service_status = '0'");
$if_alerts = dbFetchCell("SELECT COUNT(interface_id) FROM `ports` WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `ignore` = '0'");
$device_alerts = "0";
$device_alert_sql = "WHERE 0";
if (isset($config['enable_bgp']) && $config['enable_bgp'])
{
$bgp_alerts = dbFetchCell("SELECT COUNT(*) FROM bgpPeers AS B where (bgpPeerAdminStatus = 'start' OR bgpPeerAdminStatus = 'running') AND bgpPeerState != 'established'");
}
foreach (dbFetchRows("SELECT * FROM `devices`") as $device)
{
$this_alert = 0;
if ($device['status'] == 0 && $device['ignore'] == '0') { $this_alert = "1"; } elseif ($device['ignore'] == '0')
{
## sluggish. maybe we cache this at poll-time?
# if (dbFetchCell("SELECT count(service_id) FROM services WHERE service_status = '0' AND device_id = ?", array($device['device_id']))) { $this_alert = "1"; }
# if (dbFetchCell("SELECT count(*) FROM ports WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND device_id = ? AND `ignore` = '0'", array($device['device_id']))) { $this_alert = "1"; }
}
if ($this_alert)
{
$device_alerts++;
$device_alert_sql .= " OR `device_id` = '" . $device['device_id'] . "'";
}
$cache['devices'][$device['hostname']] = $device;
}
?>
<ul id="menium">

View File

@@ -6,9 +6,9 @@ echo('<tr bgcolor="' . $bg_colour . '">');
echo('<td class="list">');
if (array_search($vm['vmwVmDisplayName'],array_keys($cache['devices'])))
if (getidbyname($vm['vmwVmDisplayName']))
{
echo(generate_device_link($cache['devices'][$vm['vmwVmDisplayName']]));
echo(generate_device_link(device_by_name($vm['vmwVmDisplayName'])));
} else {
echo $vm['vmwVmDisplayName'];
}

View File

@@ -1,8 +1,21 @@
<?php
foreach (dbFetchRows("SELECT * FROM `devices`") as $device)
{
if (get_dev_attrib($device,'override_sysLocation_bool'))
{
$device['real_location'] = $device['location'];
$device['location'] = get_dev_attrib($device,'override_sysLocation_string');
}
$devices['count']++;
$cache['devices']['hostname'][$device['hostname']] = $device['device_id'];
$cache['devices']['id'][$device['device_id']] = $device;
}
if($_SESSION['userlevel'] >= 5)
{
$devices['count'] = dbFetchCell("SELECT COUNT(*) FROM devices");
$devices['up'] = dbFetchCell("SELECT COUNT(*) FROM devices WHERE status = '1' AND `ignore` = '0'");
$devices['down'] = dbFetchCell("SELECT COUNT(*) FROM devices WHERE status = '0' AND `ignore` = '0'");
$devices['ignored'] = dbFetchCell("SELECT COUNT(*) FROM devices WHERE `ignore` = '1'");