From 190f5ee2ce86116cecde49bd85728dcbc1ec1412 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Sat, 15 Mar 2008 17:58:15 +0000 Subject: [PATCH] Add BGP detection and polling. Fix a lot of other things. git-svn-id: http://www.observium.org/svn/observer/trunk@161 61d68cd4-352d-0410-923a-c4978735b2b8 --- config.php.default | 11 ++-- cron.sh | 4 +- discover-bgp_peers.php | 99 +++++++++++++++++++++++++++++++++++ discover-cdp.php | 6 +-- generate-iplist.php | 2 +- html/graph.php | 8 +++ html/index.php | 10 ++-- html/pages/device.php | 9 ++++ html/pages/device/dev-bgp.inc | 56 ++++++++++++++++++++ html/percentage.php | 2 + includes/functions.php | 6 +++ includes/graphing.php | 85 +++++++++++++++++++----------- interface-ips.php | 2 +- ips.php | 2 +- map.php | 14 ++--- 15 files changed, 259 insertions(+), 57 deletions(-) create mode 100755 discover-bgp_peers.php create mode 100644 html/pages/device/dev-bgp.inc 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 + + 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]) { <?php echo("$page_title"); ?> - " /> + - - + + @@ -55,7 +55,7 @@ function popUp(URL) { $_SESSION[username] (Logout)"); + echo("Logged in as ".$_SESSION['username']." (Logout)"); } else { echo("Not logged in!"); } @@ -68,7 +68,7 @@ function popUp(URL) {
- +
diff --git a/html/pages/device.php b/html/pages/device.php index 926a39bdc..86c4b4d74 100644 --- a/html/pages/device.php +++ b/html/pages/device.php @@ -36,6 +36,15 @@ if(@mysql_result(mysql_query("select count(vlan_id) from vlans WHERE device_id = "); } +if($device['bgpLocalAs']) { + echo(" +
  • + + BGP + +
  • "); +} + if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') { echo("
  • diff --git a/html/pages/device/dev-bgp.inc b/html/pages/device/dev-bgp.inc new file mode 100644 index 000000000..d7f8e0154 --- /dev/null +++ b/html/pages/device/dev-bgp.inc @@ -0,0 +1,56 @@ +"); + $i = "1"; + $peer_query = mysql_query("select * from bgpPeers WHERE device_id = '".$device['device_id']."' ORDER BY bgpPeerRemoteAs, bgpPeerIdentifier"); + while($peer = mysql_fetch_array($peer_query)) { + + if(!is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } + if($peer['bgpPeerAdminStatus'] == "start") { $img = "images/16/accept.png"; } else { $img = "images/16/delete.png"; } + if($peer['bgpPeerState'] == "established") { $col = "green"; } else { $col = "red"; $bg_colour = "#fcc"; } + + + $peerhost = mysql_fetch_array(mysql_query("SELECT * FROM ipaddr AS A, interfaces AS I, devices AS D WHERE A.addr = '".$peer['bgpPeerIdentifier']."' AND I.interface_id = A.interface_id AND D.device_id = I.device_id")); + + if($peerhost) { $peername = generatedevicelink($peerhost); } else { unset($peername); } + + echo(""); + +# if($graphs) { + + $graph_type = "bgpupdates"; + + $daily_traffic = "graph.php?peer=" . $peer['bgpPeer_id'] . "&type=$graph_type&from=$day&to=$now&width=210&height=100"; + $daily_url = "graph.php?peer=" . $peer['bgpPeer_id'] . "&type=$graph_type&from=$day&to=$now&width=500&height=150"; + + $weekly_traffic = "graph.php?peer=" . $peer['bgpPeer_id'] . "&type=$graph_type&from=$week&to=$now&width=210&height=100"; + $weekly_url = "graph.php?peer=" . $peer['bgpPeer_id'] . "&type=$graph_type&from=$week&to=$now&width=500&height=150"; + + $monthly_traffic = "graph.php?peer=" . $peer['bgpPeer_id'] . "&type=$graph_type&from=$month&to=$now&width=210&height=100"; + $monthly_url = "graph.php?peer=" . $peer['bgpPeer_id'] . "&type=$graph_type&from=$month&to=$now&width=500&height=150"; + + $yearly_traffic = "graph.php?peer=" . $peer['bgpPeer_id'] . "&type=$graph_type&from=$year&to=$now&width=210&height=100"; + $yearly_url = "graph.php?peer=" . $peer['bgpPeer_id'] . "&type=$graph_type&from=$year&to=$now&width=500&height=150"; + + echo(""); + + + # } + + $i++; + } + echo("
    $i" . $peer['bgpPeerIdentifier'] . "
    ".$peername."
    AS" . $peer['bgpPeerRemoteAs'] . "
    " . $peer['astext'] . "
    " . $peer['bgpPeerState'] . "" .formatUptime($peer['bgpPeerFsmEstablishedTime']). "
    "); + + echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "); + echo("', LEFT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"> + "); + echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT".$config['overlib_defaults'].", WIDTH, 350);\" onmouseout=\"return nd();\"> + "); + + + echo("
  • "); + +?> 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 @@