fix some polling things. maybe.

git-svn-id: http://www.observium.org/svn/observer/trunk@213 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2008-03-31 13:08:17 +00:00
parent 5499871873
commit a8a7e04f1f
7 changed files with 56 additions and 69 deletions

View File

@@ -31,7 +31,7 @@ if($argv[1] == "--device" && $argv[2]) {
$devices_polled = 0; $devices_polled = 0;
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' $where"); $device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' $where ORDER BY device_id DESC");
while ($device = mysql_fetch_array($device_query)) { while ($device = mysql_fetch_array($device_query)) {
echo($device['hostname'] ."\n"); echo($device['hostname'] ."\n");

View File

@@ -15,8 +15,6 @@
$ifPhysAddress = $interface['ifPhysAddress']; $ifPhysAddress = $interface['ifPhysAddress'];
$ifType = fixiftype($interface['ifType']); $ifType = fixiftype($interface['ifType']);
$ifHardType = $interface['ifHardType']; $ifHardType = $interface['ifHardType'];
# $errors = interface_errors($interface);
# $rates = interface_rates($interface);
if($ifAlias) {$ifAlias = $ifAlias . "</br>";} if($ifAlias) {$ifAlias = $ifAlias . "</br>";}
if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; } if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; }
@@ -32,12 +30,15 @@
<span class=list-large> <span class=list-large>
" . generateiflink($interface, "$i. $ifDescr") . " $error_img " . generateiflink($interface, "$i. $ifDescr") . " $error_img
</span><br /><span class=interface-desc>$ifAlias</span>"); </span><br /><span class=interface-desc>$ifAlias</span>");
if($ifAlias) { echo("<br />"); }
unset ($break); unset ($break);
if(!$dographs) { if(!$dographs) {
$ipdata = mysql_query("SELECT * FROM `ipaddr` WHERE `interface_id` = '" . $interface['interface_id'] . "'"); $ipdata = mysql_query("SELECT * FROM `ipaddr` WHERE `interface_id` = '" . $interface['interface_id'] . "'");
while($ip = mysql_fetch_Array($ipdata)) { while($ip = mysql_fetch_Array($ipdata)) {
echo("$break <a class=interface-desc href=\"javascript:popUp('/netcmd.php?cmd=whois&query=$ip[addr]')\">$ip[addr]/$ip[cidr]</a>"); echo("$break <a class=interface-desc href=\"javascript:popUp('/netcmd.php?cmd=whois&query=$ip[addr]')\">$ip[addr]/$ip[cidr]</a>");
$break = " "; $break = "<br />";
} }
echo("</span>"); echo("</span>");
echo("</td><td width=100>"); echo("</td><td width=100>");
@@ -79,7 +80,7 @@ echo("</td>");
if ( strpos($ifDescr, "oopback") === false && !$dographs) { if ( strpos($ifDescr, "oopback") === false && !$dographs) {
$link_query = mysql_query("select * from links AS L, interfaces AS I, devices AS D WHERE L.src_if = '$if_id' AND L.dst_if = I.interface_id AND I.device_id = D.device_id"); $link_query = mysql_query("select * from links AS L, interfaces AS I, devices AS D WHERE L.src_if = '$if_id' AND L.dst_if = I.interface_id AND I.device_id = D.device_id");
while($link = mysql_fetch_array($link_query)) { while($link = mysql_fetch_array($link_query)) {
echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generateiflink($link) . " on " . generatedevicelink($link) . "</a><br />"); echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generateiflink($link, makeshortif($link['ifDescr'])) . " on " . generatedevicelink($link) . "</a><br />");
$br = "<br />"; $br = "<br />";
} }
unset($br); unset($br);
@@ -106,7 +107,7 @@ echo("</td>");
$wq = mysql_query("select count(*) FROM links WHERE dst_if = '$this_ifid' AND src_if = $if_id;"); $wq = mysql_query("select count(*) FROM links WHERE dst_if = '$this_ifid' AND src_if = $if_id;");
if (@mysql_result($wq, 0) == '0' && $this_hostname != $hostname) { if (@mysql_result($wq, 0) == '0' && $this_hostname != $hostname) {
$graph_url = "graph.php?if=$this_ifid&from=$twoday&to=$now&width=400&height=120&type=bits'"; $graph_url = "graph.php?if=$this_ifid&from=$twoday&to=$now&width=400&height=120&type=bits'";
echo("$br &nbsp;<img src='images/16/bullet_go.png' alt='Same Subnet' align=absmiddle />" . generateiflink($new) . " on " . generatedevicelink($new)); echo("$br &nbsp;<img src='images/16/bullet_go.png' alt='Same Subnet' align=absmiddle />" . generateiflink($new, makeshortif($new['ifDescr'])) . " on " . generatedevicelink($new));
$br = "<br />"; $br = "<br />";
} }
} }

22
includes/common.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
$config['version'] = "0.3.3";
### Connect to database
if (!@mysql_connect($config['db_host'], $config['db_user'], $config['db_pass'])) {
echo "<h2>MySQL Error</h2>";
die;
}
mysql_select_db($config['db_name']);
# Set some times needed by loads of scripts (it's dynamic, so we do it here!)
$now = time();
$day = time() - (24 * 60 * 60);
$twoday = time() - (2 * 24 * 60 * 60);
$week = time() - (7 * 24 * 60 * 60);
$month = time() - (31 * 24 * 60 * 60);
$year = time() - (365 * 24 * 60 * 60);
?>

View File

@@ -16,10 +16,24 @@ include("cisco-entities.php");
include("syslog.php"); include("syslog.php");
function write_dev_attrib($device_id, $attrib_type, $attrib_value) {
$count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . $device_id . "' AND `attrib_type` = '$attrib_type'";
if(mysql_result(mysql_query($count_sql),0)) {
$update_sql = "UPDATE devices_attribs SET attrib_value = '$attrib_value' WHERE `device_id` = '$device_id' AND `attrib_type` = '$attrib_type'";
mysql_query($update_sql);
} else {
$insert_sql = "INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('$device_id', '$attrib_type', '$attrib_value')";
mysql_query($insert_sql);
}
return mysql_affected_rows();
}
function shorthost($hostname, $len=16) { function shorthost($hostname, $len=16) {
list ($first, $second, $third, $fourth, $fifth) = explode(".", $hostname); list ($first, $second, $third, $fourth, $fifth) = explode(".", $hostname);
$shorthost = $first; $shorthost = $first;
if(strlen($first.".".$second) < $len && $second) { if(strlen($first.".".$second) < $len && $second) {
$shorthost = $first.".".$second; $shorthost = $first.".".$second;
@@ -47,8 +61,8 @@ function getHostOS($hostname, $community, $snmpver) {
global $config; global $config;
$sysDescr_cmd = "snmpget -O qv -" . $snmpver . " -c " . $community . " " . $hostname . " sysDescr.0"; $sysDescr_cmd = $config['snmpget']." -O qv -" . $snmpver . " -c " . $community . " " . $hostname . " sysDescr.0";
$sysDescr = str_replace("\"", "", trim(`$sysDescr_cmd`)); $sysDescr = str_replace("\"", "", trim(shell_exec($sysDescr_cmd)));
$dir_handle = @opendir("includes/osdiscovery") or die("Unable to open $path"); $dir_handle = @opendir("includes/osdiscovery") or die("Unable to open $path");
while ($file = readdir($dir_handle)) { while ($file = readdir($dir_handle)) {
if( preg_match("/^discover-([a-z0-9]*).php/", $file) ) { if( preg_match("/^discover-([a-z0-9]*).php/", $file) ) {
@@ -56,14 +70,12 @@ function getHostOS($hostname, $community, $snmpver) {
} }
} }
closedir($dir_handle); closedir($dir_handle);
if($os) { return $os; } else { return FALSE; } if($os) { return $os; } else { return FALSE; }
} }
function strgen ($length = 8) function strgen ($length = 16)
{ {
$entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e', $entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e',
'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n', 'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n',
@@ -72,8 +84,7 @@ function strgen ($length = 8)
$string = ""; $string = "";
for ($i=0; $i<$length; $i++) for ($i=0; $i<$length; $i++) {
{
$key = mt_rand(0,61); $key = mt_rand(0,61);
$string .= $entropy[$key]; $string .= $entropy[$key];
} }

View File

@@ -262,7 +262,7 @@ function cpugraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $verti
$options .= " GPRINT:nice_perc:AVERAGE:\ \ \ %5.2lf%%"; $options .= " GPRINT:nice_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:nice_perc:MAX:\ \ \ %5.2lf%%\\\\n"; $options .= " GPRINT:nice_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$options .= " AREA:system_perc#ea8f00:system:STACK"; $options .= " AREA:system_perc#ea8f00:system:STACK";
$options .= " GPRINT:system_perc:LAST:\ \ %5.2lf%%"; $options .= " GPRINT:system_perc:LAST:\ \ \ %5.2lf%%";
$options .= " GPRINT:system_perc:AVERAGE:\ \ \ %5.2lf%%"; $options .= " GPRINT:system_perc:AVERAGE:\ \ \ %5.2lf%%";
$options .= " GPRINT:system_perc:MAX:\ \ \ %5.2lf%%\\\\n"; $options .= " GPRINT:system_perc:MAX:\ \ \ %5.2lf%%\\\\n";
$options .= " AREA:idle_perc#f5f5e5:idle:STACK"; $options .= " AREA:idle_perc#f5f5e5:idle:STACK";

View File

@@ -1,49 +0,0 @@
NETSCREEN-CHASSIS-MIB NS-CHASSIS.mib
NETSCREEN-QOS-MIB NS-QOS.mib
NETSCREEN-INTERFACE-MIB NS-INTERFACE.mib
NETSCREEN-VR-BGP4-MIB NS-VR-BGP4.mib
NETSCREEN-RIPv2-MIB NS-RIP.mib
NETSCREEN-VR-MIB NS-VR.mib
NETSCREEN-SET-GEN-MIB NS-SET-GEN.mib
NETSCREEN-SET-DHCP-MIB NS-SET-DHCP.mib
NETSCREEN-NAT-MIB NS-NAT.mib
NETSCREEN-VPN-MON-MIB NS-VPN-MON.mib
NETSCREEN-SET-SYSTIME-MIB NS-SET-SYSTIME.mib
NETSCREEN-VPN-GATEWAY-MIB NS-VPN-GW.mib
NETSCREEN-TRAP-MIB NS-TRAPS.mib
NETSCREEN-VPN-USER-MIB NS-VPN-USR.mib
NETSCREEN-SET-SNMP-MIB NS-SET-SNMP.mib
NETSCREEN-VPN-PHASETWO-MIB NS-VPN-PH2.mib
NETSCREEN-VSYS-MIB NS-VSYS.mib
NETSCREEN-VPN-MON-SA-COUNT-MIB NS-VPN-MON-SA.mib
NETSCREEN-VPN-L2TP-MIB NS-VPN-L2TP.mib
NETSCREEN-SET-GLB-MIB NS-SET-GLB.mib
NETSCREEN-SET-URL-FILTER-MIB NS-SET-URL-FILTER.mib
NETSCREEN-VR-OSPF-MIB NS-VR-OSPF.mib
NETSCREEN-SET-DNS-MIB NS-SET-DNS.mib
NETSCREEN-IDS-MIB NS-IDS.mib
NETSCREEN-SET-ADMIN-USR-MIB NS-SET-ADMIN-USR.mib
NETSCREEN-SET-LOG-MIB NS-SET-LOG.mib
NETSCREEN-POLICY-MIB NS-POLICY.mib
NETSCREEN-SMI NS-SMI.mib
NETSCREEN-IPPOOL-MIB NS-VPN-IPPOOL.mib
NETSCREEN-NSRP-MIB NS-NSRP.mib
NETSCREEN-VR-RIPv2-MIB NS-VR-RIP.mib
NETSCREEN-IP-ARP-MIB NS-IP-ARP.mib
NETSCREEN-VPN-PHASEONE-MIB NS-VPN-PH1.mib
NETSCREEN-SCHEDULE-MIB NS-SCHEDULE.mib
NETSCREEN-PRODUCTS-MIB NS-PRODUCTS.mib
NETSCREEN-SET-EMAIL-MIB NS-SET-EMAIL.mib
NETSCREEN-OSPF-TRAP-MIB NS-OSPF-TRAP.mib
NETSCREEN-SERVICE-MIB NS-SERVICE.mib
NETSCREEN-ADDR-MIB NS-ADDR.mib
NETSCREEN-OSPF-MIB NS-OSPF.mib
NETSCREEN-ZONE-MIB NS-ZONE.mib
NETSCREEN-RESOURCE-MIB NS-RES.mib
NETSCREEN-VPN-IAS-MIB NS-VPN-IAS.mib
NETSCREEN-VPN-MANUAL-MIB NS-VPN-MANUAL.mib
NETSCREEN-VPN-IKE-MIB NS-VPN-IKE.mib
NETSCREEN-BGP4-MIB NS-BGP4.mib
NETSCREEN-SET-WEB-MIB NS-SET-WEB.mib
NETSCREEN-SET-AUTH-MIB NS-SET-AUTH.mib
NETSCREEN-CERTIFICATE-MIB NS-VPN-CERT.mib

View File

@@ -29,7 +29,7 @@ while ($device = mysql_fetch_array($device_query)) {
echo("Polling " . $device['hostname'] . " ( device_id ".$device['device_id']." )\n\n"); echo("Polling " . $device['hostname'] . " ( device_id ".$device['device_id']." )\n\n");
unset($update); unset($update_query); unset($seperator); unset($version); unset($uptime); unset($features); unset($update); unset($update_query); unset($seperator); unset($version); unset($uptime); unset($features);
unset($location); unset($hardware); unset($sysDescr); unset($sysContact); unset($sysLocation); unset($hardware); unset($sysDescr); unset($sysContact);
$pingable = isPingable($device['hostname']); $pingable = isPingable($device['hostname']);
@@ -46,6 +46,8 @@ while ($device = mysql_fetch_array($device_query)) {
if($snmpable) { echo("SNMP : yes :)\n"); } else { echo("SNMP : no :(\n"); } if($snmpable) { echo("SNMP : yes :)\n"); } else { echo("SNMP : no :(\n"); }
} }
unset($snmpdata);
if ($snmpable) { if ($snmpable) {
$status = '1'; $status = '1';
@@ -177,7 +179,7 @@ while ($device = mysql_fetch_array($device_query)) {
default: default:
pollDevice(); pollDevice();
} }
$location = str_replace("\"","", $sysLocation); $sysLocation = str_replace("\"","", $sysLocation);
echo("Polling temperatures\n"); echo("Polling temperatures\n");
include("includes/polling/temperatures.inc.php"); include("includes/polling/temperatures.inc.php");
@@ -208,10 +210,10 @@ while ($device = mysql_fetch_array($device_query)) {
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysDescr -> $sysDescr')"); mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysDescr -> $sysDescr')");
} }
if ( $location && $device['location'] != $location ) { if ( $sysLocation && $device['location'] != $sysLocation ) {
$update .= $seperator . "`location` = '$location'"; $update .= $seperator . "`location` = '$sysLocation'";
$seperator = ", "; $seperator = ", ";
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $location')"); mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $sysLocation')");
} }
if ( $version && $device['version'] != $version ) { if ( $version && $device['version'] != $version ) {