mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-01 00:24:21 +02:00
small fixes
git-svn-id: http://www.observium.org/svn/observer/trunk@1755 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -1,56 +1,64 @@
|
||||
<?php
|
||||
|
||||
echo("IP Addresses : ");
|
||||
|
||||
# FIXME function!
|
||||
$oids = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m IP-MIB -".$device['snmpver']." -Osq -c ".$device['community']." ".$device['hostname'].":".$device['port']." ipAdEntIfIndex");
|
||||
$oids = trim($oids);
|
||||
$oids = str_replace("ipAdEntIfIndex.", "", $oids);
|
||||
foreach(explode("\n", $oids) as $data) {
|
||||
$data = trim($data);
|
||||
list($oid,$ifIndex) = explode(" ", $data);
|
||||
# FIXME function!
|
||||
$mask = shell_exec($config['snmpget']. " -M " . $config['mibdir'] ." -m IP-MIB -O qv -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." ipAdEntNetMask.$oid");
|
||||
$mask = trim($mask);
|
||||
$network = trim(shell_exec ($config['ipcalc'] . " $oid/$mask | grep Network | cut -d\" \" -f 4"));
|
||||
list($net,$cidr) = explode("/", $network);
|
||||
$cidr = trim($cidr);
|
||||
if($mask == "255.255.255.255") { $cidr = "32"; $network = "$oid/$cidr"; }
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $oid != "0.0.0.0") {
|
||||
$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 `ipv4_networks` WHERE `ipv4_network` = '$network'"), 0) < '1') {
|
||||
mysql_query("INSERT INTO `ipv4_networks` (`ipv4_network`) VALUES ('$network')");
|
||||
#echo("Create Subnet $network\n");
|
||||
echo("S");
|
||||
}
|
||||
$ipv4_network_id = @mysql_result(mysql_query("SELECT `ipv4_network_id` from `ipv4_networks` WHERE `ipv4_network` = '$network'"), 0);
|
||||
echo("IP Addresses : ");
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = '$oid' AND `ipv4_prefixlen` = '$cidr' AND `interface_id` = '$interface_id'"), 0) == '0') {
|
||||
mysql_query("INSERT INTO `ipv4_addresses` (`ipv4_address`, `ipv4_prefixlen`, `ipv4_network_id`, `interface_id`) VALUES ('$oid', '$cidr', '$ipv4_network_id', '$interface_id')");
|
||||
#echo("Added $oid/$cidr to $interface_id ( $hostname $ifIndex )\n $i_query\n");
|
||||
echo("+");
|
||||
} else { echo("."); }
|
||||
$full_address = "$oid/$cidr|$ifIndex";
|
||||
$valid_v4[$full_address] = 1;
|
||||
} else { echo("!"); }
|
||||
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.interface_id = I.interface_id";
|
||||
$data = mysql_query($sql);
|
||||
while($row = mysql_fetch_array($data)) {
|
||||
$full_address = $row['ipv4_address'] . "/" . $row['ipv4_prefixlen'] . "|" . $row['ifIndex'];
|
||||
if(!$valid_v4[$full_address]) {
|
||||
echo("-");
|
||||
$query = @mysql_query("DELETE FROM `ipv4_addresses` WHERE `ipv4_address_id` = '".$row['ipv4_address_id']."'");
|
||||
if(!mysql_result(mysql_query("SELECT count(*) FROM ipv4_addresses WHERE ipv4_network_id = '".$row['ipv4_network_id']."'"),0)) {
|
||||
$query = @mysql_query("DELETE FROM `ipv4_networks` WHERE `ipv4_network_id` = '".$row['ipv4_network_id']."'");
|
||||
}
|
||||
}
|
||||
$oids = trim(snmp_walk($device,"ipAdEntIfIndex","-Osq","IP-MIB"));
|
||||
$oids = str_replace("ipAdEntIfIndex.", "", $oids);
|
||||
foreach(explode("\n", $oids) as $data)
|
||||
{
|
||||
$data = trim($data);
|
||||
list($oid,$ifIndex) = explode(" ", $data);
|
||||
$mask = trim(snmp_get($device,"ipAdEntNetMask.$oid","-Oqv","IP-MIB"));
|
||||
#FIXME internalize?
|
||||
$network = trim(shell_exec ($config['ipcalc'] . " $oid/$mask | grep Network | cut -d\" \" -f 4"));
|
||||
list($net,$cidr) = explode("/", $network);
|
||||
$cidr = trim($cidr);
|
||||
if ($mask == "255.255.255.255") { $cidr = "32"; $network = "$oid/$cidr"; }
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $oid != "0.0.0.0")
|
||||
{
|
||||
$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 `ipv4_networks` WHERE `ipv4_network` = '$network'"), 0) < '1')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv4_networks` (`ipv4_network`) VALUES ('$network')");
|
||||
#echo("Create Subnet $network\n");
|
||||
echo("S");
|
||||
}
|
||||
|
||||
$ipv4_network_id = @mysql_result(mysql_query("SELECT `ipv4_network_id` from `ipv4_networks` WHERE `ipv4_network` = '$network'"), 0);
|
||||
|
||||
echo("\n");
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = '$oid' AND `ipv4_prefixlen` = '$cidr' AND `interface_id` = '$interface_id'"), 0) == '0')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv4_addresses` (`ipv4_address`, `ipv4_prefixlen`, `ipv4_network_id`, `interface_id`) VALUES ('$oid', '$cidr', '$ipv4_network_id', '$interface_id')");
|
||||
#echo("Added $oid/$cidr to $interface_id ( $hostname $ifIndex )\n $i_query\n");
|
||||
echo("+");
|
||||
} else { echo("."); }
|
||||
|
||||
$full_address = "$oid/$cidr|$ifIndex";
|
||||
$valid_v4[$full_address] = 1;
|
||||
} else { echo("!"); }
|
||||
|
||||
unset($valid_v4);
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.interface_id = I.interface_id";
|
||||
$data = mysql_query($sql);
|
||||
while($row = mysql_fetch_array($data))
|
||||
{
|
||||
$full_address = $row['ipv4_address'] . "/" . $row['ipv4_prefixlen'] . "|" . $row['ifIndex'];
|
||||
|
||||
if (!$valid_v4[$full_address])
|
||||
{
|
||||
echo("-");
|
||||
$query = @mysql_query("DELETE FROM `ipv4_addresses` WHERE `ipv4_address_id` = '".$row['ipv4_address_id']."'");
|
||||
if (!mysql_result(mysql_query("SELECT count(*) FROM ipv4_addresses WHERE ipv4_network_id = '".$row['ipv4_network_id']."'"),0))
|
||||
{
|
||||
$query = @mysql_query("DELETE FROM `ipv4_networks` WHERE `ipv4_network_id` = '".$row['ipv4_network_id']."'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
||||
unset($valid_v4);
|
||||
?>
|
||||
|
||||
@@ -4,7 +4,7 @@ global $valid_sensor;
|
||||
|
||||
if (strstr($device['hardware'], "dell"))
|
||||
{
|
||||
$oids = snmp_walk($device, ".1.3.6.1.4.1.674.10892.1.700.20.1.8", "-Osqn", "MIB-Dell-10892");
|
||||
$oids = snmp_walk($device, "coolingDeviceDiscreteReading", "-Osqn", "MIB-Dell-10892");
|
||||
$oids = trim($oids);
|
||||
if ($oids) echo("Dell OMSA ");
|
||||
foreach(explode("\n",$oids) as $oid)
|
||||
@@ -16,8 +16,8 @@ if (strstr($device['hardware'], "dell"))
|
||||
$descr_query = snmp_get($device, ".1.3.6.1.4.1.674.10892.1.700.20.1.8.$oid", "-Onvq", "MIB-Dell-10892");
|
||||
$descr = trim(str_replace("\"", "", shell_exec($descr_query)));
|
||||
$fulloid = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.$oid";
|
||||
### FIXME CURRENT
|
||||
discover_sensor($valid_sensor, 'temperature', $device, $fulloid, $oid, 'dell', $descr, '10', '1', NULL, NULL, NULL, NULL, NULL);
|
||||
$temp = snmp_get($device, $fulloid, "-Oqv");
|
||||
discover_sensor($valid_sensor, 'temperature', $device, $fulloid, $oid, 'dell', $descr, '10', '1', NULL, NULL, NULL, NULL, $temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user