mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
code and formatting cleanups
git-svn-id: http://www.observium.org/svn/observer/trunk@1804 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -127,7 +127,7 @@ function getHostOS($device)
|
||||
$dir_handle = @opendir($config['install_dir'] . "/includes/discovery/os") or die("Unable to open $path");
|
||||
while ($file = readdir($dir_handle))
|
||||
{
|
||||
if ( preg_match("/.php$/", $file) )
|
||||
if (preg_match("/.php$/", $file) )
|
||||
{
|
||||
include($config['install_dir'] . "/includes/discovery/os/" . $file);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ 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];
|
||||
@@ -185,7 +185,8 @@ function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/ou
|
||||
global $config;
|
||||
$cmd = $config['rrdtool']." fetch -s $period -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5";
|
||||
$data = trim(shell_exec($cmd));
|
||||
foreach( explode("\n", $data) as $entry) {
|
||||
foreach (explode("\n", $data) as $entry)
|
||||
{
|
||||
list($in, $out) = explode(" ", $entry);
|
||||
$in_errors += ($in * 300);
|
||||
$out_errors += ($out * 300);
|
||||
@@ -288,11 +289,15 @@ function addHost($host, $community, $snmpver, $port = 161)
|
||||
{
|
||||
global $config;
|
||||
list($hostshort) = explode(".", $host);
|
||||
if ( isDomainResolves($host)) {
|
||||
if ( isPingable($host)) {
|
||||
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) {
|
||||
if (isDomainResolves($host))
|
||||
{
|
||||
if (isPingable($host))
|
||||
{
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' )
|
||||
{
|
||||
$snmphost = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0");
|
||||
if ($snmphost == $host || $hostshort = $host) {
|
||||
if ($snmphost == $host || $hostshort = $host)
|
||||
{
|
||||
createHost ($host, $community, $snmpver, $port);
|
||||
} else { echo("Given hostname does not match SNMP-read hostname!\n"); }
|
||||
} else { echo("Already got host $host\n"); }
|
||||
@@ -402,7 +407,7 @@ function isValidInterface($if) {
|
||||
|
||||
function utime()
|
||||
{
|
||||
$time = explode( " ", microtime());
|
||||
$time = explode(" ", microtime());
|
||||
$usec = (double)$time[0];
|
||||
$sec = (double)$time[1];
|
||||
return $sec + $usec;
|
||||
@@ -554,7 +559,8 @@ function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_orig
|
||||
if ($ipv6_type == "Link-Local Unicast Addresses") return; # ignore link-locals (coming from IPV6-MIB)
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM `ports`
|
||||
WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
|
||||
WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1')
|
||||
{
|
||||
$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') {
|
||||
@@ -573,7 +579,11 @@ function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_orig
|
||||
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("+");
|
||||
} else { echo("."); }
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
$full_address = "$ipv6_address/$ipv6_prefixlen";
|
||||
$valid = $full_address . "-" . $interface_id;
|
||||
$valid_v6[$valid] = 1;
|
||||
@@ -618,7 +628,7 @@ function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
|
||||
{
|
||||
global $debug;
|
||||
|
||||
if(!is_array($device)) { $device = device_by_id_cache($device); }
|
||||
if (!is_array($device)) { $device = device_by_id_cache($device); }
|
||||
|
||||
$event_query = "INSERT INTO eventlog (host, reference, type, datetime, message) VALUES (" . ($device['device_id'] ? $device['device_id'] : "NULL");
|
||||
$event_query .= ", '" . ($reference ? $reference : "NULL") . "', '" . ($type ? $type : "NULL") . "', NOW(), '" . mres($text) . "')";
|
||||
@@ -630,9 +640,9 @@ function notify($device,$title,$message)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if($config['alerts']['email']['enable'])
|
||||
if ($config['alerts']['email']['enable'])
|
||||
{
|
||||
if($config['alerts']['email']['default_only'])
|
||||
if ($config['alerts']['email']['default_only'])
|
||||
{
|
||||
$email = $config['alerts']['email']['default'];
|
||||
} else {
|
||||
@@ -643,7 +653,7 @@ function notify($device,$title,$message)
|
||||
$email = $config['alerts']['email']['default'];
|
||||
}
|
||||
}
|
||||
if($email)
|
||||
if ($email)
|
||||
{
|
||||
mail($email, $title, $message, $config['email_headers']);
|
||||
}
|
||||
@@ -701,7 +711,7 @@ function isHexString($str)
|
||||
function include_dir($dir, $regex = "")
|
||||
{
|
||||
global $device, $config, $debug;
|
||||
if ( $regex == "")
|
||||
if ($regex == "")
|
||||
{
|
||||
$regex = "/\.inc\.php$/";
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
#-r RETRIES set the number of retries
|
||||
#-t TIMEOUT set the request timeout (in seconds)
|
||||
|
||||
#$config['snmp']['timeout'] = 300; # timeout in ms
|
||||
#$config['snmp']['retries'] = 6; # how many times to retry the query
|
||||
|
||||
function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir = NULL)
|
||||
{
|
||||
global $debug,$config,$runtime_stats,$mibs_loaded;
|
||||
@@ -74,8 +68,10 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir
|
||||
function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
|
||||
{
|
||||
global $debug,$config,$runtime_stats,$mibs_loaded;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
|
||||
if ($config['snmp']['internal'] == true)
|
||||
{
|
||||
if ($mib && $mibdir && !$mibs_loaded[$mib])
|
||||
@@ -93,12 +89,14 @@ function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
|
||||
$data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
}
|
||||
if ($debug) { print "DEBUG: $oid: $data\n"; }
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd = $config['snmpget'] . " -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
|
||||
if ($options) { $cmd .= " " . $options; }
|
||||
if ($mib) { $cmd .= " -m " . $mib; }
|
||||
if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; }
|
||||
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
|
||||
@@ -109,22 +107,31 @@ function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
|
||||
if ($debug) { echo("$data\n"); }
|
||||
}
|
||||
$runtime_stats['snmpget']++;
|
||||
if (is_string($data) && (preg_match("/No Such Instance/i", $data) || preg_match("/No Such Object/i", $data) || preg_match("/No more variables left/i", $data))) { return false; }
|
||||
if (is_string($data) && (preg_match("/No Such Instance/i", $data) || preg_match("/No Such Object/i", $data) || preg_match("/No more variables left/i", $data)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
elseif ($data) { return $data; }
|
||||
else { return false; }
|
||||
}
|
||||
|
||||
function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL) {
|
||||
function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
|
||||
{
|
||||
global $debug,$config,$runtime_stats;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
|
||||
// php has no bulkwalk functionality, so use binary for this.
|
||||
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) {
|
||||
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk'])
|
||||
{
|
||||
$snmpcommand = $config['snmpwalk'];
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
$snmpcommand = $config['snmpbulkwalk'];
|
||||
}
|
||||
|
||||
$cmd = $snmpcommand . " -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
if ($options) { $cmd .= " $options "; }
|
||||
if ($mib) { $cmd .= " -m $mib"; }
|
||||
@@ -132,15 +139,18 @@ function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oid;
|
||||
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
if ($debug) { echo("$cmd\n"); }
|
||||
$data = trim(shell_exec($cmd));
|
||||
if ($debug) { echo("$data\n"); }
|
||||
|
||||
if (is_string($data) && (preg_match("/No Such (Object|Instance)/i", $data)))
|
||||
{
|
||||
$data = false;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (preg_match("/No more variables left in this MIB View \(It is past the end of the MIB tree\)$/",$data)) {
|
||||
# Bit ugly :-(
|
||||
$d_ex = explode("\n",$data);
|
||||
@@ -149,30 +159,41 @@ function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
|
||||
}
|
||||
}
|
||||
$runtime_stats['snmpwalk']++;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function snmpwalk_cache_cip($device, $oid, $array, $mib = 0) {
|
||||
function snmpwalk_cache_cip($device, $oid, $array, $mib = 0)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) {
|
||||
|
||||
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk'])
|
||||
{
|
||||
$snmpcommand = $config['snmpwalk'];
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
$snmpcommand = $config['snmpbulkwalk'];
|
||||
}
|
||||
|
||||
$cmd = $snmpcommand . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
if ($mib) { $cmd .= " -m $mib"; }
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oid;
|
||||
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
|
||||
#echo("Caching: $oid\n");
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
foreach(explode("\n", $data) as $entry)
|
||||
{
|
||||
list ($this_oid, $this_value) = preg_split("/=/", $entry);
|
||||
$this_oid = trim($this_oid);
|
||||
$this_value = trim($this_value);
|
||||
@@ -186,18 +207,23 @@ function snmpwalk_cache_cip($device, $oid, $array, $mib = 0) {
|
||||
$h_f = zeropad(dechex($f));
|
||||
$mac = "$h_a$h_b$h_c$h_d$h_e$h_f";
|
||||
if ($dir == "1") { $dir = "input"; } elseif ($dir == "2") { $dir = "output"; }
|
||||
if ($mac && $dir) {
|
||||
if ($mac && $dir)
|
||||
{
|
||||
$array[$ifIndex][$mac][$oid][$dir] = $this_value;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
function snmp_cache_ifIndex($device)
|
||||
{
|
||||
// FIXME: this has no internal version, and is not yet using our own snmp_*
|
||||
global $config;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
|
||||
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk'])
|
||||
{
|
||||
$snmpcommand = $config['snmpwalk'];
|
||||
@@ -206,38 +232,47 @@ function snmp_cache_ifIndex($device)
|
||||
{
|
||||
$snmpcommand = $config['snmpbulkwalk'];
|
||||
}
|
||||
|
||||
$cmd = $snmpcommand . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
$cmd .= " -m IF-MIB ifIndex";
|
||||
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
|
||||
foreach(explode("\n", $data) as $entry)
|
||||
{
|
||||
list ($this_oid, $this_value) = preg_split("/=/", $entry);
|
||||
list ($this_oid, $this_index) = explode(".", $this_oid);
|
||||
$this_index = trim($this_index);
|
||||
$this_oid = trim($this_oid);
|
||||
$this_value = trim($this_value);
|
||||
if (!strstr($this_value, "at this OID") && $this_index) {
|
||||
if (!strstr($this_value, "at this OID") && $this_index)
|
||||
{
|
||||
$array[] = $this_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
function snmpwalk_cache_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL)
|
||||
{
|
||||
$data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir);
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
foreach(explode("\n", $data) as $entry)
|
||||
{
|
||||
list($oid,$value) = explode("=", $entry);
|
||||
$oid = trim($oid); $value = trim($value);
|
||||
list($oid, $index) = explode(".", $oid);
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($index)) {
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($index))
|
||||
{
|
||||
$array[$index][$oid] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -275,15 +310,19 @@ function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = NULL, $mibdir =
|
||||
function snmpwalk_cache_double_oid($device, $oid, $array, $mib = NULL, $mibdir = NULL)
|
||||
{
|
||||
$data = snmp_walk($device, $oid, "-OQUs", $mib, $mibdir);
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
|
||||
foreach(explode("\n", $data) as $entry)
|
||||
{
|
||||
list($oid,$value) = explode("=", $entry);
|
||||
$oid = trim($oid); $value = trim($value);
|
||||
list($oid, $first, $second) = explode(".", $oid);
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) {
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second))
|
||||
{
|
||||
$double = $first.".".$second;
|
||||
$array[$double][$oid] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -294,11 +333,13 @@ function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = NULL, $mibdir =
|
||||
list($oid,$value) = explode("=", $entry);
|
||||
$oid = trim($oid); $value = trim($value);
|
||||
list($oid, $first, $second, $third) = explode(".", $oid);
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) {
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second))
|
||||
{
|
||||
$index = $first.".".$second.".".$third;
|
||||
$array[$index][$oid] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -307,8 +348,10 @@ function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = NULL, $mibdir =
|
||||
function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
|
||||
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk'])
|
||||
{
|
||||
$snmpcommand = $config['snmpwalk'];
|
||||
@@ -326,21 +369,27 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0)
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
foreach(explode("\n", $data) as $entry)
|
||||
{
|
||||
list($oid,$value) = explode("=", $entry);
|
||||
$oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value);
|
||||
list($oid, $first, $second) = explode(".", $oid);
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) {
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second))
|
||||
{
|
||||
$array[$first][$second][$oid] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0) {
|
||||
function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
|
||||
{
|
||||
global $config, $debug;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
|
||||
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk'])
|
||||
{
|
||||
$snmpcommand = $config['snmpwalk'];
|
||||
@@ -349,6 +398,7 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0) {
|
||||
{
|
||||
$snmpcommand = $config['snmpbulkwalk'];
|
||||
}
|
||||
|
||||
$cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if ($mib) { $cmd .= " -m $mib"; }
|
||||
@@ -357,23 +407,30 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0) {
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oid;
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
|
||||
$device_id = $device['device_id'];
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
foreach(explode("\n", $data) as $entry)
|
||||
{
|
||||
list($oid,$value) = explode("=", $entry);
|
||||
$oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value);
|
||||
list($oid, $first, $second, $third) = explode(".", $oid);
|
||||
if ($debug) {echo("$entry || $oid || $first || $second || $third\n");}
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third)) {
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third))
|
||||
{
|
||||
$array[$first][$second][$third][$oid] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) {
|
||||
function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
|
||||
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk'])
|
||||
{
|
||||
$snmpcommand = $config['snmpwalk'];
|
||||
@@ -382,6 +439,7 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) {
|
||||
{
|
||||
$snmpcommand = $config['snmpbulkwalk'];
|
||||
}
|
||||
|
||||
$cmd = $snmpcommand . " -O QUs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
if ($mib) { $cmd .= " -m $mib"; }
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
@@ -391,16 +449,19 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) {
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
|
||||
foreach(explode("\n", $data) as $entry)
|
||||
{
|
||||
$entry = str_replace($oid.".", "", $entry);
|
||||
list($slotport, $value) = explode("=", $entry);
|
||||
$slotport = trim($slotport); $value = trim($value);
|
||||
if ($array[$slotport]['ifIndex']) {
|
||||
if ($array[$slotport]['ifIndex'])
|
||||
{
|
||||
$ifIndex = $array[$slotport]['ifIndex'];
|
||||
#$array[$slotport][$oid] = $value;
|
||||
$array[$ifIndex][$oid] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -412,11 +473,15 @@ function snmp_cache_oid($oid, $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']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
foreach($oids as $oid){
|
||||
|
||||
foreach($oids as $oid)
|
||||
{
|
||||
$string .= " $oid.$port";
|
||||
}
|
||||
|
||||
$cmd = $config['snmpget'] . " -O vq -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
@@ -435,13 +500,17 @@ function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) {
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
function snmp_cache_portIfIndex ($device, $array) {
|
||||
function snmp_cache_portIfIndex ($device, $array)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
|
||||
$cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O q -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
@@ -449,7 +518,9 @@ function snmp_cache_portIfIndex ($device, $array) {
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." portIfIndex";
|
||||
$output = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
foreach(explode("\n", $output) as $entry){
|
||||
|
||||
foreach(explode("\n", $output) as $entry)
|
||||
{
|
||||
$entry = str_replace("CISCO-STACK-MIB::portIfIndex.", "", $entry);
|
||||
list($slotport, $ifIndex) = explode(" ", $entry);
|
||||
if ($slotport && $ifIndex){
|
||||
@@ -457,13 +528,17 @@ function snmp_cache_portIfIndex ($device, $array) {
|
||||
$array[$slotport]['ifIndex'] = $ifIndex;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
function snmp_cache_portName ($device, $array) {
|
||||
function snmp_cache_portName ($device, $array)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (is_numeric($device['timeout'])) { $timeout = $device['timeout']; } elseif (isset($config['snmp']['timeout'])) { $timeout = $config['snmp']['timeout']; }
|
||||
if (is_numeric($device['retries'])) { $retries = $device['retries']; } elseif (isset($config['snmp']['retries'])) { $retries = $config['snmp']['retries']; }
|
||||
|
||||
$cmd = $config['snmpwalk'] . " -CI -m CISCO-STACK-MIB -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " ";
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
@@ -472,16 +547,20 @@ function snmp_cache_portName ($device, $array) {
|
||||
$output = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
#echo("Caching: portName\n");
|
||||
foreach(explode("\n", $output) as $entry){
|
||||
|
||||
foreach(explode("\n", $output) as $entry)
|
||||
{
|
||||
$entry = str_replace("portName.", "", $entry);
|
||||
list($slotport, $portName) = explode("=", $entry);
|
||||
$slotport = trim($slotport); $portName = trim($portName);
|
||||
if ($array[$slotport]['ifIndex']) {
|
||||
if ($array[$slotport]['ifIndex'])
|
||||
{
|
||||
$ifIndex = $array[$slotport]['ifIndex'];
|
||||
$array[$slotport]['portName'] = $portName;
|
||||
$array[$ifIndex]['portName'] = $portName;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user