mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 00:24:21 +02:00
ipv4/ipv6 udp/tcp transport support patch
git-svn-id: http://www.observium.org/svn/observer/trunk@1860 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -62,6 +62,7 @@ $config['ports_page_default'] = "details/"; ## eg "details/" "graphs/bits/"
|
||||
#$config['snmp']['retries'] = 5; # how many times to retry the query
|
||||
$config['snmp']['community'][] = "public"; # Communities to try during discovery (dangerous)
|
||||
$config['snmp']['internal'] = false; # Enable php_snmp functions to make gets faster
|
||||
$config['snmp']['transports'] = array('udp', 'udp6', 'tcp', 'tcp6');
|
||||
|
||||
### Autodiscovery Settings
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ if ($device['os_group'] == "unix")
|
||||
{
|
||||
# FIXME snmp_walk
|
||||
# ObserverNMS-style temperature
|
||||
$oids = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -M " . $config['mibdir'] . " -".$device['snmpver']." -m SNMPv2-SMI -Osqn -CI -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.4.1.2021.7891 | sed s/.1.3.6.1.4.1.2021.7891.// | grep '.1.1 ' | grep -v '.101.' | cut -d'.' -f 1");
|
||||
$oids = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -M " . $config['mibdir'] . " -".$device['snmpver']." -m SNMPv2-SMI -Osqn -CI -c ".$device['community']." ".$device['transport'].":".$device['hostname'].":".$device['port']." .1.3.6.1.4.1.2021.7891 | sed s/.1.3.6.1.4.1.2021.7891.// | grep '.1.1 ' | grep -v '.101.' | cut -d'.' -f 1");
|
||||
$oids = trim($oids);
|
||||
if ($oids) echo("Observer-Style ");
|
||||
foreach (explode("\n",$oids) as $oid)
|
||||
|
||||
+31
-18
@@ -291,7 +291,7 @@ function delete_device($id)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function addHost($host, $community, $snmpver, $port = 161)
|
||||
function addHost($host, $community, $snmpver, $port = 161, $transport = 'udp')
|
||||
{
|
||||
global $config;
|
||||
list($hostshort) = explode(".", $host);
|
||||
@@ -305,7 +305,7 @@ function addHost($host, $community, $snmpver, $port = 161)
|
||||
$snmphost = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0");
|
||||
if ($snmphost == $host || $hostshort = $host)
|
||||
{
|
||||
createHost ($host, $community, $snmpver, $port);
|
||||
createHost ($host, $community, $snmpver, $port, $transport);
|
||||
} else { echo("Given hostname does not match SNMP-read hostname!\n"); }
|
||||
} else { echo("Already got host $host\n"); }
|
||||
} else { echo("Could not ping $host\n"); }
|
||||
@@ -328,6 +328,18 @@ function scanUDP ($host, $port, $timeout)
|
||||
} else { fclose($handle); return 0; }
|
||||
}
|
||||
|
||||
function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp')
|
||||
{
|
||||
$device = array();
|
||||
$device['hostname'] = $host;
|
||||
$device['port'] = $port;
|
||||
$device['community'] = $community;
|
||||
$device['snmpver'] = $snmpver;
|
||||
$device['transport'] = $transport;
|
||||
|
||||
return $device;
|
||||
}
|
||||
|
||||
function netmask2cidr($netmask)
|
||||
{
|
||||
$addr = Net_IPv4::parseAddress("1.2.3.4/$netmask");
|
||||
@@ -372,17 +384,17 @@ function formatUptime($diff, $format="long")
|
||||
return trim($uptime);
|
||||
}
|
||||
|
||||
function isSNMPable($hostname, $community, $snmpver, $port)
|
||||
function isSNMPable($device)
|
||||
{
|
||||
global $config;
|
||||
# FIXME internalize
|
||||
$pos = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -$snmpver -c $community -t 1 $hostname:$port sysObjectID.0");
|
||||
if ($pos == '')
|
||||
{
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
global $config;
|
||||
|
||||
$pos = snmp_get($device, "sysObjectID.0", "-Oqv", "SNMPv2-MIB");
|
||||
if ($pos === '' || $pos === false)
|
||||
{
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function isPingable($hostname)
|
||||
@@ -486,14 +498,15 @@ function fixIOSHardware($hardware)
|
||||
|
||||
}
|
||||
|
||||
function createHost ($host, $community, $snmpver, $port = 161)
|
||||
function createHost ($host, $community, $snmpver, $port = 161, $proto = 'udp')
|
||||
{
|
||||
$host = trim(strtolower($host));
|
||||
$device = array('hostname' => $host, 'community' => $community, 'snmpver' => $snmpver, 'port' => $port);
|
||||
$host_os = getHostOS($device);
|
||||
$device = deviceArray($host, $community, $snmpver, $port, $proto);
|
||||
$host_os = getHostOS($device);
|
||||
|
||||
if ($host_os)
|
||||
{
|
||||
$sql = mysql_query("INSERT INTO `devices` (`hostname`, `sysName`, `community`, `port`, `os`, `status`,`snmpver`) VALUES ('$host', '$host', '$community', '$port', '$host_os', '1','$snmpver')");
|
||||
$sql = mysql_query("INSERT INTO `devices` (`hostname`, `sysName`, `community`, `port`, `transport`, `os`, `status`,`snmpver`) VALUES ('$host', '$host', '$community', '$port', '$transport', '$host_os', '1','$snmpver')");
|
||||
if (mysql_affected_rows())
|
||||
{
|
||||
$device_id = mysql_result(mysql_query("SELECT device_id FROM devices WHERE hostname = '$host'"),0);
|
||||
@@ -514,7 +527,7 @@ function createHost ($host, $community, $snmpver, $port = 161)
|
||||
|
||||
function isDomainResolves($domain)
|
||||
{
|
||||
return gethostbyname($domain) != $domain;
|
||||
return count(dns_get_record($domain)) != 0;
|
||||
}
|
||||
|
||||
function hoststatus($id)
|
||||
@@ -772,4 +785,4 @@ function include_dir($dir, $regex = "")
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
+17
-17
@@ -34,11 +34,11 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir
|
||||
{
|
||||
if ($device['snmpver'] == "v2c")
|
||||
{
|
||||
$data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
$data = @snmp2_get($device['transport'].":".$device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
}
|
||||
elseif ($device['snmpver'] == "v1")
|
||||
{
|
||||
$data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
$data = @snmpget($device['transport'].":".$device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
}
|
||||
|
||||
list($oid, $index) = explode(".", $oid);
|
||||
@@ -56,7 +56,7 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oids;
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oids;
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
if ($debug) { echo("$cmd\n"); }
|
||||
$data = trim(shell_exec($cmd));
|
||||
@@ -112,9 +112,9 @@ function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
|
||||
if (isset($timeout)) { $timeout = $timeout*1000*1000; }
|
||||
if ($device['snmpver'] == "v2c")
|
||||
{
|
||||
$data = @snmp2_get($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
} elseif ($device['snmpver'] == "v1") {
|
||||
$data = @snmpget($device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
$data = @snmp2_get($device['transport'].":".$device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
} elseif ( $device['snmpver'] == "v1") {
|
||||
$data = @snmpget($device['transport'].":".$device['hostname'].":".$device['port'], $device['community'], $oid, $timeout, $retries);
|
||||
}
|
||||
if ($debug) { print "DEBUG: $oid: $data\n"; }
|
||||
}
|
||||
@@ -128,7 +128,7 @@ function snmp_get($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;
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
if ($debug) { echo("$cmd\n"); }
|
||||
$data = trim(shell_exec($cmd));
|
||||
@@ -178,7 +178,7 @@ function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
|
||||
if ($mibdir) { $cmd .= " -M " . $mibdir; } else { $cmd .= " -M ".$config['mibdir']; }
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oid;
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
|
||||
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
if ($debug) { echo("$cmd\n"); }
|
||||
@@ -235,8 +235,8 @@ function snmpwalk_cache_cip($device, $oid, $array, $mib = 0)
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oid;
|
||||
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
|
||||
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
@@ -440,7 +440,7 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0)
|
||||
if ($mib) { $cmd .= " -m $mib"; }
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oid;
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
@@ -490,7 +490,7 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
|
||||
if ($mib) { $cmd .= " -m $mib"; }
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oid;
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
|
||||
@@ -542,7 +542,7 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0)
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$oid;
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
@@ -597,7 +597,7 @@ function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0)
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if ($mib) { $cmd .= " -m $mib"; }
|
||||
$cmd .= " -t " . $timeout . " -r " . $retries;
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." ".$string;
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$string;
|
||||
if (!$debug) { $cmd .= " 2>/dev/null"; }
|
||||
$data = trim(shell_exec($cmd));
|
||||
$x=0;
|
||||
@@ -636,7 +636,7 @@ function snmp_cache_portIfIndex($device, $array)
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." portIfIndex";
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." portIfIndex";
|
||||
$output = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
|
||||
@@ -675,7 +675,7 @@ function snmp_cache_portName($device, $array)
|
||||
$cmd .= " -M ".$config['install_dir']."/mibs/";
|
||||
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
|
||||
if (isset($retries)) { $cmd .= " -r " . $retries; }
|
||||
$cmd .= " ".$device['hostname'].":".$device['port']." portName";
|
||||
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." portName";
|
||||
$output = trim(shell_exec($cmd));
|
||||
$device_id = $device['device_id'];
|
||||
#echo("Caching: portName\n");
|
||||
@@ -696,4 +696,4 @@ function snmp_cache_portName($device, $array)
|
||||
return $array;
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user