code standard/cleanups

git-svn-id: http://www.observium.org/svn/observer/trunk@1978 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-26 19:12:24 +00:00
parent ec7535c25a
commit 7454791074
19 changed files with 239 additions and 229 deletions

View File

@@ -41,7 +41,8 @@ while ($device = mysql_fetch_array($query))
unset($valid_ips);
foreach (explode("\n", $oids) as $data) {
foreach (explode("\n", $oids) as $data)
{
$data = trim($data);
list($ipv6addr,$ifIndex) = explode(" ", $data);
$valid_ips[] = $ipv6addr;

View File

@@ -7,7 +7,6 @@ include("../includes/functions.php"); ## FIXME zeropad()
if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || bill_permitted($_GET['id'])))
{
$bill_query = mysql_query("SELECT * FROM `bills` WHERE bill_id = '".mres($_GET['id'])."'");
$bill = mysql_fetch_assoc($bill_query);
@@ -22,9 +21,6 @@ if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || bill_permitted
AND D.device_id = P.device_id");
$auth = TRUE;
}
?>

View File

@@ -4,7 +4,7 @@ $i = 1;
foreach (explode(",", $id) as $ifid)
{
if(strstr($ifid, "!"))
if (strstr($ifid, "!"))
{
$rrd_inverted[$i] = TRUE;
$ifid = str_replace("!", "", $ifid);

View File

@@ -51,6 +51,7 @@ while ($acc = mysql_fetch_array($query))
$mac = formatmac($acc['mac']);
$name = $mac;
$addy = mysql_fetch_array(mysql_query("SELECT * FROM ipv4_mac where mac_address = '".$acc['mac']."' AND interface_id = '".$acc['interface_id']."'"));
if ($addy)
{
$name = $addy['ipv4_address'] . " (".$mac.")";
@@ -70,7 +71,8 @@ while ($acc = mysql_fetch_array($query))
$name .= " - AS".$peer_info['bgpPeerRemoteAs'];
}
if ($peer_info) {
if ($peer_info)
{
$asn = "AS".$peer_info['bgpPeerRemoteAs']; $astext = $peer_info['astext'];
} else {
unset ($as); unset ($astext); unset($asn);

View File

@@ -34,7 +34,8 @@ $month = time() - (31 * 24 * 60 * 60);
$year = time() - (365 * 24 * 60 * 60);
# Load the settings for Multi-Tenancy.
if (is_array($config['branding'])) {
if (is_array($config['branding']))
{
if ($config['branding'][$_SERVER['SERVER_NAME']])
{
foreach ($config['branding'][$_SERVER['SERVER_NAME']] as $confitem => $confval)

View File

@@ -11,7 +11,8 @@ else
$i = "1";
if ($_GET['opta'] == "alerts") {
if ($_GET['opta'] == "alerts")
{
$where = "AND (B.bgpPeerAdminStatus = 'start' or B.bgpPeerAdminStatus = 'running') AND B.bgpPeerState != 'established'";
} elseif ($_GET['opta'] == "external") {
$where = "AND D.bgpLocalAs != B.bgpPeerRemoteAs";

View File

@@ -80,7 +80,8 @@ if (device_permitted($_GET['id']) || $check_device == $_GET['id'])
</li>');
}
if (is_dir($config['collectd_dir'] . "/" . $device['hostname'] ."/")) {
if (is_dir($config['collectd_dir'] . "/" . $device['hostname'] ."/"))
{
echo('<li class="' . $select['collectd'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/collectd/">
<img src="images/16/chart_line.png" align="absmiddle" border="0" /> CollectD
@@ -88,7 +89,8 @@ if (device_permitted($_GET['id']) || $check_device == $_GET['id'])
</li>');
}
if (@mysql_result(mysql_query("select count(interface_id) from ports WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') {
if (@mysql_result(mysql_query("select count(interface_id) from ports WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0')
{
echo('<li class="' . $select['ports'] . '">
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/ports/' .$config['ports_page_default']. '">
<img src="images/16/connect.png" align="absmiddle" border="0" /> Ports
@@ -197,14 +199,17 @@ if (device_permitted($_GET['id']) || $check_device == $_GET['id'])
}
if ($_SESSION['userlevel'] >= "7") {
if ($_SESSION['userlevel'] >= "7")
{
if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); }
foreach ($config['rancid_configs'] as $configs) {
foreach ($config['rancid_configs'] as $configs)
{
if ($configs[strlen($configs)-1] != '/') { $configs .= '/'; }
if (is_file($configs . $device['hostname'])) { $device_config_file = $configs . $device['hostname']; }
}
}
if ($device_config_file) {
if ($device_config_file)
{
echo('<li class="' . $select['showconfig'] . '">
<a href="'.$config['base_url']."/device/" . $device['device_id'] . '/showconfig/">
<img src="images/16/page_white_text.png" align="absmiddle" border="0" /> Config
@@ -213,7 +218,8 @@ if (device_permitted($_GET['id']) || $check_device == $_GET['id'])
');
}
if ($_SESSION['userlevel'] >= "7") {
if ($_SESSION['userlevel'] >= "7")
{
echo('<li class="' . $select['edit'] . '">
<a href="'.$config['base_url']."/device/" . $device['device_id'] . '/edit/">
<img src="images/16/server_edit.png" align="absmiddle" border="0" /> Settings

View File

@@ -90,7 +90,8 @@ print_optionbar_start(62);
<option value="">All Locations</option>
<?php
if($_SESSION['userlevel'] >= '5') {
if($_SESSION['userlevel'] >= '5')
{
$query = mysql_query("SELECT location FROM devices WHERE 1 $where GROUP BY location ORDER BY location");
} else {
$query = mysql_query("SELECT location FROM devices AS D, devices_perms AS P WHERE 1 $where AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' GROUP BY location ORDER BY location");

View File

@@ -14,37 +14,43 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
if ($_GET['action'] == "deldevperm")
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = '" . $_GET['device_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0)) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = '" . $_GET['device_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0))
{
mysql_query("DELETE FROM devices_perms WHERE `device_id` = '" . $_GET['device_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'");
}
}
if ($_GET['action'] == "adddevperm")
{
if (!mysql_result(mysql_query("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = '" . $_GET['device_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0)) {
if (!mysql_result(mysql_query("SELECT COUNT(*) FROM devices_perms WHERE `device_id` = '" . $_GET['device_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0))
{
mysql_query("INSERT INTO devices_perms (`device_id`, `user_id`) VALUES ('" . $_GET['device_id'] . "', '" . $_GET['user_id'] . "')");
}
}
if ($_GET['action'] == "delifperm")
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM ports_perms WHERE `interface_id` = '" . $_GET['interface_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0)) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM ports_perms WHERE `interface_id` = '" . $_GET['interface_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0))
{
mysql_query("DELETE FROM ports_perms WHERE `interface_id` = '" . $_GET['interface_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'");
}
}
if ($_GET['action'] == "addifperm")
{
if (!mysql_result(mysql_query("SELECT COUNT(*) FROM ports_perms WHERE `interface_id` = '" . $_GET['interface_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0)) {
if (!mysql_result(mysql_query("SELECT COUNT(*) FROM ports_perms WHERE `interface_id` = '" . $_GET['interface_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0))
{
mysql_query("INSERT INTO ports_perms (`interface_id`, `user_id`) VALUES ('" . $_GET['interface_id'] . "', '" . $_GET['user_id'] . "')");
}
}
if ($_GET['action'] == "delbillperm")
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = '" . $_GET['bill_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0)) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = '" . $_GET['bill_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0))
{
mysql_query("DELETE FROM bill_perms WHERE `bill_id` = '" . $_GET['bill_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'");
}
}
if ($_GET['action'] == "addbillperm")
{
if (!mysql_result(mysql_query("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = '" . $_GET['bill_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0)) {
if (!mysql_result(mysql_query("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = '" . $_GET['bill_id'] . "' AND `user_id` = '" . $_GET['user_id'] . "'"),0))
{
mysql_query("INSERT INTO bill_perms (`bill_id`, `user_id`) VALUES ('" . $_GET['bill_id'] . "', '" . $_GET['user_id'] . "')");
}
}

View File

@@ -13,17 +13,21 @@ $ports = str_replace("ifDescr.", "", $ports);
$interface_ignored = 0;
$interface_added = 0;
foreach (explode("\n", $ports) as $entry){
foreach (explode("\n", $ports) as $entry)
{
$entry = trim($entry);
list($ifIndex, $ifDescr) = explode(" ", $entry, 2);
if (!strstr($entry, "irtual")) {
if (!strstr($entry, "irtual"))
{
$if = trim(strtolower($ifDescr));
$nullintf = 0;
foreach ($config['bad_if'] as $bi) { if (strstr($if, $bi)) { $nullintf = 1; } }
if (is_array($config['bad_if_regexp'])) {
foreach ($config['bad_if_regexp'] as $bi) {
if (preg_match($bi ."i", $if)) {
if (is_array($config['bad_if_regexp']))
{
foreach ($config['bad_if_regexp'] as $bi)
{
if (preg_match($bi ."i", $if))
{
$nullintf = 1;
}
}
@@ -34,11 +38,13 @@ foreach (explode("\n", $ports) as $entry){
if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $ifDescr, $matches)) { $ifDescr = $matches[1]; }
$ifDescr = fixifName($ifDescr);
if (preg_match('/serial[0-9]:/', $if)) { $nullintf = 1; }
if (isset($config['allow_ng']) && !$config['allow_ng']) {
if (isset($config['allow_ng']) && !$config['allow_ng'])
{
if (preg_match('/ng[0-9]+$/', $if)) { $nullintf = 1; }
}
if ($debug) echo("\n $if ");
if ($nullintf == 0) {
if ($nullintf == 0)
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') {
mysql_query("INSERT INTO `ports` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('".$device['device_id']."','$ifIndex','".mres($ifDescr)."')");
# Add Interface
@@ -61,19 +67,21 @@ foreach (explode("\n", $ports) as $entry){
}
}
$sql = "SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `deleted` = '0'";
$query = mysql_query($sql);
while ($test_if = mysql_fetch_array($query)) {
while ($test_if = mysql_fetch_array($query))
{
unset($exists);
$i = 0;
while ($i < count($int_exists) && !isset($exists)) {
while ($i < count($int_exists) && !isset($exists))
{
$this_if = $test_if['ifIndex'];
if ($int_exists[$i] == $this_if) { $exists = 1; }
$i++;
}
if (!$exists) {
if (!$exists)
{
echo("-");
mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE interface_id = '" . $test_if['interface_id'] . "'");
}

View File

@@ -3,8 +3,6 @@
global $valid_processor;
## Hardcoded discovery of device CPU usage on Alcatel-Lucent Omniswitches.
##
if ($device['os'] == "aos")
{

View File

@@ -4,23 +4,20 @@
* Try to discover any Virtual Machines.
*/
if ($device['os'] == "vmware") {
if ($device['os'] == "vmware")
{
/*
* Variable to hold the discovered Virtual Machines.
*/
$vmw_vmlist = array();
/*
* CONSOLE: Start the VMware discovery process.
*/
echo("VMware VM: ");
/*
* Fetch the list is Virtual Machines.
*
@@ -32,9 +29,8 @@ if ($device['os'] == "vmware") {
$oids = snmp_walk($device, "VMWARE-VMINFO-MIB::vmwVmVMID", "-Osqnv", "+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB", "+" . $config["install_dir"] . "/mibs/vmware");
$oids = explode("\n", $oids);
foreach ($oids as $oid) {
foreach ($oids as $oid)
{
/*
* Fetch the Virtual Machine information.
*
@@ -58,29 +54,28 @@ if ($device['os'] == "vmware") {
$vmwVmState = snmp_get($device, "VMWARE-VMINFO-MIB::vmwVmState." . $oid, "-Osqnv", "+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB", "+" . $config["install_dir"] . "/mibs/vmware");
$vmwVmCpus = snmp_get($device, "VMWARE-VMINFO-MIB::vmwVmCpus." . $oid, "-Osqnv", "+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB", "+" . $config["install_dir"] . "/mibs/vmware");
/*
* VMware does not return an INTEGER but a STRING of the vmwVmMemSize. This bug
* might be resolved by VMware in the future making this code absolete.
*/
if (preg_match("/^([0-9]+) .*$/", $vmwVmMemSize, $matches)) {
if (preg_match("/^([0-9]+) .*$/", $vmwVmMemSize, $matches))
{
$vmwVmMemSize = $matches[1];
}
/*
* Check whether the Virtual Machine is already known for this host.
*/
if (mysql_result(mysql_query("SELECT COUNT(id) FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $oid . "'"), 0) == 0) {
if (mysql_result(mysql_query("SELECT COUNT(id) FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $oid . "'"), 0) == 0)
{
mysql_query("INSERT INTO vmware_vminfo (device_id, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState) VALUES (" . $device["device_id"] . ", " . $oid . ", '" . mres($vmwVmDisplayName) . "', '" . mres($vmwVmGuestOS) . "', " . $vmwVmMemSize . ", " . $vmwVmCpus . ", '" . mres($vmwVmState) . "')");
echo("+");
} else {
echo ".";
}
/*
* Save the discovered Virtual Machine.
*/
@@ -88,16 +83,14 @@ if ($device['os'] == "vmware") {
$vmw_vmlist[] = $oid;
}
/*
* Get a list of all the known Virtual Machines for this host.
*/
$db_vm_list = mysql_query("SELECT id, vmwVmVMID FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'");
while ($db_vm = mysql_fetch_array($db_vm_list)) {
while ($db_vm = mysql_fetch_array($db_vm_list))
{
/*
* Delete the Virtual Machines that are removed from the host.
*/
@@ -108,11 +101,11 @@ if ($device['os'] == "vmware") {
}
}
/*
* Finished discovering VMware information.
*/
echo("\n");
}
?>

View File

@@ -92,7 +92,7 @@ function shorthost($hostname, $len=16)
{
$parts = explode(".", $hostname);
$shorthost = $parts[0];
$i=1;
$i = 1;
while ($i < count($parts) && strlen($shorthost.'.'.$parts[$i]) < $len)
{
$shorthost = $shorthost.'.'.$parts[$i];
@@ -150,14 +150,14 @@ function format_si($rate)
$sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E');
$round = Array('2','2','2','2','2','2','2','2','2');
$ext = $sizes[0];
for ($i=1; (($i < count($sizes)) && ($rate >= 1000)); $i++) { $rate = $rate / 1000; $ext = $sizes[$i]; }
for ($i = 1; (($i < count($sizes)) && ($rate >= 1000)); $i++) { $rate = $rate / 1000; $ext = $sizes[$i]; }
}
else
{
$sizes = Array('', 'm', 'u', 'n');
$round = Array('2','2','2','2');
$ext = $sizes[0];
for ($i=1; (($i < count($sizes)) && ($rate != 0) && ($rate <= 0.1)); $i++) { $rate = $rate * 1000; $ext = $sizes[$i]; }
for ($i = 1; (($i < count($sizes)) && ($rate != 0) && ($rate <= 0.1)); $i++) { $rate = $rate * 1000; $ext = $sizes[$i]; }
}
return round($rate, $round[$i]).$ext;
@@ -167,7 +167,7 @@ function format_bi($size, $round = '2')
{
$sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E');
$ext = $sizes[0];
for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; }
for ($i = 1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; }
return round($size, $round).$ext;
}
@@ -746,7 +746,7 @@ function hex2str($hex)
{
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2)
for ($i = 0; $i < strlen($hex)-1; $i+=2)
{
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}

View File

@@ -15,36 +15,34 @@ $data = snmp_get_multi($device, "VMWARE-SYSTEM-MIB::vmwProdName.0 VMWARE-SYS
$version = preg_replace("/^VMware /", "", $data[0]["vmwProdName"]) . " " . $data[0]["vmwProdVersion"];
$features = "build-" . $data[0]["vmwProdBuild"];
/*
* VMware ESXi returns "not set" instead of a NULL value.
*/
if ($sysLocation == "not set") {
if ($sysLocation == "not set")
{
$sysLocation = "";
}
if ($sysContact == "not set") {
if ($sysContact == "not set")
{
$sysContact = "";
}
/*
* CONSOLE: Start the VMware discovery process.
*/
echo("VMware VM: ");
/*
* Get a list of all the known Virtual Machines for this host.
*/
$db_info_list = mysql_query("SELECT id, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'");
while ($db_info = mysql_fetch_array($db_info_list)) {
while ($db_info = mysql_fetch_array($db_info_list))
{
/*
* Fetch the Virtual Machine information.
*
@@ -64,39 +62,38 @@ while ($db_info = mysql_fetch_array($db_info_list)) {
$vm_info["vmwVmState"] = snmp_get($device, "VMWARE-VMINFO-MIB::vmwVmState." . $db_info["vmwVmVMID"], "-Osqnv", "+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB", "+" . $config["install_dir"] . "/mibs/vmware");
$vm_info["vmwVmCpus"] = snmp_get($device, "VMWARE-VMINFO-MIB::vmwVmCpus." . $db_info["vmwVmVMID"], "-Osqnv", "+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB", "+" . $config["install_dir"] . "/mibs/vmware");
/*
* VMware does not return an INTEGER but a STRING of the vmwVmMemSize. This bug
* might be resolved by VMware in the future making this code absolete.
*/
if (preg_match("/^([0-9]+) .*$/", $vm_info["vmwVmMemSize"], $matches)) {
if (preg_match("/^([0-9]+) .*$/", $vm_info["vmwVmMemSize"], $matches))
{
$vm_info["vmwVmMemSize"] = $matches[1];
}
/*
* Proceess all the VMware Virtual Machine properties.
*/
foreach ($vm_info as $property => $value) {
foreach ($vm_info as $property => $value)
{
/*
* Check the property for any modifications.
*/
if ($vm_info[$property] != $db_info[$property]) {
if ($vm_info[$property] != $db_info[$property])
{
mysql_query("UPDATE vmware_vminfo SET " . $property ." = '" . mres($vm_info[$property]) ."' WHERE id = '" . $db_info["id"] . "'");
log_event($db_info["vmwVmDisplayName"] . " (" . preg_replace("/^vmwVm/", "", $property) . ") -> " . $vm_info[$property], $device['device_id']);
}
}
}
/*
* Finished discovering VMware information.
*/
echo("\n");
?>