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
-22
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">
+2 -2
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'];
}
+14 -1
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'");
+15 -12
View File
@@ -29,8 +29,10 @@ include("includes/functions.inc.php");
include("includes/authenticate.inc.php");
foreach($_GET as $key=>$get_var) {
if (strstr($key, "opt")) {
foreach ($_GET as $key=>$get_var)
{
if (strstr($key, "opt"))
{
list($name, $value) = explode("|", $get_var);
if (!isset($value)) { $value = "yes"; }
$vars[$name] = $value;
@@ -38,14 +40,16 @@ foreach($_GET as $key=>$get_var) {
}
$segments = explode('/', trim($_SERVER['PATH_INFO'], '/'));
foreach($segments as $pos => $segment) {
foreach ($segments as $pos => $segment)
{
$segment = urldecode($segment);
if ($pos == "0")
{
$vars['page'] = $segment;
} else {
if (TRUE) // do this to keep everything working whilst we fiddle
{
if (TRUE) // do this to keep everything working whilst we fiddle --AS
{ // also, who wrote this? Please check php.net/switch ;) --TL
if ($pos == "1")
{
$_GET['opta'] = $segment;
@@ -299,12 +303,10 @@ if ($config['page_gen'])
echo('<br />Generated in ' . $gentime . ' seconds.');
}
echo('</div>');
echo('</div>');
?>
<script class="content_tooltips" type="text/javascript">
</div>
</div>
<script class="content_tooltips" type="text/javascript">
$(document).ready(function() { $('#content a[title]').qtip({ content: { text: false }, style: 'light' }); });
$('INPUT.auto-hint, TEXTAREA.auto-hint').focus(function() {
@@ -313,8 +315,9 @@ $('INPUT.auto-hint, TEXTAREA.auto-hint').focus(function() {
$(this).removeClass('auto-hint');
}
});
</script>
</script>
<?php echo "ohai: " . gethostbyid(174); ?>
</body>
</body>
</html>
+19 -8
View File
@@ -203,13 +203,18 @@ function ifclass($ifOperStatus, $ifAdminStatus)
return $ifclass;
}
function device_by_name($name, $refresh = 0)
{
return device_by_id_cache(getidbyname($name), $refresh);
}
function device_by_id_cache($device_id, $refresh = '0')
{
global $device_cache;
global $cache;
if (!$refresh && isset($device_cache[$device_id]) && is_array($device_cache[$device_id]))
if (!$refresh && isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id]))
{
$device = $device_cache[$device_id];
$device = $cache['devices']['id'][$device_id];
} else {
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
if (get_dev_attrib($device,'override_sysLocation_bool'))
@@ -217,7 +222,7 @@ function device_by_id_cache($device_id, $refresh = '0')
$device['real_location'] = $device['location'];
$device['location'] = get_dev_attrib($device,'override_sysLocation_string');
}
$device_cache[$device_id] = $device;
$cache['devices']['id'][$device_id] = $device;
}
return $device;
@@ -242,7 +247,9 @@ function getifhost($id)
function gethostbyid($id)
{
return dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id));
global $cache;
return $cache['devices']['id'][$id]['hostname'];
}
function strgen ($length = 16)
@@ -282,14 +289,18 @@ function getifdescrbyid($id)
return dbFetchCell("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = ?", array($id));
}
function getidbyname($domain)
function getidbyname($hostname)
{
return dbFetchCell("SELECT `device_id` FROM `devices` WHERE `hostname` = ?", array($domain));
global $cache;
return $cache['devices']['hostname'][$hostname];
}
function gethostosbyid($id)
{
return dbFetchCell("SELECT `os` FROM `devices` WHERE `device_id` = ?", array($id));
global $cache;
return $cache['devices']['id'][$id]['os'];
}
function safename($name)
+1 -1
View File
@@ -34,7 +34,7 @@ function ifNameDescr($interface, $device = NULL)
return ifLabel($interface, $device);
}
function ifLabel ($interface, $device = NULL)
function ifLabel($interface, $device = NULL)
{
global $config;
-1
View File
@@ -502,7 +502,6 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
$device['transport'] = "udp";
}
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk'])
{
$snmpcommand = $config['snmpwalk'];