From d0772824448919900f0b90c1679a9548e838100b Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Tue, 15 Mar 2011 15:39:57 +0000 Subject: [PATCH] Reindent/cleanup, remove dead files git-svn-id: http://www.observium.org/svn/observer/trunk@1858 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/billing.php | 265 ++++++++++-------- includes/common.php | 2 +- includes/discovery/cisco-processors.inc.php | 59 ---- includes/discovery/functions.inc.php | 2 +- includes/discovery/hr-device.inc.php | 8 +- includes/discovery/ipv6-addresses.inc.php | 2 +- .../discovery/processors/hrdevice.inc.php | 2 +- includes/print-functions.php | 21 -- 8 files changed, 149 insertions(+), 212 deletions(-) delete mode 100755 includes/discovery/cisco-processors.inc.php delete mode 100644 includes/print-functions.php diff --git a/includes/billing.php b/includes/billing.php index 0cfba4299a..b217f3d6fd 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -1,86 +1,85 @@ $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); - - $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['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,14 +88,18 @@ 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) { - $query = mysql_query("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id=$bill_id ORDER BY timestamp DESC"); + + 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]; $return[delta] = $row[2]; @@ -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? -?> +?> \ No newline at end of file diff --git a/includes/common.php b/includes/common.php index 903f0e88e7..ba9d76a600 100644 --- a/includes/common.php +++ b/includes/common.php @@ -177,7 +177,7 @@ function gethostosbyid($id) return $result; } -function safename($name) +function safename($name) { return preg_replace('/[^a-zA-Z0-9,._\-]/', '_', $name); } diff --git a/includes/discovery/cisco-processors.inc.php b/includes/discovery/cisco-processors.inc.php deleted file mode 100755 index 3216d260c9..0000000000 --- a/includes/discovery/cisco-processors.inc.php +++ /dev/null @@ -1,59 +0,0 @@ - diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 7c2d26ec36..3e8b0cf09b 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -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"); } } } diff --git a/includes/discovery/hr-device.inc.php b/includes/discovery/hr-device.inc.php index 6b139898a6..671c7edd99 100755 --- a/includes/discovery/hr-device.inc.php +++ b/includes/discovery/hr-device.inc.php @@ -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'] . "'"); diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index db677c2eef..d5c150195e 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -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"); diff --git a/includes/discovery/processors/hrdevice.inc.php b/includes/discovery/processors/hrdevice.inc.php index 3daa3a35c5..944422a387 100755 --- a/includes/discovery/processors/hrdevice.inc.php +++ b/includes/discovery/processors/hrdevice.inc.php @@ -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); diff --git a/includes/print-functions.php b/includes/print-functions.php deleted file mode 100644 index e293f8d9e5..0000000000 --- a/includes/print-functions.php +++ /dev/null @@ -1,21 +0,0 @@ - 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("$temp_current"); - -} - -?>