many fixes to ip address polling and displaying

git-svn-id: http://www.observium.org/svn/observer/trunk@403 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2009-04-13 19:16:22 +00:00
parent 44f3a83038
commit d10c1c26d2
16 changed files with 2485 additions and 95 deletions
+1
View File
@@ -82,6 +82,7 @@ while ($entry = mysql_fetch_array($query)) {
}
if(!$exists) {
mysql_query("DELETE FROM bgpPeers WHERE bgpPeer_id = '" . $entry['bgpPeer_id'] . "'");
mysql_query("DELETE FROM bgpPeers_cbgp WHERE bgpPeer_id = '" . $entry['bgpPeer_id'] . "'");
echo("-");
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
echo("IP Addresses : ");
$oids = shell_exec($config['snmpwalk'] . " -".$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);
$mask = shell_exec($config['snmpget']." -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 `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 `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);
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("."); }
} else { echo("!"); }
}
echo("\n");
?>
+22 -24
View File
@@ -14,60 +14,58 @@ if($ipv6interfaces){
list($ipv6addr,$ifIndex) = explode(" ", $data);
$oid = "";
$sep = ''; $adsep = '';
unset($ip6_addr);
unset($ipv6_address);
$do = '0';
foreach(explode(":", $ipv6addr) as $part) {
$n = hexdec($part);
$oid = "$oid" . "$sep" . "$n";
$sep = ".";
$ip6_addr = $ip6_addr . "$adsep" . $part;
$ipv6_address = $ipv6_address . "$adsep" . $part;
$do++;
if($do == 2) { $adsep = ":"; $do = '0'; } else { $adsep = "";}
}
$ip6_prefixlen = trim(shell_exec($config['snmpget']." -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.2.1.4.34.1.5.2.16.$oid | sed 's/.*\.//'"));
$ip6_origin = trim(shell_exec($config['snmpget']." -Ovq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.2.1.4.34.1.6.2.16.$oid"));
$ipv6_prefixlen = trim(shell_exec($config['snmpget']." -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.2.1.4.34.1.5.2.16.$oid | sed 's/.*\.//'"));
$ipv6_origin = trim(shell_exec($config['snmpget']." -Ovq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.2.1.4.34.1.6.2.16.$oid"));
$ip6_network = trim(shell_exec($config['sipcalc']." $ip6_addr/$ip6_prefixlen | grep Subnet | cut -f 2 -d '-'"));
$ip6_comp_addr = trim(shell_exec($config['sipcalc']." $ip6_addr/$ip6_prefixlen | grep Compressed | cut -f 2 -d '-'"));
$ipv6_network = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep Subnet | cut -f 2 -d '-'"));
$ipv6_compressed = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep Compressed | cut -f 2 -d '-'"));
if (mysql_result(mysql_query("SELECT count(*) FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ip6_prefixlen > '0' && $ip6_prefixlen < '129' && $ip6_comp_addr != '::1') {
if (mysql_result(mysql_query("SELECT count(*) FROM `interfaces`
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 `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 `ip6networks` WHERE `ip6_network` = '$ip6_network'"), 0) < '1') {
mysql_query("INSERT INTO `ip6networks` (`ip6_network`) VALUES ('$ip6_network')");
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 `ip6networks` WHERE `ip6_network` = '$ip6_network'"), 0) < '1') {
mysql_query("INSERT INTO `ip6networks` (`ip6_network`) VALUES ('$ip6_network')");
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");
}
$ip6_network_id = @mysql_result(mysql_query("SELECT `ip6_network_id` from `ip6networks` WHERE `ip6_network` = '$ip6_network'"), 0);
$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 `ip6addr` WHERE `ip6_addr` = '$ip6_addr' AND `ip6_prefixlen` = '$ip6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0') {
mysql_query("INSERT INTO `ip6addr` (`ip6_addr`, `ip6_comp_addr`, `ip6_prefixlen`, `ip6_origin`, `ip6_network`, `ip6_network_id`, `interface_id`) VALUES ('$ip6_addr', '$ip6_comp_addr', '$ip6_prefixlen', '$ip6_origin', '$ip6_network', '$ip6_network_id', '$interface_id')");
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("+");
} else { echo("."); }
# if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ip6adjacencies` WHERE `ip6_network_id` = '$ip6_network_id' AND `interface_id` = '$interface_id'"), 0) < '1') {
# mysql_query("INSERT INTO `ip6adjacencies` (`network_id`, `interface_id`) VALUES ('$ip6_network_id', '$interface_id')");
# echo("A");
# }
$full_address = "$ip6_addr/$ip6_prefixlen";
$full_address = "$ipv6_address/$ipv6_prefixlen";
$valid_v6[$full_address] = 1;
}
}
}
} else { echo("None configured"); }
$sql = "SELECT * FROM ip6addr AS A, interfaces AS I WHERE I.device_id = '".$device['device_id']."' AND A.interface_id = I.interface_id";
$sql = "SELECT * FROM ipv6_addresses AS A, interfaces 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['ip6_addr'] . "/" . $row['ip6_prefixlen'];
$full_address = $row['ipv6_address'] . "/" . $row['ipv6_prefixlen'];
if(!$valid_v6[$full_address]) {
echo("-");
$query = @mysql_query("DELETE FROM `ip6addr` WHERE `ip6_addr_id` = '".$row['ip6_addr_id']."'");
if(!mysql_result(mysql_query("SELECT count(*) FROM ip6addr WHERE ip6_network_id = '".$row['ip6_network_id']."'"),0)) {
$query = @mysql_query("DELETE FROM `ip6networks` WHERE `ip6_network_id` = '".$row['ip6_network_id']."'");
$query = @mysql_query("DELETE FROM `ipv6_addresses` WHERE `ipv6_address_id` = '".$row['ipv6_address_id']."'");
if(!mysql_result(mysql_query("SELECT count(*) FROM ipv6_addresses WHERE ipv6_network_id = '".$row['ipv6_network_id']."'"),0)) {
$query = @mysql_query("DELETE FROM `ipv6_networks` WHERE `ipv6_network_id` = '".$row['ipv6_network_id']."'");
}
}
}
+28
View File
@@ -94,6 +94,34 @@ function temp_graph ($temp, $graph, $from, $to, $width, $height, $title, $vertic
return $imgfile;
}
function graph_device_cpmCPU ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$options = "--start $from --end $to --width $width --height $height --vertical-label '$vertical' --alt-autoscale-max ";
$options .= " -l 0 -E -b 1024 --title '$title' ";
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
$hostname = gethostbyid($device);
$imgfile = $config['install_dir'] . "/graphs/" . "$graph";
$iter = "1";
$sql = mysql_query("SELECT * FROM `cpmCPU` where `device_id` = '$device'");
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Cur\ \ \ \ Max\\\\n";
while($proc = mysql_fetch_array($sql)) {
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; unset($iter); }
$proc['descr_fixed'] = str_pad($proc['entPhysicalDescr'], 28);
$proc['descr_fixed'] = substr($proc['descr_fixed'],0,28);
$rrd = $config['rrd_dir'] . "/$hostname/cpmCPU-" . $proc['cpmCPU_oid'] . ".rrd";
$options .= " DEF:proc" . $proc['cpmCPU_oid'] . "=$rrd:usage:AVERAGE ";
$options .= " LINE1:proc" . $proc['cpmCPU_oid'] . "#" . $colour . ":'" . $proc['descr_fixed'] . "' ";
$options .= " GPRINT:proc" . $proc['cpmCPU_oid'] . ":LAST:%3.0lf";
$options .= " GPRINT:proc" . $proc['cpmCPU_oid'] . ":MAX:%3.0lf\\\l ";
$iter++;
}
$thing = shell_exec($config['rrdtool'] . " graph $imgfile $options");
return $imgfile;
}
function temp_graph_dev ($device, $graph, $from, $to, $width, $height, $title, $vertical) {
global $config, $installdir;
$options = "--start $from --end $to --width $width --height $height --vertical-label '$vertical' --alt-autoscale-max ";
+2 -4
View File
@@ -9,9 +9,7 @@ while($processor = mysql_fetch_array($proc_data)) {
echo("Checking CPU " . $processor['entPhysicalDescr'] . "... ");
$procrrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/cpmCPU-" . str_replace("/", "_", str_replace(" ", "_",$processor['entPhysicalDescr'])) . ".rrd");
$procrrd = str_replace(")", "_", $procrrd);
$procrrd = str_replace("(", "_", $procrrd);
$procrrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/cpmCPU-" . $processor['cpmCPU_oid'] . ".rrd");
if (!is_file($procrrd)) {
`rrdtool create $procrrd \
@@ -29,7 +27,7 @@ while($processor = mysql_fetch_array($proc_data)) {
echo($proc . "%\n");
$updatecmd = $config['rrdtool'] ." update $procrrd N:$proc";
echo("$updatecmd");
shell_exec($updatecmd);
mysql_query("UPDATE `cpmCPU` SET `cpmCPUTotal5minRev` = '$proc' WHERE `cpmCPU_id` = '".$processor['cpmCPU_id']."'");