Reindent/cleanup, remove dead files

git-svn-id: http://www.observium.org/svn/observer/trunk@1858 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-15 15:39:57 +00:00
parent 6b4e8a2b59
commit d077282444
8 changed files with 149 additions and 212 deletions

View File

@@ -1,86 +1,85 @@
<?php
#include("../../config.php");
function getDates($dayofmonth)
{
if ($dayofmonth < 10) { $dayofmonth = "0" . $dayofmonth; }
list($year, $month) = split('-', date('Y-m'));
function testPassword($id,$code){
if (date('d') > $dayofmonth)
{
$newmonth = $month + 1;
if ($newmonth == 13)
{
$newmonth = 1;
$newyear = year + 1;
} else {
$newyear = $year;
}
# include("config.php");
$date_from = $year . $month . $dayofmonth;
$date_to = $newyear . $newmonth . $dayofmonth;
$dt_q = mysql_query("SELECT DATE_ADD(DATE_SUB('$date_from', INTERVAL 1 DAY), INTERVAL 1 MONTH);");
$date_to = mysql_result($dt_q,0);
$date_to = str_replace("-","",$date_to);
}
else
{
$newmonth = $month - 1;
if ($newmonth == 0)
{
$newmonth = 12;
$newyear = $year - 1;
} else {
$newyear = $year;
}
# $query = mysql_query("SELECT count(bill_id) FROM bills WHERE bill_id = '$id' AND bill_code = '$code'");
# if (mysql_result($query, 0)) {
# return "1";
# } elseif ($code == $master_code) {
return "1";
# }
# else {
# return "0";
# }
$date_from = $newyear . $newmonth . $dayofmonth;
$date_to = $year . $month . $dayofmonth;
$dt_q = mysql_query("SELECT DATE_ADD(DATE_SUB('$date_to', INTERVAL 1 MONTH), INTERVAL 1 DAY);");
$date_from = mysql_result($dt_q,0);
$date_from = str_replace("-","",$date_from);
}
}
$lq_from = mysql_query("SELECT DATE_SUB('$date_from', INTERVAL 1 MONTH);");
$last_from = mysql_result($lq_from,0);
$last_from = str_replace("-","",$last_from);
function getDates($dayofmonth) {
$lq_to = mysql_query("SELECT DATE_SUB('$date_to', INTERVAL 1 MONTH);");
$last_to = mysql_result($lq_to,0);
$last_to = str_replace("-","",$last_to);
if ($dayofmonth < 10) { $dayofmonth = "0" . $dayofmonth; }
list($year, $month) = split('-', date('Y-m'));
if (date('d') > $dayofmonth) {
$newmonth = $month + 1;
if($newmonth == 13) {
$newmonth = 1;
$newyear = year + 1;
} else {
$newyear = $year;
}
$date_from = $year . $month . $dayofmonth;
$date_to = $newyear . $newmonth . $dayofmonth;
$dt_q = mysql_query("SELECT DATE_ADD(DATE_SUB('$date_from', INTERVAL 1 DAY), INTERVAL 1 MONTH);");
$date_to = mysql_result($dt_q,0);
$date_to = str_replace("-","",$date_to);
} else {
$newmonth = $month - 1;
if($newmonth == 0) {
$newmonth = 12;
$newyear = $year - 1;
} else {
$newyear = $year;
}
$date_from = $newyear . $newmonth . $dayofmonth;
$date_to = $year . $month . $dayofmonth;
$dt_q = mysql_query("SELECT DATE_ADD(DATE_SUB('$date_to', INTERVAL 1 MONTH), INTERVAL 1 DAY);");
$date_from = mysql_result($dt_q,0);
$date_from = str_replace("-","",$date_from);
}
$lq_from = mysql_query("SELECT DATE_SUB('$date_from', INTERVAL 1 MONTH);");
$last_from = mysql_result($lq_from,0);
$last_from = str_replace("-","",$last_from);
$return['0'] = $date_from . "000000";
$return['1'] = $date_to . "235959";
$return['2'] = $last_from . "000000";
$return['3'] = $last_to . "235959";
$lq_to = mysql_query("SELECT DATE_SUB('$date_to', INTERVAL 1 MONTH);");
$last_to = mysql_result($lq_to,0);
$last_to = str_replace("-","",$last_to);
$return['0'] = $date_from . "000000";
$return['1'] = $date_to . "235959";
$return['2'] = $last_from . "000000";
$return['3'] = $last_to . "235959";
return($return);
return($return);
}
function getValue($host, $community, $snmpver, $port, $id, $inout) {
global $config;
$oid = "IF-MIB::ifHC" . $inout . "Octets." . $id;
$value = shell_exec($config['snmpget'] ." -m IF-MIB -c $community -$snmpver -O qv $host:$port $oid");
if(!is_numeric($value)) {
$oid = "IF-MIB::if" . $inout . "Octets." . $id;
$value = shell_exec($config['snmpget'] ." -m IF-MIB -c $community -$snmpver -O qv $host:$port $oid");
}
return $value;
function getValue($host, $community, $snmpver, $port, $id, $inout)
{
global $config;
$oid = "IF-MIB::ifHC" . $inout . "Octets." . $id;
$value = shell_exec($config['snmpget'] ." -m IF-MIB -c $community -$snmpver -O qv $host:$port $oid");
if (!is_numeric($value))
{
$oid = "IF-MIB::if" . $inout . "Octets." . $id;
$value = shell_exec($config['snmpget'] ." -m IF-MIB -c $community -$snmpver -O qv $host:$port $oid");
}
return $value;
}
function getLastPortCounter($port_id,$inout) {
function getLastPortCounter($port_id,$inout)
{
$query = mysql_query("SELECT count(counter) from port_" . $inout . "_measurements WHERE port_id=" . $port_id);
$rows = mysql_result($query, 0);
if($rows > 0) {
if ($rows > 0)
{
$query = mysql_query("SELECT counter,delta FROM port_" . $inout . "_measurements WHERE port_id=$port_id ORDER BY timestamp DESC");
$row = mysql_fetch_row($query);
$return[counter] = $row[0];
@@ -89,13 +88,17 @@ function getLastPortCounter($port_id,$inout) {
} else {
$return[state] = "failed";
}
return($return);
}
function getLastMeasurement($bill_id) {
function getLastMeasurement($bill_id)
{
$query = mysql_query("SELECT count(delta) from bill_data WHERE bill_id=" . $bill_id);
$rows = mysql_result($query, 0);
if($rows > 0) {
if ($rows > 0)
{
$query = mysql_query("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id=$bill_id ORDER BY timestamp DESC");
$row = mysql_fetch_row($query);
$return[delta] = $row[1];
@@ -106,70 +109,84 @@ function getLastMeasurement($bill_id) {
} else {
$return[state] = "failed";
}
return($return);
}
function get95thin($bill_id,$datefrom,$dateto){
$mq_text = "SELECT count(delta) FROM bill_data";
$mq_text = $mq_text . " WHERE bill_id = $bill_id";
$mq_text = $mq_text . " AND timestamp > $datefrom AND timestamp <= $dateto";
$m_query = mysql_query($mq_text);
$measurements = mysql_result($m_query,0);
$measurement_95th = round($measurements /100 * 95) - 1;
$q_95_text = "SELECT in_delta FROM bill_data WHERE bill_id = $bill_id";
$q_95_text = $q_95_text . " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY in_delta ASC";
$q_95th = mysql_query($q_95_text);
$m_95th = mysql_result($q_95th,$measurement_95th);
return(round($m_95th / 1000 / 300 * 8, 2));
function get95thin($bill_id,$datefrom,$dateto)
{
$mq_text = "SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id";
$mq_text .= " AND timestamp > $datefrom AND timestamp <= $dateto";
$m_query = mysql_query($mq_text);
$measurements = mysql_result($m_query,0);
$measurement_95th = round($measurements /100 * 95) - 1;
$q_95_text = "SELECT in_delta FROM bill_data WHERE bill_id = $bill_id";
$q_95_text .= " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY in_delta ASC";
$q_95th = mysql_query($q_95_text);
$m_95th = mysql_result($q_95th,$measurement_95th);
return(round($m_95th / 1000 / 300 * 8, 2));
}
function get95thout($bill_id,$datefrom,$dateto){
$mq_text = "SELECT count(delta) FROM bill_data ";
$mq_text = $mq_text . " WHERE bill_id = $bill_id";
$mq_text = $mq_text . " AND timestamp > $datefrom AND timestamp <= $dateto";
$m_query = mysql_query($mq_text);
$measurements = mysql_result($m_query,0);
$measurement_95th = round($measurements /100 * 95) - 1;
$q_95_text = "SELECT out_delta FROM bill_data WHERE bill_id = $bill_id";
$q_95_text = $q_95_text . " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY out_delta ASC";
$q_95th = mysql_query($q_95_text);
$m_95th = mysql_result($q_95th,$measurement_95th);
return(round($m_95th / 1000 / 300 * 8, 2));
function get95thout($bill_id,$datefrom,$dateto)
{
$mq_text = "SELECT count(delta) FROM bill_data WHERE bill_id = $bill_id";
$mq_text .= " AND timestamp > $datefrom AND timestamp <= $dateto";
$m_query = mysql_query($mq_text);
$measurements = mysql_result($m_query,0);
$measurement_95th = round($measurements /100 * 95) - 1;
$q_95_text = "SELECT out_delta FROM bill_data WHERE bill_id = $bill_id";
$q_95_text .= " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY out_delta ASC";
$q_95th = mysql_query($q_95_text);
$m_95th = mysql_result($q_95th,$measurement_95th);
return(round($m_95th / 1000 / 300 * 8, 2));
}
function getRates($bill_id,$datefrom,$dateto) {
$mq_text = "SELECT count(delta) FROM bill_data ";
$mq_text = $mq_text . " WHERE bill_id = $bill_id";
$mq_text = $mq_text . " AND timestamp > $datefrom AND timestamp <= $dateto";
$m_query = mysql_query($mq_text);
$measurements = mysql_result($m_query,0);
$measurement_95th = round($measurements /100 * 95) - 1;
$q_95_text = "SELECT delta FROM bill_data WHERE bill_id = $bill_id";
$q_95_text = $q_95_text . " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY delta ASC";
$q_95th = mysql_query($q_95_text);
$m_95th = mysql_result($q_95th,$measurement_95th);
$mt_q = mysql_query("SELECT SUM(delta) FROM bill_data WHERE bill_id = '$bill_id' AND timestamp > '$datefrom' AND timestamp <= '$dateto'");
$mtot = mysql_result($mt_q,0);
$data['rate_95th_in'] = get95thIn($bill_id,$datefrom,$dateto);
$data['rate_95th_out'] = get95thOut($bill_id,$datefrom,$dateto);
if ($data['rate_95th_out'] > $data['rate_95th_in']) {
$data['rate_95th'] = $data['rate_95th_out'];
$data['dir_95th'] = 'out';
function getRates($bill_id,$datefrom,$dateto)
{
$mq_text = "SELECT count(delta) FROM bill_data ";
$mq_text = $mq_text . " WHERE bill_id = $bill_id";
$mq_text = $mq_text . " AND timestamp > $datefrom AND timestamp <= $dateto";
$m_query = mysql_query($mq_text);
$measurements = mysql_result($m_query,0);
$measurement_95th = round($measurements /100 * 95) - 1;
$q_95_text = "SELECT delta FROM bill_data WHERE bill_id = $bill_id";
$q_95_text = $q_95_text . " AND timestamp > $datefrom AND timestamp <= $dateto ORDER BY delta ASC";
$q_95th = mysql_query($q_95_text);
$m_95th = mysql_result($q_95th,$measurement_95th);
$mt_q = mysql_query("SELECT SUM(delta) FROM bill_data WHERE bill_id = '$bill_id' AND timestamp > '$datefrom' AND timestamp <= '$dateto'");
$mtot = mysql_result($mt_q,0);
$data['rate_95th_in'] = get95thIn($bill_id,$datefrom,$dateto);
$data['rate_95th_out'] = get95thOut($bill_id,$datefrom,$dateto);
if ($data['rate_95th_out'] > $data['rate_95th_in'])
{
$data['rate_95th'] = $data['rate_95th_out'];
$data['dir_95th'] = 'out';
} else {
$data['rate_95th'] = $data['rate_95th_in'];
$data['dir_95th'] = 'in';
}
$data['total_data'] = round($mtot / 1000 / 1000, 2);
$data['rate_average'] = round($mtot / $measurements / 1000 / 300 * 8, 2);
return($data);
$data['rate_95th'] = $data['rate_95th_in'];
$data['dir_95th'] = 'in';
}
$data['total_data'] = round($mtot / 1000 / 1000, 2);
$data['rate_average'] = round($mtot / $measurements / 1000 / 300 * 8, 2);
return($data);
}
function getTotal($bill_id,$datefrom,$dateto) {
$mt_q = mysql_query("SELECT sum(delta) FROM bill_data WHERE bill_id = $bill_id AND timestamp > $datefrom AND timestamp <= $dateto");
$mtot = mysql_result($mt_q,0);
return($mtot);
function getTotal($bill_id,$datefrom,$dateto)
{
$mt_q = mysql_query("SELECT sum(delta) FROM bill_data WHERE bill_id = $bill_id AND timestamp > $datefrom AND timestamp <= $dateto");
$mtot = mysql_result($mt_q,0);
return($mtot);
}
$dayofmonth = date("j");
$dayofmonth = date("j"); //FIXME is this used anywhere?
?>

View File

@@ -1,59 +0,0 @@
<?php
/* FIXME: dead file */
$id = $device['device_id'];
$hostname = $device['hostname'];
$community = $device['community'];
$snmpver = $device['snmpver'];
$port = $device['port'];
echo("CISCO-PROCESS-MIB : ");
## Cisco Processors
if($device['os'] == "ios") {
/* FIXME: switch to snmp.inc.php:snmp_walk() */
$oids = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m CISCO-PROCESS-MIB -".$device['snmpver']." -CI -Osqn -c ".$community." ".$protocol.":".$hostname.":".$port." .1.3.6.1.4.1.9.9.109.1.1.1.1.2 | sed s/.1.3.6.1.4.1.9.9.109.1.1.1.1.2.//g");
$oids = trim($oids);
foreach(explode("\n", $oids) as $data) {
$data = trim($data);
if($data) {
list($oid, $entPhysicalIndex) = explode(" ", $data);
$usage_oid = "cpmCPUTotal5minRev.$oid";
$descr_oid = "entPhysicalName.$entPhysicalIndex";
$descr = snmp_get($device, $descr_oid, "-O qv", "ENTITY-MIB", $config['mibdir']);
$usage = snmp_get($device, $usage_oid, "-O qv", "CISCO-PROCESS-MIB", $config['mibdir']);
if($entPhysicalIndex == "0") { $descr = "Proc $oid"; }
if(!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" ) {
$descr = str_replace("\"", "", $descr);
$descr = str_replace("CPU of ", "", $descr);
$descr = str_replace("Sub-", "", $descr);
$descr = str_replace("Routing Processor", "RP", $descr);
$descr = str_replace("Switching Processor", "SP", $descr);
$descr = trim($descr);
if(mysql_result(mysql_query("SELECT count(cpmCPU_id) FROM `cpmCPU` WHERE `cpmCPU_oid` = '$oid' AND `device_id` = '$id'"),0) == '0') {
$query = "INSERT INTO cpmCPU (`entPhysicalIndex`, `device_id`, `entPhysicalDescr`, `cpmCPU_oid`) values ('$entPhysicalIndex', '$id', '$descr', '$oid')";
mysql_query($query);
echo("+");
} else { echo("."); }
$valid_cpm[$oid] = 1;
}
}
}
} ## End Cisco Processors
$sql = "SELECT * FROM `cpmCPU` WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($test_cpm = mysql_fetch_array($query)) {
$cpm_index = $test_cmp['cpmCPU_oid'];
if(!$valid_cpm[$cpm_index]) {
echo("-");
mysql_query("DELETE FROM `cpmCPU` WHERE cpmCPU_id = '" . $test_cmp['cpmCPU_id'] . "'");
}
unset($cpm_index);
}
unset($valid_cpm);
echo("\n");
?>

View File

@@ -197,7 +197,7 @@ function discover_link($local_interface_id, $protocol, $remote_interface_id, $re
{
$sql = "UPDATE `links` SET `remote_interface_id` = $remote_interface_id, `remote_platform` = '$remote_platform', `remote_version` = '$remote_version' WHERE `id` = '".$data['id']."'";
mysql_query($sql);
echo("U"); if ($debug) {echo("$sql");}
echo("U"); if ($debug) {echo("$sql"); }
}
}

View File

@@ -3,11 +3,11 @@
echo("hrDevice : ");
$hrDevice_oids = array('hrDeviceEntry','hrProcessorEntry');
if ($debug) {print_r($hrDevices);}
if ($debug) { print_r($hrDevices); }
$hrDevices = array();
foreach ($hrDevice_oids as $oid) { $hrDevices = snmpwalk_cache_oid($device, $oid, $hrDevices, "HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES"); }
if ($debug) {print_r($hrDevices);}
if ($debug) { print_r($hrDevices); }
if (is_array($hrDevices))
{
@@ -37,7 +37,7 @@ if (is_array($hrDevices))
@mysql_query($insert_query); echo("+");
if ($debug) { print_r($hrDevice); echo("$insert_query" . mysql_affected_rows() . " row inserted"); }
}
$valid_hrDevice[$hrDevice[hrDeviceIndex]] = 1;
$valid_hrDevice[$hrDevice['hrDeviceIndex']] = 1;
}
}
}
@@ -47,7 +47,7 @@ $query = mysql_query($sql);
while ($test_hrDevice = mysql_fetch_array($query))
{
if (!$valid_hrDevice[$test_hrDevice[hrDeviceIndex]])
if (!$valid_hrDevice[$test_hrDevice['hrDeviceIndex']])
{
echo("-");
mysql_query("DELETE FROM `hrDevice` WHERE hrDevice_id = '" . $test_hrDevice['hrDevice_id'] . "'");

View File

@@ -25,7 +25,7 @@ foreach (explode("\n", $oids) as $data)
$sep = ".";
$ipv6_address = $ipv6_address . "$adsep" . $part;
$do++;
if ($do == 2) { $adsep = ":"; $do = '0'; } else { $adsep = "";}
if ($do == 2) { $adsep = ":"; $do = '0'; } else { $adsep = ""; }
}
$ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", "", "IP-MIB");

View File

@@ -23,7 +23,7 @@ if (is_array($hrDevice_array))
if ($descr_array['1']) { $descr = $descr_array['1']; } else { $descr = $descr_array['0']; }
### Workaround to set fake description for Mikrotik who don't populate hrDeviceDescr
if ($device['os'] == "routeros" && !isset($entry['hrDeviceDescr'])) { $descr = "Processor";}
if ($device['os'] == "routeros" && !isset($entry['hrDeviceDescr'])) { $descr = "Processor"; }
$descr = str_replace("CPU ", "", $descr);
$descr = str_replace("(TM)", "", $descr);

View File

@@ -1,21 +0,0 @@
<?php
function print_temperature($temp_current, $temp_limit) {
$temp_cur = $temp_current - 15;
$temp_lim = $temp_limit - 15;
if(($temp_lim - $temp_cur) > 25) { $style = "color: LimeGreen;"; }
if(($temp_lim - $temp_cur) <= 25) { $style = "color: Green;"; }
if(($temp_lim - $temp_cur) < 20) { $style = "color: Blue;"; }
if(($temp_lim - $temp_cur) < 15) { $style = "color: MediumPurple;"; }
if(($temp_lim - $temp_cur) < 10) { $style = "font-weight: bold; color: Tomato;"; }
if(($temp_lim - $temp_cur) < 5) { $style = "font-weight: bold; color: OrangeRed;"; }
if(($temp_lim - $temp_cur) <= 0) { $style = "font-weight: bold; color: Crimson;"; }
return("<span style='$style'>$temp_current</span>");
}
?>