mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
cleanups, reindents, etc
git-svn-id: http://www.observium.org/svn/observer/trunk@1821 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
+54
-24
@@ -2,14 +2,14 @@
|
||||
|
||||
## Common Functions
|
||||
|
||||
|
||||
|
||||
function get_port_by_id($port_id)
|
||||
{
|
||||
if(is_numeric($port_id)) {
|
||||
if (is_numeric($port_id))
|
||||
{
|
||||
$port = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '".$port_id."'"));
|
||||
}
|
||||
if(is_array($port)){
|
||||
if (is_array($port))
|
||||
{
|
||||
return $port;
|
||||
} else {
|
||||
return FALSE;
|
||||
@@ -18,10 +18,12 @@ function get_port_by_id($port_id)
|
||||
|
||||
function get_application_by_id($application_id)
|
||||
{
|
||||
if(is_numeric($application_id)) {
|
||||
if (is_numeric($application_id))
|
||||
{
|
||||
$application = mysql_fetch_assoc(mysql_query("SELECT * FROM `applications` WHERE `app_id` = '".$application_id."'"));
|
||||
}
|
||||
if(is_array($application)){
|
||||
if (is_array($application))
|
||||
{
|
||||
return $application;
|
||||
} else {
|
||||
return FALSE;
|
||||
@@ -30,21 +32,26 @@ function get_application_by_id($application_id)
|
||||
|
||||
function get_sensor_by_id($sensor_id)
|
||||
{
|
||||
if(is_numeric($sensor_id)) {
|
||||
if (is_numeric($sensor_id))
|
||||
{
|
||||
$sensor = mysql_fetch_assoc(mysql_query("SELECT * FROM `sensors` WHERE `sensor_id` = '".$sensor_id."'"));
|
||||
}
|
||||
if(is_array($sensor)){
|
||||
if (is_array($sensor))
|
||||
{
|
||||
return $sensor;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function get_device_id_by_interface_id($interface_id) {
|
||||
if(is_numeric($interface_id)) {
|
||||
function get_device_id_by_interface_id($interface_id)
|
||||
{
|
||||
if (is_numeric($interface_id))
|
||||
{
|
||||
$device_id = mysql_result(mysql_query("SELECT `device_id` FROM `ports` WHERE `interface_id` = '".$interface_id."'"),0);
|
||||
}
|
||||
if(is_numeric($device_id)){
|
||||
if (is_numeric($device_id))
|
||||
{
|
||||
return $device_id;
|
||||
} else {
|
||||
return FALSE;
|
||||
@@ -54,15 +61,18 @@ function get_device_id_by_interface_id($interface_id) {
|
||||
function ifclass($ifOperStatus, $ifAdminStatus)
|
||||
{
|
||||
$ifclass = "interface-upup";
|
||||
|
||||
if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; }
|
||||
if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; }
|
||||
if ($ifAdminStatus == "up" && $ifOperStatus== "up") { $ifclass = "interface-upup"; }
|
||||
|
||||
return $ifclass;
|
||||
}
|
||||
|
||||
function device_by_id_cache($device_id)
|
||||
{
|
||||
global $device_cache;
|
||||
|
||||
if (is_array($device_cache[$device_id]))
|
||||
{
|
||||
$device = $device_cache[$device_id];
|
||||
@@ -70,28 +80,35 @@ function device_by_id_cache($device_id)
|
||||
$device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'"));
|
||||
$device_cache[$device_id] = $device;
|
||||
}
|
||||
|
||||
return $device;
|
||||
}
|
||||
|
||||
function truncate($substring, $max = 50, $rep = '...'){
|
||||
function truncate($substring, $max = 50, $rep = '...')
|
||||
{
|
||||
if (strlen($substring) < 1){ $string = $rep; } else { $string = $substring; }
|
||||
$leave = $max - strlen ($rep);
|
||||
if (strlen($string) > $max){ return substr_replace($string, $rep, $leave); } else { return $string; }
|
||||
}
|
||||
|
||||
function mres($string) { // short function wrapper because the real one is stupidly long and ugly. aestetics.
|
||||
function mres($string)
|
||||
{ // short function wrapper because the real one is stupidly long and ugly. aestetics.
|
||||
return mysql_real_escape_string($string);
|
||||
}
|
||||
|
||||
function getifhost($id) {
|
||||
function getifhost($id)
|
||||
{
|
||||
$sql = mysql_query("SELECT `device_id` from `ports` WHERE `interface_id` = '$id'");
|
||||
$result = @mysql_result($sql, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function gethostbyid($id) {
|
||||
function gethostbyid($id)
|
||||
{
|
||||
$sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'");
|
||||
$result = @mysql_result($sql, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -102,54 +119,67 @@ function strgen ($length = 16)
|
||||
'N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w',
|
||||
'W','x','X','y','Y','z','Z');
|
||||
$string = "";
|
||||
for ($i=0; $i<$length; $i++) {
|
||||
|
||||
for ($i=0; $i<$length; $i++)
|
||||
{
|
||||
$key = mt_rand(0,61);
|
||||
$string .= $entropy[$key];
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
function getpeerhost($id) {
|
||||
function getpeerhost($id)
|
||||
{
|
||||
$sql = mysql_query("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = '$id'");
|
||||
$result = @mysql_result($sql, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getifindexbyid($id) {
|
||||
function getifindexbyid($id)
|
||||
{
|
||||
$sql = mysql_query("SELECT `ifIndex` FROM `ports` WHERE `interface_id` = '$id'");
|
||||
$result = @mysql_result($sql, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getifbyid($id) {
|
||||
function getifbyid($id)
|
||||
{
|
||||
$sql = mysql_query("SELECT * FROM `ports` WHERE `interface_id` = '$id'");
|
||||
$result = @mysql_fetch_array($sql);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getifdescrbyid($id) {
|
||||
function getifdescrbyid($id)
|
||||
{
|
||||
$sql = mysql_query("SELECT `ifDescr` FROM `ports` WHERE `interface_id` = '$id'");
|
||||
$result = @mysql_result($sql, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getidbyname($domain){
|
||||
function getidbyname($domain)
|
||||
{
|
||||
$sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'");
|
||||
$result = @mysql_result($sql, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function gethostosbyid($id) {
|
||||
function gethostosbyid($id)
|
||||
{
|
||||
$sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'");
|
||||
$result = @mysql_result($sql, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function safename($name)
|
||||
{
|
||||
return preg_replace('/[^a-zA-Z0-9,._\-]/', '_', $name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
+77
-37
@@ -137,7 +137,8 @@ function getHostOS($device)
|
||||
if ($os) { return $os; } else { return "generic"; }
|
||||
}
|
||||
|
||||
function formatRates($rate) {
|
||||
function formatRates($rate)
|
||||
{
|
||||
$rate = format_si($rate) . "bps";
|
||||
return $rate;
|
||||
}
|
||||
@@ -150,12 +151,15 @@ function formatstorage($rate, $round = '2')
|
||||
|
||||
function format_si($rate)
|
||||
{
|
||||
if ($rate >= "0.1") {
|
||||
if ($rate >= "0.1")
|
||||
{
|
||||
$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]; }
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$sizes = Array('', 'm', 'u', 'n');
|
||||
$round = Array('2','2','2','2');
|
||||
$ext = $sizes[0];
|
||||
@@ -217,7 +221,8 @@ function getImage($host)
|
||||
} else {
|
||||
if (file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$type.'.png" />';
|
||||
} elseif (file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$type.'.gif" />'; }
|
||||
if ($type == "linux") {
|
||||
if ($type == "linux")
|
||||
{
|
||||
$features = strtolower(trim($data['features']));
|
||||
list($distro) = split(" ", $features);
|
||||
if (file_exists($config['html_dir'] . "/images/os/$distro" . ".png")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$distro.'.png" />';
|
||||
@@ -227,10 +232,11 @@ function getImage($host)
|
||||
return $image;
|
||||
}
|
||||
|
||||
function renamehost($id, $new) {
|
||||
function renamehost($id, $new)
|
||||
{
|
||||
global $config;
|
||||
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
|
||||
shell_exec("mv ".$config['rrd_dir']."/$host ".$config['rrd_dir']."/$new");
|
||||
rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new");
|
||||
mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'");
|
||||
eventlog("Hostname changed -> $new (console)", $id);
|
||||
}
|
||||
@@ -248,7 +254,7 @@ function delete_port($int_id)
|
||||
mysql_query("DELETE FROM `bill_ports` WHERE `port_id` = '$int_id'");
|
||||
mysql_query("DELETE from `pseudowires` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE FROM `ports` WHERE `interface_id` = '$int_id'");
|
||||
shell_exec("rm -rf ".trim($config['rrd_dir'])."/".trim($interface['hostname'])."/".$interface['ifIndex'].".rrd");
|
||||
unlink(trim($config['rrd_dir'])."/".trim($interface['hostname'])."/".$interface['ifIndex'].".rrd");
|
||||
}
|
||||
|
||||
function delete_device($id)
|
||||
@@ -257,7 +263,8 @@ function delete_device($id)
|
||||
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
|
||||
mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'");
|
||||
$int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'");
|
||||
while($int_data = mysql_fetch_array($int_query)) {
|
||||
while($int_data = mysql_fetch_array($int_query))
|
||||
{
|
||||
$int_if = $int_data['ifDescr'];
|
||||
$int_id = $int_data['interface_id'];
|
||||
delete_port($int_id);
|
||||
@@ -295,6 +302,7 @@ function addHost($host, $community, $snmpver, $port = 161)
|
||||
{
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' )
|
||||
{
|
||||
# FIXME internalize
|
||||
$snmphost = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0");
|
||||
if ($snmphost == $host || $hostshort = $host)
|
||||
{
|
||||
@@ -308,8 +316,6 @@ function addHost($host, $community, $snmpver, $port = 161)
|
||||
function scanUDP ($host, $port, $timeout)
|
||||
{
|
||||
$handle = fsockopen($host, $port, $errno, $errstr, 2);
|
||||
if (!$handle) {
|
||||
}
|
||||
socket_set_timeout ($handle, $timeout);
|
||||
$write = fwrite($handle,"\x00");
|
||||
if (!$write) { next; }
|
||||
@@ -317,7 +323,8 @@ function scanUDP ($host, $port, $timeout)
|
||||
$header = fread($handle, 1);
|
||||
$endTime = time();
|
||||
$timeDiff = $endTime - $startTime;
|
||||
if ($timeDiff >= $timeout) {
|
||||
if ($timeDiff >= $timeout)
|
||||
{
|
||||
fclose($handle); return 1;
|
||||
} else { fclose($handle); return 0; }
|
||||
}
|
||||
@@ -347,13 +354,16 @@ function formatUptime($diff, $format="long")
|
||||
|
||||
$uptime = "";
|
||||
|
||||
if ($format == "short") {
|
||||
if ($format == "short")
|
||||
{
|
||||
if ($yearsDiff > '0') { $uptime .= $yearsDiff . "y "; }
|
||||
if ($daysDiff > '0') { $uptime .= $daysDiff . "d "; }
|
||||
if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; }
|
||||
if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; }
|
||||
if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; }
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($yearsDiff > '0') { $uptime .= $yearsDiff . " years, "; }
|
||||
if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '' ) . ", "; }
|
||||
if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; }
|
||||
@@ -366,43 +376,54 @@ function formatUptime($diff, $format="long")
|
||||
function isSNMPable($hostname, $community, $snmpver, $port)
|
||||
{
|
||||
global $config;
|
||||
# FIXME internalize
|
||||
$pos = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -$snmpver -c $community -t 1 $hostname:$port sysObjectID.0");
|
||||
if ($pos == '') {
|
||||
if ($pos == '')
|
||||
{
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function isPingable($hostname) {
|
||||
function isPingable($hostname)
|
||||
{
|
||||
global $config;
|
||||
$status = shell_exec($config['fping'] . " $hostname");
|
||||
if (strstr($status, "alive")) {
|
||||
if (strstr($status, "alive"))
|
||||
{
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function is_odd($number) {
|
||||
function is_odd($number)
|
||||
{
|
||||
return $number & 1; // 0 = even, 1 = odd
|
||||
}
|
||||
|
||||
function isValidInterface($if) {
|
||||
function isValidInterface($if)
|
||||
{
|
||||
global $config;
|
||||
$if = strtolower($if);
|
||||
$nullintf = 0;
|
||||
foreach($config['bad_if'] as $bi) {
|
||||
foreach($config['bad_if'] as $bi)
|
||||
{
|
||||
$pos = strpos($if, $bi);
|
||||
if ($pos !== FALSE) {
|
||||
if ($pos !== FALSE)
|
||||
{
|
||||
$nullintf = 1;
|
||||
echo("$if matched $bi \n");
|
||||
}
|
||||
}
|
||||
if (preg_match('/serial[0-9]:/', $if)) { $nullintf = '1'; }
|
||||
if ($nullintf != '1') {
|
||||
if ($nullintf != '1')
|
||||
{
|
||||
return 1;
|
||||
} else { return 0; }
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function utime()
|
||||
@@ -509,7 +530,8 @@ function match_network ($nets, $ip, $first=false)
|
||||
{
|
||||
$return = false;
|
||||
if (!is_array ($nets)) $nets = array ($nets);
|
||||
foreach ($nets as $net) {
|
||||
foreach ($nets as $net)
|
||||
{
|
||||
$rev = (preg_match ("/^\!/", $net)) ? true : false;
|
||||
$net = preg_replace ("/^\!/", "", $net);
|
||||
$ip_arr = explode('/', $net);
|
||||
@@ -517,7 +539,8 @@ function match_network ($nets, $ip, $first=false)
|
||||
$x = ip2long($ip_arr[1]);
|
||||
$mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]);
|
||||
$ip_long = ip2long($ip);
|
||||
if ($rev) {
|
||||
if ($rev)
|
||||
{
|
||||
if (($ip_long & $mask) == ($net_long & $mask)) return false;
|
||||
} else {
|
||||
if (($ip_long & $mask) == ($net_long & $mask)) $return = true;
|
||||
@@ -565,19 +588,22 @@ function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_orig
|
||||
{
|
||||
$i_query = "SELECT interface_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
|
||||
$interface_id = mysql_result(mysql_query($i_query), 0);
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') {
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
|
||||
echo("N");
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1') {
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
|
||||
echo("N");
|
||||
}
|
||||
|
||||
$ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0);
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0') {
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `interface_id`)
|
||||
VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$interface_id')");
|
||||
echo("+");
|
||||
@@ -664,22 +690,34 @@ function notify($device,$title,$message)
|
||||
|
||||
function formatCiscoHardware(&$device, $short = false)
|
||||
{
|
||||
|
||||
if ($device['os'] == "ios") {
|
||||
if ($device['hardware']) {
|
||||
if (preg_match("/^WS-C([A-Za-z0-9]+).*/", $device['hardware'], $matches)) {
|
||||
if (!$short) {
|
||||
if ($device['os'] == "ios")
|
||||
{
|
||||
if ($device['hardware'])
|
||||
{
|
||||
if (preg_match("/^WS-C([A-Za-z0-9]+).*/", $device['hardware'], $matches))
|
||||
{
|
||||
if (!$short)
|
||||
{
|
||||
$device['hardware'] = "Cisco " . $matches[1] . " (" . $device['hardware'] . ")";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$device['hardware'] = "Cisco " . $matches[1];
|
||||
}
|
||||
} elseif (preg_match("/^CISCO([0-9]+)$/", $device['hardware'], $matches)) {
|
||||
}
|
||||
elseif (preg_match("/^CISCO([0-9]+)$/", $device['hardware'], $matches))
|
||||
{
|
||||
$device['hardware'] = "Cisco " . $matches[1];
|
||||
}
|
||||
} else {
|
||||
if (preg_match("/Cisco IOS Software, C([A-Za-z0-9]+) Software.*/", $device['sysDescr'], $matches)) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (preg_match("/Cisco IOS Software, C([A-Za-z0-9]+) Software.*/", $device['sysDescr'], $matches))
|
||||
{
|
||||
$device['hardware'] = "Cisco " . $matches[1];
|
||||
} elseif (preg_match("/Cisco IOS Software, ([0-9]+) Software.*/", $device['sysDescr'], $matches)) {
|
||||
}
|
||||
elseif (preg_match("/Cisco IOS Software, ([0-9]+) Software.*/", $device['sysDescr'], $matches))
|
||||
{
|
||||
$device['hardware'] = "Cisco " . $matches[1];
|
||||
}
|
||||
}
|
||||
@@ -690,10 +728,12 @@ function formatCiscoHardware(&$device, $short = false)
|
||||
function hex2str($hex)
|
||||
{
|
||||
$string='';
|
||||
|
||||
for ($i=0; $i < strlen($hex)-1; $i+=2)
|
||||
{
|
||||
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
+88
-56
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
|
||||
function formatMac($mac) {
|
||||
function formatMac($mac)
|
||||
{
|
||||
$mac = preg_replace("/(..)(..)(..)(..)(..)(..)/", "\\1:\\2:\\3:\\4:\\5:\\6", $mac);
|
||||
return $mac;
|
||||
}
|
||||
|
||||
function rewrite_entity_descr ($descr) {
|
||||
|
||||
function rewrite_entity_descr ($descr)
|
||||
{
|
||||
$descr = str_replace("Distributed Forwarding Card", "DFC", $descr);
|
||||
$descr = preg_replace("/7600 Series SPA Interface Processor-/", "7600 SIP-", $descr);
|
||||
$descr = preg_replace("/Rev\.\ [0-9\.]+\ /", "", $descr);
|
||||
@@ -28,30 +29,38 @@ function rewrite_entity_descr ($descr) {
|
||||
return $descr;
|
||||
}
|
||||
|
||||
function ifNameDescr($interface, $device = NULL) {
|
||||
function ifNameDescr($interface, $device = NULL)
|
||||
{
|
||||
return ifLabel($interface, $device);
|
||||
}
|
||||
|
||||
function ifLabel ($interface, $device = NULL) {
|
||||
function ifLabel ($interface, $device = NULL)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!$device) { $device = device_by_id_cache($interface['device_id']); }
|
||||
$os = strtolower($device['os']);
|
||||
|
||||
if (isset($config['os'][$os]['ifname'])) {
|
||||
if (isset($config['os'][$os]['ifname']))
|
||||
{
|
||||
$interface['label'] = $interface['ifName'];
|
||||
} elseif (isset($config['os'][$os]['ifalias'])) {
|
||||
} elseif (isset($config['os'][$os]['ifalias']))
|
||||
{
|
||||
$interface['label'] = $interface['ifAlias'];
|
||||
} else {
|
||||
$interface['label'] = $interface['ifDescr'];
|
||||
if (isset($config['os'][$os]['ifindex'])) { $interface['label'] = $interface['label'] . " " . $interface['ifIndex']; }
|
||||
if (isset($config['os'][$os]['ifindex']))
|
||||
{
|
||||
$interface['label'] = $interface['label'] . " " . $interface['ifIndex'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($device['os'] == "speedtouch") {
|
||||
if ($device['os'] == "speedtouch")
|
||||
{
|
||||
list($interface['label']) = explode("thomson", $interface['label']);
|
||||
}
|
||||
|
||||
return $interface;
|
||||
|
||||
}
|
||||
|
||||
$rewrite_entSensorType = array (
|
||||
@@ -72,11 +81,15 @@ $translate_ifOperStatus = array(
|
||||
"7" => "lowerLayerDown",
|
||||
);
|
||||
|
||||
function translate_ifOperStatus ($ifOperStatus) {
|
||||
function translate_ifOperStatus ($ifOperStatus)
|
||||
{
|
||||
global $translate_ifOperStatus;
|
||||
if($translate_ifOperStatus['$ifOperStatus']) {
|
||||
|
||||
if ($translate_ifOperStatus['$ifOperStatus'])
|
||||
{
|
||||
$ifOperStatus = $translate_ifOperStatus['$ifOperStatus'];
|
||||
}
|
||||
|
||||
return $ifOperStatus;
|
||||
}
|
||||
|
||||
@@ -86,11 +99,15 @@ $translate_ifAdminStatus = array(
|
||||
"3" => "testing",
|
||||
);
|
||||
|
||||
function translate_ifAdminStatus ($ifAdminStatus) {
|
||||
function translate_ifAdminStatus ($ifAdminStatus)
|
||||
{
|
||||
global $translate_ifAdminStatus;
|
||||
if($translate_ifAdminStatus[$ifAdminStatus]) {
|
||||
|
||||
if ($translate_ifAdminStatus[$ifAdminStatus])
|
||||
{
|
||||
$ifAdminStatus = $translate_ifAdminStatus[$ifAdminStatus];
|
||||
}
|
||||
|
||||
return $ifAdminStatus;
|
||||
}
|
||||
|
||||
@@ -278,7 +295,6 @@ $rewrite_extreme_hardware = array (
|
||||
'.1.3.6.1.4.1.1916.2.79' => 'Summit X450e-48p'
|
||||
);
|
||||
|
||||
|
||||
$rewrite_ironware_hardware = array(
|
||||
'snFIWGSwitch' => 'Stackable FastIron workgroup',
|
||||
'snFIBBSwitch' => 'Stackable FastIron backbone',
|
||||
@@ -702,39 +718,37 @@ $rewrite_ironware_hardware = array(
|
||||
);
|
||||
|
||||
$rewrite_ios_features = array(
|
||||
"PK9S" => "IP w/SSH LAN Only",
|
||||
"LANBASEK9" => "Lan Base Crypto",
|
||||
"LANBASE" => "Lan Base",
|
||||
"ADVENTERPRISEK9_IVS" => "Advanced Enterprise Crypto Voice",
|
||||
"ADVENTERPRISEK9" => "Advanced Enterprise Crypto",
|
||||
"ADVSECURITYK9" => "Advanced Security Crypto",
|
||||
"K91P" => "Provider Crypto",
|
||||
"K4P" => "Provider Crypto",
|
||||
"ADVIPSERVICESK9" => "Adv IP Services Crypto",
|
||||
"ADVIPSERVICES" => "Adv IP Services",
|
||||
"IK9P" => "IP Plus Crypto",
|
||||
"K9O3SY7" => "IP ADSL FW IDS Plus IPSEC 3DES",
|
||||
"SPSERVICESK9" => "SP Services Crypto",
|
||||
"PK9SV" => "IP MPLS/IPV6 W/SSH + BGP",
|
||||
"IS" => "IP Plus",
|
||||
"IPSERVICESK9" => "IP Services Crypto",
|
||||
"BROADBAND" => "Broadband",
|
||||
"IPBASE" => "IP Base",
|
||||
"IPSERVICE" => "IP Services",
|
||||
"P" => "Service Provider",
|
||||
"P11" => "Broadband Router",
|
||||
"G4P5" => "NRP",
|
||||
"JK9S" => "Enterprise Plus Crypto",
|
||||
"IK9S" => "IP Plus Crypto",
|
||||
"JK" => "Enterprise Plus",
|
||||
"I6Q4L2" => "Layer 2",
|
||||
"I6K2L2Q4" => "Layer 2 Crypto",
|
||||
"C3H2S" => "Layer 2 SI/EI",
|
||||
"_WAN" => " + WAN",
|
||||
'PK9S' => 'IP w/SSH LAN Only',
|
||||
'LANBASEK9' => 'Lan Base Crypto',
|
||||
'LANBASE' => 'Lan Base',
|
||||
'ADVENTERPRISEK9_IVS' => 'Advanced Enterprise Crypto Voice',
|
||||
'ADVENTERPRISEK9' => 'Advanced Enterprise Crypto',
|
||||
'ADVSECURITYK9' => 'Advanced Security Crypto',
|
||||
'K91P' => 'Provider Crypto',
|
||||
'K4P' => 'Provider Crypto',
|
||||
'ADVIPSERVICESK9' => 'Adv IP Services Crypto',
|
||||
'ADVIPSERVICES' => 'Adv IP Services',
|
||||
'IK9P' => 'IP Plus Crypto',
|
||||
'K9O3SY7' => 'IP ADSL FW IDS Plus IPSEC 3DES',
|
||||
'SPSERVICESK9' => 'SP Services Crypto',
|
||||
'PK9SV' => 'IP MPLS/IPV6 W/SSH + BGP',
|
||||
'IS' => 'IP Plus',
|
||||
'IPSERVICESK9' => 'IP Services Crypto',
|
||||
'BROADBAND' => 'Broadband',
|
||||
'IPBASE' => 'IP Base',
|
||||
'IPSERVICE' => 'IP Services',
|
||||
'P' => 'Service Provider',
|
||||
'P11' => 'Broadband Router',
|
||||
'G4P5' => 'NRP',
|
||||
'JK9S' => 'Enterprise Plus Crypto',
|
||||
'IK9S' => 'IP Plus Crypto',
|
||||
'JK' => 'Enterprise Plus',
|
||||
'I6Q4L2' => 'Layer 2',
|
||||
'I6K2L2Q4' => 'Layer 2 Crypto',
|
||||
'C3H2S' => 'Layer 2 SI/EI',
|
||||
'_WAN' => ' + WAN',
|
||||
);
|
||||
|
||||
|
||||
|
||||
$rewrite_shortif = array (
|
||||
'tengigabitethernet' => 'Te',
|
||||
'gigabitethernet' => 'Gi',
|
||||
@@ -808,23 +822,29 @@ $rewrite_ios_features = array(
|
||||
function makeshortif ($if)
|
||||
{
|
||||
global $rewrite_shortif;
|
||||
|
||||
$if = fixifName ($if);
|
||||
$if = strtolower($if);
|
||||
$if = array_str_replace($rewrite_shortif, $if);
|
||||
|
||||
return $if;
|
||||
}
|
||||
|
||||
function rewrite_ios_features ($features)
|
||||
{
|
||||
global $rewrite_ios_features;
|
||||
|
||||
$type = array_preg_replace($rewrite_ios_features, $features);
|
||||
|
||||
return ($features);
|
||||
}
|
||||
|
||||
function rewrite_fortinet_hardware ($hardware)
|
||||
{
|
||||
global $rewrite_fortinet_hardware;
|
||||
|
||||
$hardware = $rewrite_fortinet_hardware[$hardware];
|
||||
|
||||
return ($hardware);
|
||||
}
|
||||
|
||||
@@ -832,15 +852,19 @@ function rewrite_fortinet_hardware ($hardware)
|
||||
function rewrite_extreme_hardware ($hardware)
|
||||
{
|
||||
global $rewrite_extreme_hardware;
|
||||
|
||||
#$hardware = array_str_replace($rewrite_extreme_hardware, $hardware);
|
||||
$hardware = $rewrite_extreme_hardware[$hardware];
|
||||
|
||||
return ($hardware);
|
||||
}
|
||||
|
||||
function rewrite_ftos_hardware ($hardware)
|
||||
{
|
||||
global $rewrite_ftos_hardware;
|
||||
|
||||
$hardware = $rewrite_ftos_hardware[$hardware];
|
||||
|
||||
return ($hardware);
|
||||
}
|
||||
|
||||
@@ -848,43 +872,53 @@ function rewrite_ftos_hardware ($hardware)
|
||||
function rewrite_ironware_hardware ($hardware)
|
||||
{
|
||||
global $rewrite_ironware_hardware;
|
||||
|
||||
$hardware = array_str_replace($rewrite_ironware_hardware, $hardware);
|
||||
|
||||
return ($hardware);
|
||||
}
|
||||
|
||||
function rewrite_junose_hardware ($hardware)
|
||||
{
|
||||
global $rewrite_junose_hardware;
|
||||
|
||||
$hardware = array_str_replace($rewrite_junose_hardware, $hardware);
|
||||
|
||||
return ($hardware);
|
||||
}
|
||||
|
||||
function fixiftype ($type)
|
||||
{
|
||||
global $rewrite_iftype;
|
||||
|
||||
$type = array_preg_replace($rewrite_iftype, $type);
|
||||
|
||||
return ($type);
|
||||
}
|
||||
|
||||
function fixifName ($inf)
|
||||
{
|
||||
global $rewrite_ifname;
|
||||
|
||||
$inf = strtolower($inf);
|
||||
$inf = array_str_replace($rewrite_ifname, $inf);
|
||||
|
||||
return $inf;
|
||||
}
|
||||
|
||||
function short_hrDeviceDescr($dev)
|
||||
{
|
||||
global $rewrite_hrDevice;
|
||||
|
||||
$dev = array_str_replace($rewrite_hrDevice, $dev);
|
||||
$dev = preg_replace("/\ +/"," ", $dev);
|
||||
$dev = trim($dev);
|
||||
|
||||
return $dev;
|
||||
}
|
||||
|
||||
function short_port_descr ($desc) {
|
||||
|
||||
function short_port_descr ($desc)
|
||||
{
|
||||
list($desc) = explode("(", $desc);
|
||||
list($desc) = explode("[", $desc);
|
||||
list($desc) = explode("{", $desc);
|
||||
@@ -893,29 +927,27 @@ function short_port_descr ($desc) {
|
||||
$desc = trim($desc);
|
||||
|
||||
return $desc;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Underlying rewrite functions
|
||||
|
||||
|
||||
function array_str_replace($array, $string)
|
||||
{
|
||||
foreach ($array as $search => $replace) {
|
||||
foreach ($array as $search => $replace)
|
||||
{
|
||||
$string = str_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
function array_preg_replace($array, $string)
|
||||
{
|
||||
foreach ($array as $search => $replace) {
|
||||
foreach ($array as $search => $replace)
|
||||
{
|
||||
$string = preg_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -477,7 +477,8 @@ function snmp_cache_oid($oid, $device, $array, $mib = 0)
|
||||
return $array;
|
||||
}
|
||||
|
||||
function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) {
|
||||
function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
|
||||
+27
-14
@@ -1,36 +1,47 @@
|
||||
<?php
|
||||
|
||||
function process_syslog ($entry, $update) {
|
||||
|
||||
function process_syslog ($entry, $update)
|
||||
{
|
||||
global $config;
|
||||
|
||||
foreach($config['syslog_filter'] as $bi) {
|
||||
if (strstr($entry['msg'], $bi) !== FALSE) {
|
||||
foreach($config['syslog_filter'] as $bi)
|
||||
{
|
||||
if (strstr($entry['msg'], $bi) !== FALSE)
|
||||
{
|
||||
$delete = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$device_id_host = @mysql_result(mysql_query("SELECT device_id FROM devices WHERE `hostname` = '".$entry['host']."' OR `sysName` = '".$entry['host']."'"),0);
|
||||
|
||||
if($device_id_host) {
|
||||
if($device_id_host)
|
||||
{
|
||||
$entry['device_id'] = $device_id_host;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$device_id_ip = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE
|
||||
A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id"),0);
|
||||
if($device_id_ip) {
|
||||
if($device_id_ip)
|
||||
{
|
||||
$entry['device_id'] = $device_id_ip;
|
||||
}
|
||||
}
|
||||
|
||||
if($entry['device_id'] && !$delete) {
|
||||
if($entry['device_id'] && !$delete)
|
||||
{
|
||||
$os = mysql_result(mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '".$entry['device_id']."'"),0);
|
||||
if($os == "ios" || $os == "iosxe") {
|
||||
if(strstr($entry[msg], "%")) {
|
||||
if($os == "ios" || $os == "iosxe")
|
||||
{
|
||||
if(strstr($entry[msg], "%"))
|
||||
{
|
||||
$entry['msg'] = preg_replace("/^%(.+?):\ /", "\\1||", $entry['msg']);
|
||||
list(,$entry[msg]) = split(": %", $entry['msg']);
|
||||
$entry['msg'] = "%" . $entry['msg'];
|
||||
$entry['msg'] = preg_replace("/^%(.+?):\ /", "\\1||", $entry['msg']);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$entry['msg'] = preg_replace("/^.*[0-9]:/", "", $entry['msg']);
|
||||
$entry['msg'] = preg_replace("/^[0-9][0-9]\ [A-Z]{3}:/", "", $entry['msg']);
|
||||
$entry['msg'] = preg_replace("/^(.+?):\ /", "\\1||", $entry['msg']);
|
||||
@@ -42,14 +53,17 @@ function process_syslog ($entry, $update) {
|
||||
list($entry['program'], $entry['msg']) = explode("||", $entry['msg']);
|
||||
$entry['msg'] = preg_replace("/^[0-9]+:/", "", $entry['msg']);
|
||||
|
||||
if(!$entry['program']) {
|
||||
if(!$entry['program'])
|
||||
{
|
||||
$entry['msg'] = preg_replace("/^([0-9A-Z\-]+?):\ /", "\\1||", $entry['msg']);
|
||||
list($entry['program'], $entry['msg']) = explode("||", $entry['msg']);
|
||||
}
|
||||
|
||||
if(!$entry['msg']) { $entry['msg'] = $entry['program']; unset ($entry['program']); }
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$program = preg_quote($entry['program'],'/');
|
||||
$entry['msg'] = preg_replace("/^$program:\ /", "", $entry['msg']);
|
||||
# if(preg_match("/^[a-zA-Z\/]+\[[0-9]+\]:/", $entry['msg'])) {
|
||||
@@ -71,5 +85,4 @@ function process_syslog ($entry, $update) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
+20
-15
@@ -3,7 +3,6 @@
|
||||
|
||||
$debug = "1";
|
||||
|
||||
|
||||
include("includes/defaults.inc.php");
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
@@ -13,18 +12,19 @@ $iter = "0";
|
||||
echo("Starting Polling Session ... \n\n");
|
||||
|
||||
$bill_query = mysql_query("select * from bills");
|
||||
while ($bill_data = mysql_fetch_array($bill_query)) {
|
||||
while ($bill_data = mysql_fetch_array($bill_query))
|
||||
{
|
||||
echo("Bill : ".$bill_data['bill_name']."\n");
|
||||
|
||||
CollectData($bill_data['bill_id']);
|
||||
|
||||
$iter++;
|
||||
}
|
||||
|
||||
function CollectData($bill_id) {
|
||||
function CollectData($bill_id)
|
||||
{
|
||||
$port_query = mysql_query("select * from bill_ports as P, ports as I, devices as D where P.bill_id='$bill_id' AND I.interface_id = P.port_id AND D.device_id = I.device_id");
|
||||
|
||||
while ($port_data = mysql_fetch_array($port_query)) {
|
||||
while ($port_data = mysql_fetch_array($port_query))
|
||||
{
|
||||
unset($port_in_measurement);
|
||||
unset($port_in_delta);
|
||||
unset($last_port_in_measurement);
|
||||
@@ -48,10 +48,12 @@ function CollectData($bill_id) {
|
||||
$now = mysql_result(mysql_query("SELECT NOW()"), 0);
|
||||
|
||||
$last_data = getLastPortCounter($port_id,in);
|
||||
if ($last_data[state] == "ok") {
|
||||
if ($last_data[state] == "ok")
|
||||
{
|
||||
$last_port_in_measurement = $last_data[counter];
|
||||
$last_port_in_delta = $last_data[delta];
|
||||
if ($port_in_measurement > $last_port_in_measurement) {
|
||||
if ($port_in_measurement > $last_port_in_measurement)
|
||||
{
|
||||
$port_in_delta = $port_in_measurement - $last_port_in_measurement;
|
||||
} else {
|
||||
$port_in_delta = $last_port_in_delta;
|
||||
@@ -65,10 +67,12 @@ function CollectData($bill_id) {
|
||||
unset($last_data, $last_port_in_measurement, $last_port_in_delta);
|
||||
|
||||
$last_data = getLastPortCounter($port_id,out);
|
||||
if ($last_data[state] == "ok") {
|
||||
if ($last_data[state] == "ok")
|
||||
{
|
||||
$last_port_out_measurement = $last_data[counter];
|
||||
$last_port_out_delta = $last_data[delta];
|
||||
if ($port_out_measurement > $last_port_out_measurement) {
|
||||
if ($port_out_measurement > $last_port_out_measurement)
|
||||
{
|
||||
$port_out_delta = $port_out_measurement - $last_port_out_measurement;
|
||||
} else {
|
||||
$port_out_delta = $last_port_out_delta;
|
||||
@@ -89,7 +93,8 @@ function CollectData($bill_id) {
|
||||
}
|
||||
$last_data = getLastMeasurement($bill_id);
|
||||
|
||||
if ($last_data[state] == "ok") {
|
||||
if ($last_data[state] == "ok")
|
||||
{
|
||||
$prev_delta = $last_data[delta];
|
||||
$prev_in_delta = $last_data[in_delta];
|
||||
$prev_out_delta = $last_data[out_delta];
|
||||
@@ -101,18 +106,18 @@ function CollectData($bill_id) {
|
||||
$prev_in_delta = '0';
|
||||
$prev_out_delta = '0';
|
||||
}
|
||||
if( $delta < '0' ) {
|
||||
|
||||
if ($delta < '0' )
|
||||
{
|
||||
$delta = $prev_delta;
|
||||
$in_delta = $prev_in_delta;
|
||||
$out_delta = $prev_out_delta;
|
||||
|
||||
}
|
||||
$insert_string = "INSERT INTO bill_data (bill_id,timestamp,period,delta,in_delta,out_delta) VALUES ('$bill_id','$now','$period','$delta','$in_delta','$out_delta')";
|
||||
#echo("$insert_string\n");
|
||||
$insert_measurement = mysql_query($insert_string);
|
||||
}
|
||||
|
||||
if ($argv[1]) { CollectData($argv[1]); }
|
||||
|
||||
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user