diff --git a/config.php.default b/config.php.default index 4c0de6176..38b699655 100755 --- a/config.php.default +++ b/config.php.default @@ -53,16 +53,15 @@ $config['overlib_defaults'] = ",FGCOLOR,'#e5e5e5', BGCOLOR, '#e5e5e5'"; ### List of networks to allow scanning-based discovery -$nets = array ("192.168.0.0/24", "10.0.0.0/8"); +$config['nets'] = array ("192.168.0.0/24", "10.0.0.0/8"); ### Your company domain name $config['mydomain'] = "project-observer.org"; -$mydomain = $config['mydomain']; -$page_title = "Observer Demo"; -$title_image = "/images/observer-header.png"; -$stylesheet = "/css/styles.css"; +$config['page_title'] = "Observer Demo"; +$config['title_image'] = "/images/observer-header.png"; +$config['stylesheet'] = "/css/styles.css"; $mono_font = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf"; -$favicon = "/favicon.ico"; +$config['favicon'] = "/favicon.ico"; $config['email_default'] = "admin@project-observer.org"; $config['email_from'] = "observer@project-observer.org"; diff --git a/cron.sh b/cron.sh index fa5995748..7a6f3b7bf 100755 --- a/cron.sh +++ b/cron.sh @@ -1,10 +1,8 @@ #!/bin/bash -#./poll-reachability.php +./discover-bgp_peers.php >> /var/log/observer.log & ./poll-device.php --odd >> /var/log/observer.log & ./poll-device.php --even >> /var/log/observer.log & -#./ips.php & ./check-services.php #./alerts.php - ./poll-billing.php diff --git a/discover-bgp_peers.php b/discover-bgp_peers.php new file mode 100755 index 000000000..5d14f65b4 --- /dev/null +++ b/discover-bgp_peers.php @@ -0,0 +1,99 @@ +#!/usr/bin/php + +include("config.php"); +include("includes/functions.php"); + + +### 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"); + + $as_cmd = $config['snmpwalk'] . " -CI -Oqvn -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . " "; + $as_cmd .= ".1.3.6.1.2.1.15.2"; + $bgpLocalAs = trim(`$as_cmd`); + + if($bgpLocalAs) { + + echo("Host AS is $bgpLocalAs\n"); + + if($bgpLocalAs != $device['bgpLocalAs']) { mysql_query("UPDATE devices SET bgpLocalAs = '$bgpLocalAs' WHERE device_id = '".$device['device_id']."'"); echo("Updated AS\n"); } + + $peers_cmd = $config['snmpwalk'] . " -CI -Oq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . " "; + $peers_cmd .= "BGP4-MIB::bgpPeerRemoteAs"; + $peers = trim(str_replace("BGP4-MIB::bgpPeerRemoteAs.", "", `$peers_cmd`)); + foreach (explode("\n", $peers) as $peer) { + + if($peer) { + list($peer_ip, $peer_as) = split(" ", $peer); + + $astext = trim(`/usr/bin/dig +short AS$peer_as.asn.cymru.com TXT | sed s/\"//g | cut -d "|" -f 5`); + + 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"); } + } else { echo(" Exists\n"); } + + ### Poll BGP Peer + + $peer_cmd = $config['snmpget'] . " -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . " "; + $peer_cmd .= "bgpPeerState.$peer_ip bgpPeerAdminStatus.$peer_ip bgpPeerInUpdates.$peer_ip bgpPeerOutUpdates.$peer_ip bgpPeerInTotalMessages.$peer_ip "; + $peer_cmd .= "bgpPeerOutTotalMessages.$peer_ip bgpPeerFsmEstablishedTime.$peer_ip bgpPeerInUpdateElapsedTime.$peer_ip"; + $peer_data = trim(`$peer_cmd`); + + $peerrrd = $rrd_dir . "/" . $device['hostname'] . "/bgp-$peer_ip.rrd"; + + if(!is_file($peerrrd)) { + $woo = `rrdtool create $peerrrd \ + DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 \ + DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 \ + DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 \ + DS:bgpPeerInTotal:COUNTER:600:U:100000000000 \ + DS:bgpPeerEstablished:GAUGE:600:0:U \ + RRA:AVERAGE:0.5:1:600 \ + RRA:AVERAGE:0.5:6:700 \ + RRA:AVERAGE:0.5:24:775 \ + RRA:AVERAGE:0.5:288:797`; + } + + rrdtool_update($peerrrd, "N:$bgpPeerOutUpdates:$bgpPeerInUpdates:$bgpPeerOutTotalMessages:$bgpPeerInTotalMesages:$bgpPeerFsmEstablishedTime"); + + list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime) = explode("\n", $peer_data); + + $update = "UPDATE bgpPeers SET bgpPeerState = '$bgpPeerState', bgpPeerAdminStatus = '$bgpPeerAdminStatus', "; + $update .= "bgpPeerFsmEstablishedTime = '$bgpPeerFsmEstablishedTime', astext = '$astext'"; + $update .= " WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '$peer_ip'"; + + mysql_query($update); + + } # end if $peer + } # End foreach + } # End BGP check +} # End While + +## Delete removed sensors + +$sql = "SELECT * FROM temperature AS T, devices AS D WHERE T.temp_host = D.device_id AND D.status = '1'"; +$query = mysql_query($sql); + +while ($sensor = mysql_fetch_array($query)) { + unset($exists); + $i = 0; + while ($i < count($temp_exists) && !$exists) { + $thistemp = $sensor['temp_host'] . " " . $sensor['temp_oid']; + if ($temp_exists[$i] == $thistemp) { $exists = 1; } + $i++; + } + if(!$exists) { +# echo("Deleting...\n"); +# mysql_query("DELETE FROM temperature WHERE temp_id = '" . $sensor['temp_id'] . "'"); + } +} + + +?> + diff --git a/discover-cdp.php b/discover-cdp.php index 27703c721..6ade0600d 100755 --- a/discover-cdp.php +++ b/discover-cdp.php @@ -36,11 +36,11 @@ while ($device = mysql_fetch_array($device_query)) { $dst_if = strtolower($dst_if); $src_host = strtolower($src_host); $src_if = strtolower($src_if); - if ( isDomainResolves($dst_host . "." . $mydomain) ) { - $dst_host = $dst_host . "." . $mydomain; + if ( isDomainResolves($dst_host . "." . $config['mydomain']) ) { + $dst_host = $dst_host . "." . $config['mydomain']; } $ip = gethostbyname($dst_host); - if ( match_network($nets, $ip) ) { + if ( match_network($config['nets'], $ip) ) { if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$dst_host'"), 0) == '0' ) { createHost ($dst_host, $community, "v2c"); } else { diff --git a/generate-iplist.php b/generate-iplist.php index 461fdbb9d..b4aa37441 100755 --- a/generate-iplist.php +++ b/generate-iplist.php @@ -17,7 +17,7 @@ while ($data = mysql_fetch_array($query)) { $end = ip2long($broadcast); while($ip < $end) { $ipdotted = long2ip($ip); - if(mysql_result(mysql_query("SELECT count(id) FROM ipaddr WHERE addr = '$ipdotted'"),0) == '0' && match_network($nets, $ipdotted)) { + if(mysql_result(mysql_query("SELECT count(id) FROM ipaddr WHERE addr = '$ipdotted'"),0) == '0' && match_network($config['nets'], $ipdotted)) { fputs($handle, $ipdotted . "\n"); } $ip++; diff --git a/html/graph.php b/html/graph.php index 045020a8c..8bf8718ff 100644 --- a/html/graph.php +++ b/html/graph.php @@ -22,7 +22,11 @@ } elseif($_GET['if']) { $device_id = getifhost($_GET['if']); $ifIndex = getifindexbyid($_GET['if']); + } elseif($_GET['peer']) { + $device_id = getpeerhost($_GET['peer']); } + + if($device_id) { $hostname = gethostbyid($device_id); } @@ -71,6 +75,10 @@ case 'unixfs': $graph = unixfsgraph ($_GET['id'], $graphfile, $from, $to, $width, $height, $title, $vertical); break; + case 'bgpupdates': + $bgpPeerIdentifier = mysql_result(mysql_query("SELECT bgpPeerIdentifier FROM bgpPeers WHERE bgpPeer_id = '".$_GET['peer']."'"),0); + $graph = bgpupdatesgraph ($hostname . "/bgp-" . $bgpPeerIdentifier . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical); + break; case 'calls': $graph = callsgraphSNOM ($hostname . "/data.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical); break; diff --git a/html/index.php b/html/index.php index 30f9a1864..428dedcc3 100755 --- a/html/index.php +++ b/html/index.php @@ -28,11 +28,11 @@ if($_GET[debug]) {
| - + | "); + +?> diff --git a/html/percentage.php b/html/percentage.php index e14b84bbd..749a96d60 100644 --- a/html/percentage.php +++ b/html/percentage.php @@ -1,5 +1,7 @@ |