new discovery infrastructure. woohoo!

git-svn-id: http://www.observium.org/svn/observer/trunk@194 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2008-03-22 23:09:35 +00:00
parent ca79fe6629
commit 48214c4dd2
12 changed files with 229 additions and 242 deletions

View File

@@ -1,49 +0,0 @@
#!/usr/bin/php
<?
include("config.php");
include("includes/functions.php");
# Discover interfaces
$device_query = mysql_query("SELECT device_id,hostname,community,snmpver FROM `devices` WHERE `device_id` LIKE '%" . $argv[1] . "' AND status = '1' AND os != 'Snom' ORDER BY device_id DESC");
while ($device = mysql_fetch_row($device_query)) {
$id = $device['0'];
$hostname = $device['1'];
$community = $device['2'];
$snmpver = $device['3'];
$interfaces = `snmpwalk -O nsq -v2c -c $community $hostname ".1.3.6.1.2.1.2.2.1.2" | sed s/ifDescr.//g | sed s/\ \"/\|\|\"/g | sed s/\ /\|\|/g`;
$interfaces = trim($interfaces);
echo("Polling $hostname\n");
foreach(explode("\n", $interfaces) as $entry){
$entry = trim($entry);
list($ifIndex, $ifName) = explode("||", $entry);
if(!strstr($entry, "irtual")) {
$ifName = trim(str_replace("\"", "", $ifName));
$if = trim(strtolower($ifName));
$nullintf = 0;
foreach($config['bad_if'] as $bi) {
# echo("'$bi' -> '$if'\n");
if (strstr($if, $bi)) {
echo("'$bi' -> '$if' MATCH!\n");
$nullintf = 1;
}
}
if (preg_match('/serial[0-9]:/', $if)) { $nullintf = '1'; }
if (preg_match('/ng[0-9]+$/', $if)) { $nullintf = '1'; }
if ($nullintf == 0) {
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `device_id` = '$id' AND `ifIndex` = '$ifIndex'"), 0) == '0') {
echo "Adding port $ifName \n";
mysql_query("INSERT INTO `interfaces` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('$id','$ifIndex','$ifName')");
} else {
# echo("Already have $ifName \n");
}
} else {
# echo("Invalid $ifName\n");
}
}
}
}
?>

View File

@@ -1,11 +0,0 @@
./discover-ifs.php 1 &
./discover-ifs.php 2 &
./discover-ifs.php 3 &
./discover-ifs.php 4 &
./discover-ifs.php 5 &
./discover-ifs.php 6 &
./discover-ifs.php 7 &
./discover-ifs.php 8 &
./discover-ifs.php 9 &
./discover-ifs.php 0 &

49
discovery.php Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/php
<?php
include("config.php");
include("includes/functions.php");
$start = utime();
### Observer Device Discovery
echo("Observer v".$config['version']." Discovery\n\n");
$devices_polled = 0;
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1'");
while ($device = mysql_fetch_array($device_query)) {
echo($device['hostname'] ."\n");
## Discover Interfaces
include("includes/discovery/interfaces.php");
## Discover IP Addresses
include("includes/discovery/ipaddresses.php");
## Discover Temperatures
include("includes/discovery/temperatures.php");
if($device['os'] == "Linux") {
include("includes/discovery/storage.php");
}
if($device['os'] == "IOS") {
include("includes/discovery/cisco-vlans.php");
include("includes/discovery/cisco-physical.php");
include("includes/discovery/bgp-peers.php");
}
echo("\n"); $devices_polled++;
}
$end = utime(); $run = $end - $start;
$proctime = substr($run, 0, 5);
echo("$devices_polled devices polled in $proctime secs\n");
?>

View File

@@ -1,15 +1,8 @@
#!/usr/bin/php
<?
include("config.php");
include("includes/functions.php");
if(!$config['enable_bgp']) { echo("BGP Support Disabled\n"); exit; }
### Discover BGP peers on Cisco devices
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os = 'IOS' ORDER BY device_id desc");
while ($device = mysql_fetch_array($device_query)) {
echo("\nPolling ". $device['hostname'] . "\n");
echo("BGP Sessions : ");
$as_cmd = $config['snmpwalk'] . " -CI -Oqvn -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . " ";
$as_cmd .= ".1.3.6.1.2.1.15.2";
@@ -17,7 +10,7 @@ while ($device = mysql_fetch_array($device_query)) {
if($bgpLocalAs) {
echo("Host AS is $bgpLocalAs\n");
echo("AS$bgpLocalAs ");
if($bgpLocalAs != $device['bgpLocalAs']) { mysql_query("UPDATE devices SET bgpLocalAs = '$bgpLocalAs' WHERE device_id = '".$device['device_id']."'"); echo("Updated AS\n"); }
@@ -33,37 +26,35 @@ while ($device = mysql_fetch_array($device_query)) {
$astext = trim(str_replace("\"", "", shell_exec("/usr/bin/dig +short AS$peer_as.asn.cymru.com TXT | cut -d '|' -f 5")));
echo(str_pad($peer_ip, 32). str_pad($astext, 32) . " $peer_as ");
#echo(str_pad($peer_ip, 32). str_pad($astext, 32) . " $peer_as ");
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '$peer_ip'"),0) < '1') {
$add = mysql_query("INSERT INTO bgpPeers (`device_id`, `bgpPeerIdentifier`, `bgpPeerRemoteAS`) VALUES ('".$device['device_id']."','$peer_ip','$peer_as')");
if($add) { echo(" Added \n"); } else { echo(" Add failed\n"); }
echo("+");
} else {
#Â$peer_data = mysql_fetch_array(mysql_query("SELECT * FROM `bgpPeers``device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '$peer_ip' "));
echo(" Exists\n");
echo(".");
$update = mysql_query("UPDATE `bgpPeers` SET astext = '$astext' WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '$peer_ip'");
}
} # End if
} # End foreach
} # End BGP check
} # End While
} # If Peer
} # Foreach
} else { echo("No BGP on host"); } # End if
## Delete removed peers
$sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.status = '1'";
$sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($entry = mysql_fetch_array($query)) {
unset($exists);
$i = 0;
while ($i < count($peerlist) && !$exists) {
$this = $entry['device_id'] . " " . $entry['bgpPeerIdentifier'];
if ($peerlist[$i] == $this) { $exists = 1; }
$checkme = $entry['device_id'] . " " . $entry['bgpPeerIdentifier'];
if ($peerlist[$i] == $checkme) { $exists = 1; }
$i++;
}
if(!$exists) {
mysql_query("DELETE FROM bgpPeers WHERE bgpPeer_id = '" . $entry['bgpPeer_id'] . "'");
echo("-");
}
}

View File

@@ -1,13 +1,6 @@
#!/usr/bin/php
<?php
include("config.php");
include("includes/functions.php");
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os = 'IOS' order by device_id DESC");
while ($device = mysql_fetch_array($device_query)) {
echo("Discovering Physical Entities on " . $device['hostname'] . "\n");
echo("Physical Inventory : ");
$ents_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ";
$ents_cmd .= "1.3.6.1.2.1.47.1.1.1.1.2 | sed s/.1.3.6.1.2.1.47.1.1.1.1.2.//g | cut -f 1 -d\" \"";
@@ -34,15 +27,6 @@ while ($device = mysql_fetch_array($device_query)) {
if(strpos($ifIndex, "o") || $ifIndex == "") { unset($ifIndex); }
# if ($entPhysicalVendorTypes['$entPhysicalVendorType']) {
# $entPhysicalVendorType = $entPhysicalVendorTypes['$entPhysicalVendorType'];
# } else {
# $entPhysicalVendorType_new = `grep $entPhysicalVendorType\ /usr/share/snmp/mibs/CISCO-ENTITY-VENDORTYPE-OID-MIB.my | sed s/.*\-\-\ //| grep -v \=`;
# $entPhysicalVendorTypes['$entPhysicalVendorType'] = $entPhysicalVendorType_new;
# $entPhysicalVendorType = $entPhysicalVendorType_new;
# }
$entPhysicalModelName = trim($entPhysicalModelName);
$entPhysicalSerialNum = trim($entPhysicalSerialNum);
$entPhysicalMfgName = trim($entPhysicalMfgName);
@@ -51,28 +35,26 @@ while ($device = mysql_fetch_array($device_query)) {
if ($entPhysicalVendorTypes[$entPhysicalVendorType] && !$entPhysicalModelName) {
$entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType];
}
#else { unset($entPhysicalVendorType); }
echo("$entPhysicalIndex,$entPhysicalDescr,$entPhysicalContainedIn,$entPhysicalSerialNum,");
echo("$entPhysicalClass,$entPhysicalName,$entPhysicalModelName,$entPhysicalMfgName,$entPhysicalVendorType,$entPhysicalParentRelPos\n");
#echo("$entPhysicalIndex,$entPhysicalDescr,$entPhysicalContainedIn,$entPhysicalSerialNum,");
#echo("$entPhysicalClass,$entPhysicalName,$entPhysicalModelName,$entPhysicalMfgName,$entPhysicalVendorType,$entPhysicalParentRelPos\n");
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `entPhysical` WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '$entPhysicalIndex'"),0)) {
## MySQL Update
# echo("already\n");
### TO DO : WRITE CODE FOR UPDATES!
echo(".");
} else {
# echo("insert\n");
$sql = "INSERT INTO `entPhysical` ( `device_id` , `entPhysicalIndex` , `entPhysicalDescr` , `entPhysicalClass` , `entPhysicalName` , `entPhysicalModelName` , `entPhysicalSerialNum` , `entPhysicalContainedIn`, `entPhysicalMfgName`, `entPhysicalParentRelPos`, `entPhysicalVendorType`, `ifIndex` ) ";
$sql .= "VALUES ( '" . $device['device_id'] . "', '$entPhysicalIndex', '$entPhysicalDescr', '$entPhysicalClass', '$entPhysicalName', '$entPhysicalModelName', '$entPhysicalSerialNum', '$entPhysicalContainedIn', '$entPhysicalMfgName','$entPhysicalParentRelPos' , '$entPhysicalVendorType', '$ifIndex')";
# echo($sql . "\n");
mysql_query($sql);
echo(mysql_error());
echo("+");
}
}
echo("\n");
}
?>

View File

@@ -1,15 +1,8 @@
#!/usr/bin/php
<?
include("config.php");
include("includes/functions.php");
echo("Cisco VLANs : ");
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os = 'IOS'");
while ($device = mysql_fetch_array($device_query)) {
echo("Discovering VLANs on " . $device['hostname'] . "\n");
$vtpversion_cmd = "snmpget -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.9.9.46.1.1.1.0";
$vtpversion_cmd = $config['snmpget'] . " -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.9.9.46.1.1.1.0";
$vtpversion = trim(`$vtpversion_cmd 2>/dev/null`);
if($vtpversion == '1' || $vtpversion == '2') {
@@ -17,7 +10,7 @@ while ($device = mysql_fetch_array($device_query)) {
$vtp_domain_cmd = "snmpget -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.9.9.46.1.2.1.1.2.1";
$vtp_domain = trim(str_replace("\"", "", `$vtp_domain_cmd 2>/dev/null`));
echo("VLAN Trunking Protocol Version $vtpversion Domain : $vtp_domain\n");
echo("VTP v$vtpversion $vtp_domain ");
$vlans_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ";
$vlans_cmd .= "1.3.6.1.4.1.9.9.46.1.3.1.1.2.1 | sed s/.1.3.6.1.4.1.9.9.46.1.3.1.1.2.1.//g | cut -f 1 -d\" \"";
@@ -33,11 +26,10 @@ while ($device = mysql_fetch_array($device_query)) {
$vlan_descr = trim(str_replace("\"", "", $vlan_descr));
if(mysql_result(mysql_query("SELECT COUNT(vlan_id) FROM `vlans` WHERE `device_id` = '" . $device['device_id'] . "' AND `vlan_domain` = '" . $vtp_domain . "' AND `vlan_vlan` = '" . $vlan . "'"), 0) == '0') {
echo "Adding VLAN $vlan - $vlan_descr \n";
mysql_query("INSERT INTO `vlans` (`device_id`,`vlan_domain`,`vlan_vlan`, `vlan_descr`) VALUES (" . $device['device_id'] . ",'" . $vtp_domain . "','$vlan', '$vlan_descr')");
}
echo("+");
} else { echo("."); }
echo("VLAN $vlan ($vlan_descr)\n");
$this_vlans[] = $vlan;
@@ -49,7 +41,14 @@ while ($device = mysql_fetch_array($device_query)) {
foreach($this_vlans as $test_vlan) {
if($test_vlan == $dev_vlan['vlan_vlan']) { $vlan_exists = 1; }
}
if(!$vlan_exists) { mysql_query("DELETE FROM `vlans` WHERE `vlan_id` = '" . $dev_vlan['vlan_id'] . "'"); echo("Deleted VLAN ". $dev_vlan['vlan_vlan'] ."\n"); }
if(!$vlan_exists) {
mysql_query("DELETE FROM `vlans` WHERE `vlan_id` = '" . $dev_vlan['vlan_id'] . "'");
echo("-");
#echo("Deleted VLAN ". $dev_vlan['vlan_vlan'] ."\n");
}
}
}
}
unset($this_vlans);
echo("\n");

View File

@@ -0,0 +1,49 @@
<?
# Discover interfaces
echo("Interfaces : ");
# $cmd = $config['snmpwalk'] . " -O nsq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.2.1.2.2.1.2 | sed s/ifDescr.//g | sed s/\ \"/\|\|\"/g | sed s/\ /\|\|/g";
$cmd = $config['snmpwalk'] . " -O nsq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.2.1.2.2.1.2";
$interfaces = trim(shell_exec($cmd));
$interfaces = str_replace("\"", "", $interfaces);
$interfaces = str_replace("ifDescr.", "", $interfaces);
$interfaces = str_replace(" ", "||", $interfaces);
$interface_ignored = 0;
$interface_added = 0;
foreach(explode("\n", $interfaces) as $entry){
$entry = trim($entry);
list($ifIndex, $ifName) = explode("||", $entry);
if(!strstr($entry, "irtual")) {
$ifName = trim(str_replace("\"", "", $ifName));
$if = trim(strtolower($ifName));
$nullintf = 0;
foreach($config['bad_if'] as $bi) {
if (strstr($if, $bi)) {
$nullintf = 1;
}
}
if (preg_match('/serial[0-9]:/', $if)) { $nullintf = '1'; }
if (preg_match('/ng[0-9]+$/', $if)) { $nullintf = '1'; }
if ($nullintf == 0) {
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') {
# mysql_query("INSERT INTO `interfaces` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('$id','$ifIndex','$ifName')");
echo("+");
} else {
# Interface Already Exists
echo(".");
}
} else {
# Ignored ifName
echo("X");
}
}
}
echo("\n");
?>

View File

@@ -0,0 +1,47 @@
<?php
echo("IP Addresses : ");
$oids = shell_exec($config['snmpwalk'] . " -".$device['snmpver']." -Osq -c ".$device['community']." ".$device['hostname']." ipAdEntIfIndex");
$oids = trim($oids);
$oids = str_replace("ipAdEntIfIndex.", "", $oids);
foreach(explode("\n", $oids) as $data) {
$data = trim($data);
list($oid,$ifIndex) = explode(" ", $data);
$mask = shell_exec($config['snmpget']." -O qv -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." ipAdEntNetMask.$oid");
$mask = trim($mask);
$network = trim(`$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 `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0') {
$i_query = "SELECT interface_id FROM `interfaces` 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 `ipaddr` WHERE `addr` = '$oid' AND `cidr` = '$cidr' AND `interface_id` = '$interface_id'"), 0) == '0') {
mysql_query("INSERT INTO `ipaddr` (`addr`, `cidr`, `network`, `interface_id`) VALUES ('$oid', '$cidr', '$net', '$interface_id')");
#echo("Added $oid/$cidr to $interface_id ( $hostname $ifIndex )\n $i_query\n");
echo("+");
} else { echo("."); }
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `networks` WHERE `cidr` = '$network'"), 0) < '1') {
mysql_query("INSERT INTO `networks` (`id`, `cidr`) VALUES ('', '$network')");
#echo("Create Subnet $network\n");
echo("S");
}
$network_id = mysql_result(mysql_query("SELECT id from `networks` WHERE `cidr` = '$network'"), 0);
if (match_network($config['nets'], $oid) && mysql_result(mysql_query("SELECT COUNT(*) FROM `adjacencies` WHERE `network_id` = '$network_id' AND `interface_id` = '$interface_id'"), 0) < '1') {
mysql_query("INSERT INTO `adjacencies` (`network_id`, `interface_id`) VALUES ('$network_id', '$interface_id')");
#echo("Create Adjacency : $hostname, $interface_id, $network_id, $network, $ifIndex\n");
echo("A");
}
} else { echo("!"); }
}
echo("\n");
?>

View File

@@ -1,44 +1,40 @@
#!/usr/bin/php
<?
include("config.php");
include("includes/functions.php");
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os = 'Linux' OR os = 'FreeBSD' OR os = 'NetBSD' OR os = 'OpenBSD' OR os = 'DragonFly' ORDER BY `device_id` DESC");
while ($device = mysql_fetch_array($device_query)) {
$id = $device['device_id'];
$hostname = $device['hostname'];
$community = $device['community'];
echo("\n***$hostname***\n");
$oids = `snmpwalk -v2c -Osq -c $community $hostname hrStorageIndex | sed s/hrStorageIndex.//g`;
$oids = trim($oids);
unset( $storage_exists );
echo("Storage : ");
$oids = shell_exec($config['snmpwalk'] . " -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " hrStorageIndex");
$oids = trim(str_replace("hrStorageIndex.","",$oids));
foreach(explode("\n", $oids) as $data) {
$data = trim($data);
list($oid,$hrStorageIndex) = explode(" ", $data);
$temp = `snmpget -O qv -v2c -c $community $hostname hrStorageDescr.$oid hrStorageAllocationUnits.$oid hrStorageSize.$oid hrStorageType.$oid`;
$temp = shell_exec($config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " hrStorageDescr.$oid hrStorageAllocationUnits.$oid hrStorageSize.$oid hrStorageType.$oid");
$temp = trim($temp);
list($descr, $units, $size, $type) = explode("\n", $temp);
list($units) = explode(" ", $units);
if(strstr($type, "FixedDisk") && $size > '0') {
if(mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'"),0) == '0') {
if(mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '".$device['device_id']."'"),0) == '0') {
$query = "INSERT INTO storage (`host_id`, `hrStorageIndex`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) ";
$query .= "values ('$id', '$hrStorageIndex', '$descr', '$size', '$units')";
$query .= "values ('".$device['device_id']."', '$hrStorageIndex', '$descr', '$size', '$units')";
mysql_query($query);
echo("Adding $descr\n");
echo("+");
} else {
$data = mysql_fetch_array(mysql_query("SELECT * FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'"));
$data = mysql_fetch_array(mysql_query("SELECT * FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '".$device['device_id']."'"));
if($data['hrStorageDescr'] != $descr || $data['hrStorageSize'] != $size || $data['hrStorageAllocationUnits'] != $units ) {
$query = "UPDATE storage SET `hrStorageDescr` = '$descr', `hrStorageSize` = '$size', `hrStorageAllocationUnits` = '$units' ";
$query .= "WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'";
echo("Updating $descr\n");
$query .= "WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '".$device['device_id']."'";
echo("U");
mysql_query($query);
}
} else { echo("."); }
}
$storage_exists[] = "$id $hrStorageIndex";
$storage_exists[] = $device[device_id]." $hrStorageIndex";
}
}
}
$sql = "SELECT * FROM storage AS S, devices AS D where S.host_id = D.device_id AND D.status = '1'";
$sql = "SELECT * FROM storage AS S, devices AS D where S.host_id = D.device_id AND D.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($store = mysql_fetch_array($query)) {
@@ -53,13 +49,14 @@ while ($store = mysql_fetch_array($query)) {
}
if(!$exists) {
echo("Deleting " . $store['hrStorageDescr'] . " from " . $store['hostname'] . "\n");
echo("-");
mysql_query("DELETE FROM storage WHERE storage_id = '" . $store['storage_id'] . "'");
}
}
echo("\n");
?>

View File

@@ -1,39 +1,29 @@
#!/usr/bin/php
<?
include("config.php");
include("includes/functions.php");
### Discovery Observer-style NetSNMP temperatures
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' ORDER BY device_id desc");
while ($device = mysql_fetch_array($device_query)) {
$id = $device['device_id'];
$hostname = $device['hostname'];
$community = $device['community'];
$snmpver = $device['snmpver'];
echo("\nPolling $hostname\n");
echo("Temperatures : ");
## Begin Observer-Style
if($device['os'] == "Linux") {
echo("Detecting Observer-Style sensors");
$oids = `snmpwalk -$snmpver -Osqn -c $community $hostname .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`;
echo("Observer-Style ");
$oids = `snmpwalk -$snmpver -Osqn -CI -c $community $hostname .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(strstr($oids, "no")) { unset ($oids); }
foreach(explode("\n",$oids) as $oid) {
$oid = trim($oid);
if($oid != "") {
$descr = trim(str_replace("\"", "", `snmpget -v2c -Osqn -c $community $hostname .1.3.6.1.4.1.2021.7891.$oid.2.1 | sed s/.1.3.6.1.4.1.2021.7891.$oid.2.1\ //`));
$fulloid = ".1.3.6.1.4.1.2021.7891.$oid.101.1";
echo("Detected : $fulloid ($descr)\n");
if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) {
echo("+");
mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`) VALUES ('$id', '$fulloid', '$descr');");
echo("Created $descr ($fulloid) on $hostname\n");
} else {
if (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr) {
echo("Updating $descr on $hostname\n");
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
}
} elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr) {
echo("U");
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
} else {
echo(".");
}
$temp_exists[] = "$id $fulloid";
}
@@ -42,26 +32,23 @@ while ($device = mysql_fetch_array($device_query)) {
## Dell Temperatures
if(strstr($device['hardware'], "Dell")) {
echo("Detecting Dell OMSA sensors\n");
$oids = `snmpwalk -$snmpver -Osqn -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8`;
echo("Dell OMSA ");
$oids = `snmpwalk -$snmpver -CI -Osqn -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8`;
$oids = trim($oids);
if(strstr($oids, "no")) { unset ($oids); }
foreach(explode("\n",$oids) as $oid) {
$oid = substr(trim($oid), 36);
echo("$oid \n");
list($oid) = explode(" ", $oid);
if($oid != "") {
$descr = trim(str_replace("\"", "", `snmpget -v2c -Onvq -c $community $hostname .1.3.6.1.4.1.674.10892.1.700.20.1.8.$oid`));
$fulloid = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.$oid";
echo("Detected : $fulloid ($descr)\n");
if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) {
mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`, `temp_tenths`) VALUES ('$id', '$fulloid', '$descr', '1');");
echo("Created $fulloid on $hostname\n");
echo("+");
} elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr) {
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
echo("U");
} else {
if (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr) {
echo("Updating $descr on $hostname\n");
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
}
echo(".");
}
$temp_exists[] = "$id $fulloid";
}
@@ -71,12 +58,12 @@ while ($device = mysql_fetch_array($device_query)) {
## Cisco Temperatures
if($device['os'] == "IOS") {
echo("Detecting Cisco IOS temperature sensors\n");
$oids = `snmpwalk -v2c -Osqn -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g`;
echo($oids);
echo("Cisco ");
$oids = shell_exec($config['snmpwalk'] . " -v2c -CI -Osqn -c $community $hostname .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g");
$oids = trim($oids);
foreach(explode("\n", $oids) as $data) {
$data = trim($data);
$data = trim($data);
if($data) {
list($oid) = explode(" ", $data);
$temp_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.3.$oid";
$descr_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.2.$oid";
@@ -90,19 +77,19 @@ while ($device = mysql_fetch_array($device_query)) {
$descr = trim($descr);
if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '.1.3.6.1.4.1.9.9.13.1.3.1.3.$oid' AND temp_host = '$id'"),0) == '0') {
$query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`) values ('$id', '$temp_oid', '$descr')";
echo("$query -> $descr : $temp\n");
mysql_query($query);
$temp_exists[] = "$id $fulloid";
}
echo("+");
} else { echo("."); }
$temp_exists[] = "$id $temp_oid";
}
}
}
}
}
## Delete removed sensors
$sql = "SELECT * FROM temperature AS T, devices AS D WHERE T.temp_host = D.device_id AND D.status = '1'";
$sql = "SELECT * FROM temperature AS T, devices AS D WHERE T.temp_host = D.device_id AND D.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($sensor = mysql_fetch_array($query)) {
@@ -114,11 +101,12 @@ while ($sensor = mysql_fetch_array($query)) {
$i++;
}
if(!$exists) {
echo("Deleting...\n");
echo("-");
mysql_query("DELETE FROM temperature WHERE temp_id = '" . $sensor['temp_id'] . "'");
}
}
unset($temp_exists); echo("\n");
?>

44
ips.php
View File

@@ -1,44 +0,0 @@
#!/usr/bin/php
<?php
include("config.php");
include("includes/functions.php");
$sql = "SELECT * FROM devices WHERE device_id LIKE '%$argv[1]' AND status = '1' AND os != 'Snom' order by device_id DESC";
$q = mysql_query($sql);
while ($device = mysql_fetch_array($q)) {
$hostname = $device['hostname'];
$hostid = $device['device_id'];
$community = $device['community'];
echo("$hostname\n");
$oids = `snmpbulkwalk -v2c -Osq -c $community $hostname ipAdEntIfIndex | sed s/ipAdEntIfIndex.//g`;
$oids = trim($oids);
foreach(explode("\n", $oids) as $data) {
$data = trim($data);
list($oid,$ifIndex) = explode(" ", $data);
$temp = `snmpget -O qv -v2c -c $community $hostname ipAdEntNetMask.$oid`;
$mask = trim($temp);
$address = $oid;
$network = trim(`$ipcalc $address/$mask | grep Network | cut -d" " -f 4`);
list($net,$cidr) = explode("/", $network);
$cidr = trim($cidr);
if($mask == "255.255.255.255") { $cidr = "32"; $network = "$address/$cidr"; }
if (mysql_result(mysql_query("SELECT count(*) FROM `interfaces` WHERE device_id = '$hostid' AND `ifIndex` = '$ifIndex'"), 0) != '0') {
$i_query = "SELECT interface_id FROM `interfaces` WHERE device_id = '$hostid' AND `ifIndex` = '$ifIndex'";
$interface_id = mysql_result(mysql_query($i_query), 0);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipaddr` WHERE `addr` = '$address' AND `cidr` = '$cidr' AND `interface_id` = '$interface_id'"), 0) == '0') {
mysql_query("INSERT INTO `ipaddr` (`addr`, `cidr`, `network`, `interface_id`) VALUES ('$address', '$cidr', '$net', '$interface_id')");
echo("Added $address/$cidr to $interface_id ( $hostname $ifIndex )\n $i_query\n");
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `networks` WHERE `cidr` = '$network'"), 0) < '1') {
mysql_query("INSERT INTO `networks` (`id`, `cidr`) VALUES ('', '$network')");
echo("Create Subnet $network\n");
}
$network_id = mysql_result(mysql_query("SELECT id from `networks` WHERE `cidr` = '$network'"), 0);
if (match_network($config['nets'], $address) && mysql_result(mysql_query("SELECT COUNT(*) FROM `adjacencies` WHERE `network_id` = '$network_id' AND `interface_id` = '$interface_id'"), 0) < '1') {
mysql_query("INSERT INTO `adjacencies` (`network_id`, `interface_id`) VALUES ('$network_id', '$interface_id')");
echo("Create Adjacency : $hostname, $interface_id, $network_id, $network, $ifIndex\n");
}
} else { }
}
}
?>

11
ips.sh
View File

@@ -1,11 +0,0 @@
./ips.php 1 &
./ips.php 2 &
./ips.php 3 &
./ips.php 4 &
./ips.php 5 &
./ips.php 6 &
./ips.php 7 &
./ips.php 8 &
./ips.php 9 &
./ips.php 0 &