add some ASA support, clean up polling, clean up MAC table generation, add ARP table

git-svn-id: http://www.observium.org/svn/observer/trunk@467 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong 2009-09-18 09:11:52 +00:00
parent bfc9f845ce
commit 0ceb70014f
14 changed files with 125 additions and 118 deletions

BIN
html/images/os/asa.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 B

View File

@ -5,6 +5,8 @@
$interface['device_id'] = $device['device_id'];
$interface['hostname'] = $device['hostname'];
$interface = ifNameDescr($interface);
$if_id = $interface['interface_id'];
if(!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
@ -17,7 +19,7 @@
<td valign=top width=300>");
echo(" <span class=list-large>
" . generateiflink($interface, "$i. ".fixifName($interface['ifDescr'])) . " $error_img
" . generateiflink($interface, $interface['ifIndex'] . ". ".fixifName($interface['label'])) . " $error_img
</span><br /><span class=interface-desc>".$interface['ifAlias']."</span>");
@ -85,10 +87,10 @@
echo("</td>");
echo("<td width=375 valign=top class=interface-desc>");
if ( strpos($interface['ifDescr'], "oopback") === false && !$graph_type) {
if ( strpos($interface['label'], "oopback") === false && !$graph_type) {
$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)) {
# echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generateiflink($link, makeshortif($link['ifDescr'])) . " on " . generatedevicelink($link, shorthost($link['hostname'])) . "</a><br />");
# echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generateiflink($link, makeshortif($link['label'])) . " on " . generatedevicelink($link, shorthost($link['hostname'])) . "</a><br />");
# $br = "<br />";
$int_links[$link['interface_id']] = $link['interface_id'];
$int_links_phys[$link['interface_id']] = 1;
@ -112,7 +114,7 @@ echo("</td>");
$this_ifid = $new['interface_id'];
$this_hostid = $new['device_id'];
$this_hostname = $new['hostname'];
$this_ifname = fixifName($new['ifDescr']);
$this_ifname = fixifName($new['label']);
$int_links[$this_ifid] = $this_ifid;
$int_links_v4[$this_ifid] = 1;
}
@ -132,7 +134,7 @@ echo("</td>");
$this_ifid = $new['interface_id'];
$this_hostid = $new['device_id'];
$this_hostname = $new['hostname'];
$this_ifname = fixifName($new['ifDescr']);
$this_ifname = fixifName($new['label']);
$int_links[$this_ifid] = $this_ifid;
$int_links_v6[$this_ifid] = 1;
}
@ -148,7 +150,7 @@ echo("</td>");
if($int_links_phys[$int_link]) { echo("<img align=absmiddle src='images/16/connect.png'> "); } else {
echo("<img align=absmiddle src='images/16/bullet_go.png'> "); }
echo("<b>" . generateiflink($link_if, makeshortif($link_if['ifDescr'])) . " on " . generatedevicelink($link_if, shorthost($link_if['hostname'])) );
echo("<b>" . generateiflink($link_if, makeshortif($link_if['label'])) . " on " . generatedevicelink($link_if, shorthost($link_if['hostname'])) );
if($int_links_v6[$int_link]) { echo(" <b style='color: #a10000;'>v6</b>"); }
if($int_links_v4[$int_link]) { echo(" <b style='color: #00a100'>v4</b>"); }
@ -166,7 +168,8 @@ echo("</td>");
$pw_peer_int = mysql_fetch_array(mysql_query("SELECT * from `interfaces` AS I, pseudowires AS P WHERE I.device_id = '".$pseudowire['peer_device_id']."' AND
P.cpwVcID = '".$pseudowire['cpwVcID']."' AND
P.interface_id = I.interface_id"));
echo("<img src='images/16/arrow_switch.png' align=absmiddle><b> " . generateiflink($pw_peer_int, makeshortif($pw_peer_int['ifDescr'])) ." on ". generatedevicelink($pw_peer_dev, shorthost($pw_peer_dev['hostname'])) . "</b>");
$pw_peer_int = ifNameDescr($pw_peer_int);
echo("<img src='images/16/arrow_switch.png' align=absmiddle><b> " . generateiflink($pw_peer_int, makeshortif($pw_peer_int['label'])) ." on ". generatedevicelink($pw_peer_dev, shorthost($pw_peer_dev['hostname'])) . "</b>");
}

View File

@ -16,9 +16,10 @@ $select[$section] = "selected";
$device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` = '" . $_GET['id'] . "'");
while($device = mysql_fetch_array($device_query)) {
echo("<table cellpadding=7 cellspacing=0 class=devicetable width=100%>");
echo("<table cellpadding=15
cellspacing=0 class=devicetable width=100%>");
include("includes/device-header.inc");
echo("</table><br />");
echo("</table>");
echo("<div class=mainpane>");

View File

@ -202,8 +202,9 @@ echo("
$sql = "SELECT * FROM interfaces WHERE `device_id` = '" . $device['device_id'] . "'";
$query = mysql_query($sql);
while($data = mysql_fetch_array($query)) {
$data = ifNameDescr($data);
$data['hostname'] = $device['hostname'];
echo("$ifsep" . generateiflink($data, makeshortif(strtolower($data['ifDescr']))));
echo("$ifsep" . generateiflink($data, makeshortif(strtolower($data['label']))));
$ifsep = ", ";
}
unset($ifsep);

View File

@ -60,16 +60,46 @@ if($_GET['optc'] == thumbs) {
echo("</div>");
} else {
if($_GET['opta'] == "details" ) { $port_details = 1; }
$hostname = gethostbyid($device['device_id']);
echo("<div style='margin: 5px;'><table border=0 cellspacing=0 cellpadding=5 width=100%>");
$i = "1";
$interface_query = mysql_query("select * from interfaces WHERE device_id = '$_GET[id]' AND deleted = '0' ORDER BY `ifIndex` ASC");
while($interface = mysql_fetch_array($interface_query)) {
include("includes/print-interface.inc");
$i++;
if($_GET['opta'] == "arp" ) {
$interface_query = mysql_query("select * from interfaces WHERE device_id = '$_GET[id]' AND deleted = '0' ORDER BY `ifIndex` ASC");
echo("<table border=0 cellspacing=0 cellpadding=3 width=800><tr><th>Address</th><th>Hardware Addr</th><th>Interface</th><th>Remote Device</th><th>Remote Port</th></tr>");
$i = 1;
while($interface = mysql_fetch_array($interface_query)) {
$sql = "SELECT * FROM `ipv4_mac` WHERE `interface_id` = '".$interface['interface_id']."'";
$arp_query = mysql_query($sql);
while($arp = mysql_fetch_array($arp_query)) {
$i++;
if(!is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
$r_sql = "SELECT * FROM `ipv4_addresses` AS A, `interfaces` AS I, `devices` AS D WHERE I.interface_id = A.interface_id AND
I.device_id = D.device_id AND A.ipv4_address = '".$arp['ipv4_address']."' ORDER BY A.ipv4_address";
$remote = mysql_fetch_array(mysql_query($r_sql));
$mac = formatMac($arp['mac_address']);
echo("<tr style=\"background-color: $row_colour; padding: 5px;\" valign=top>
<td>" . $arp['ipv4_address'] . "</td><td>" . $mac . "</td><td>".generateiflink($interface)."</td>");
if ($remote['interface_id'] == $interface['interface_id']) {
echo("<td><i>local</i></td><td><i>local</i></td>");
} elseif($remote['device_id']) {
echo("<td>" . generatedevicelink($remote) . "</td><td>" . generateiflink($remote) . "</td>");
} else {
echo("<td></td><td></td>");
}
echo("</tr>");
}
echo("</div>");
}
echo("</table>");
} else {
echo("<div style='margin: 5px;'><table border=0 cellspacing=0 cellpadding=5 width=100%>");
$i = "1";
$interface_query = mysql_query("select * from interfaces WHERE device_id = '$_GET[id]' AND deleted = '0' ORDER BY `ifIndex` ASC");
while($interface = mysql_fetch_array($interface_query)) {
include("includes/print-interface.inc");
$i++;
}
echo("</table></div>");
echo("<div style='min-height: 150px;'></div>");
}
echo("</table></div>");
echo("<div style='min-height: 150px;'></div>");
}
?>

View File

@ -30,6 +30,8 @@
$mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f";
$clean_mac = $m_a . $m_b . $m_c . $m_d . $m_e . $m_f;
$mac_table[$if][$mac]['cleanmac'] = $clean_mac;
$interface_id = $interface['interface_id'];
$mac_table[$interface_id][$clean_mac] = 1;
if(mysql_result(mysql_query("SELECT COUNT(*) from ipv4_mac WHERE interface_id = '".$interface['interface_id']."' AND ipv4_address = '$ip'"),0)) {
$sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND ipv4_address = '$ip'";
mysql_query($sql);
@ -37,8 +39,24 @@
#echo("Add MAC $mac\n");
mysql_query("INSERT INTO `ipv4_mac` (interface_id, mac_address, ipv4_address) VALUES ('".$interface['interface_id']."','$clean_mac','$ip')");
}
$interface_id = $interface['interface_id'];
}
print_r($mac_table);
$sql = "SELECT * from ipv4_mac AS M, interfaces as I WHERE M.interface_id = I.interface_id and I.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while($entry = mysql_fetch_array($query)) {
$entry_mac = $entry['mac_address'];
$entry_if = $entry['interface_id'];
if(!$mac_table[$entry_if][$entry_mac]) {
mysql_query("DELETE FROM ipv4_mac WHERE interface_id = '".$entry_if."' AND mac_address = '".$entry_mac."'");
echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
}
}
unset($mac);
$datas = shell_exec($config['snmpbulkwalk'] . " -m CISCO-IP-STAT-MIB -Oqn -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." cipMacSwitchedBytes");
echo("$datas\n");
echo("done\n");

View File

@ -280,7 +280,8 @@ function geteventicon ($message)
function generateiflink($interface, $text=0,$type=bits)
{
global $twoday; global $now; global $config; global $day; global $month;
if(!$text) { $text = fixIfName($interface['ifDescr']); }
$interface = ifNameDescr($interface);
if(!$text) { $text = fixIfName($interface['label']); }
if(!$type) { $type = 'bits'; }
$class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
$graph_url = $config['base_url'] . "/graph.php?if=" . $interface['interface_id'] . "&from=$day&to=$now&width=400&height=100&type=" . $type;
@ -288,7 +289,7 @@ function generateiflink($interface, $text=0,$type=bits)
$device_id = getifhost($interface['interface_id']);
$link = "<a class=$class href='".$config['base_url']."/device/$device_id/interface/" . $interface['interface_id'] . "/' ";
$link .= "onmouseover=\" return overlib('";
$link .= "<img src=\'$graph_url\'><br /><img src=\'$graph_url_month\'>', CAPTION, '<span class=list-large>" . $interface['hostname'] . " - " . fixifName($interface['ifDescr']) . "</span>";
$link .= "<img src=\'$graph_url\'><br /><img src=\'$graph_url_month\'>', CAPTION, '<span class=list-large>" . $interface['hostname'] . " - " . fixifName($interface['label']) . "</span>";
if($interface['ifAlias']) { $link .= "<br />" . $interface['ifAlias']; }
$link .= "' ";
$link .= $config['overlib_defaults'].");\" onmouseout=\"return nd();\" >$text</a>";

View File

@ -0,0 +1,7 @@
<?php
if(!$os) {
if(preg_match("/^Cisco\ Adaptive\ Security\ Appliance/", $sysDescr)) { $os = "ASA"; }
}
?>

View File

@ -19,14 +19,15 @@ while ($interface = mysql_fetch_array($interface_query)) {
echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n");
$snmp_cmd = $config['snmpget'] . " -m IF-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
$snmp_cmd .= " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ifAlias." . $interface['ifIndex'];
$snmp_cmd .= " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ifAlias." . $interface['ifIndex'] . " ifName." . $interface['ifIndex'];
$snmp_cmd .= " ifDescr." . $interface['ifIndex'];
$snmp_output = trim(shell_exec($snmp_cmd));
$snmp_output = str_replace("No Such Object available on this agent at this OID", "", $snmp_output);
$snmp_output = str_replace("No Such Instance currently exists at this OID", "", $snmp_output);
$snmp_output = str_replace("\"", "", $snmp_output);
list($ifAdminStatus, $ifOperStatus, $ifAlias) = explode("\n", $snmp_output);
list($ifAdminStatus, $ifOperStatus, $ifAlias, $ifName, $ifDescr) = explode("\n", $snmp_output);
$ifAdminStatus = translate_ifAdminStatus ($ifAdminStatus);
$ifOperStatus = translate_ifOperStatus ($ifOperStatus);
@ -37,7 +38,7 @@ while ($interface = mysql_fetch_array($interface_query)) {
$ifDescr = trim(str_replace("\"", "", $ifDescr));
$ifDescr = trim($ifDescr);
if(!$ifDescr) { $ifDescr = $ifName; }
# if(!$ifDescr) { $ifDescr = $ifName; }
$rrdfile = $host_rrd . "/" . $interface['ifIndex'] . ".rrd";
@ -63,10 +64,23 @@ while ($interface = mysql_fetch_array($interface_query)) {
if( file_exists("includes/polling/interface-" . $device['os'] . ".php") ) { include("includes/polling/interface-" . $device['os'] . ".php"); }
if ( $interface['ifDescr'] != $ifDescr ) {
$update .= $seperator . "`ifDescr` = '$ifDescr'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'ifDescr -> $ifDescr')");
}
if ( $interface['ifName'] != $ifName ) {
$update .= $seperator . "`ifName` = '$ifName'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'ifName -> $ifName')");
}
if ( $interface['ifAlias'] != $ifAlias ) {
$update .= $seperator . "`ifAlias` = '$ifAlias'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc -> $ifAlias')");
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'ifAlias -> $ifAlias')");
}
if ( $interface['ifOperStatus'] != $ifOperStatus && $ifOperStatus != "" ) {
$update .= $seperator . "`ifOperStatus` = '$ifOperStatus'";

View File

@ -1,6 +1,27 @@
<?php
function formatMac($mac) {
$mac = preg_replace("/(..)(..)(..)(..)(..)(..)/", "\\1:\\2:\\3:\\4:\\5:\\6", $mac);
return $mac;
}
function ifNameDescr ($interface, $device) {
echo($device['os']);
if(!$config['ifname'][$device['os']]) {
$interface['label'] = $interface['ifDescr'];
} else {
$interface['label'] = $interface['ifName'];
}
# unset ($interface['ifDescr']);
# unset ($interface['ifName']);
return $interface;
}
$rewrite_entSensorType = array (
'celsius' => 'C',
'unknown' => '',

View File

@ -3,6 +3,9 @@
## ifDescr whitelist (used instead of ifName)
$config['ifdescr']['IOS'] = true;
$config['ifdescr']['IOS XE'] = true;
$config['ifname']['ASA'] = true;
## AFI / SAFI pairs for BGP (and other stuff, perhaps)
$config['afi']['ipv4']['unicast'] = "IPv4";

View File

@ -1,78 +0,0 @@
#!/usr/bin/php
<?php
//
// Interface Status Poller
//
include("config.php");
include("includes/functions.php");
$interface_query = mysql_query("SELECT *, I.interface_id AS sqlid FROM `interfaces` AS I, `devices` AS D where I.device_id = D.device_id AND D.status = '1' AND I.device_id LIKE '%" . $argv[1] . "' ORDER BY I.device_id DESC");
while ($interface = mysql_fetch_array($interface_query)) {
$hostname = $interface['hostname'];
$host = $interface['host'];
$old_if = $interface['if'];
$ifIndex = $interface['ifIndex'];
$old_alias = $interface['name'];
$id = $interface['sqlid'];
$old_up = $interface['up'];
$old_speed = $interface['speed'];
$os = $interface['os'];
$old_duplex = $interface['duplex'];
$old_mac = $interface['mac'];
$old_up_admin = $interface['up_admin'];
$snmpver = $interface['snmpver'];
$snmp_cmd = "snmpget -m IF-MIB -O qv -".$interface['snmpver']." -c ".$interface['community']." ".$interface['hostname'].":".$interface['port']." ifDescr.$ifIndex ifAdminStatus.$ifIndex ifOperStatus.$ifIndex ";
$snmp_cmd .= "ifAlias.$ifIndex ifName.$ifIndex";
$snmp_output = trim(shell_exec($snmp_cmd));
list($ifDescr, $ifAdminStatus, $ifOperStatus, $ifAlias, $ifName) = explode("\n", $snmp_output);
## DUPLEX IS AT .1.3.6.1.4.1.9.5.1.4.1.1.10 <-- DUPLEX, K? BUT ONLY CATALYFAILS!
$ifDescr = trim(str_replace("\"", "", $ifDescr));
$name = $ifDescr;
if ($ifDuplex == 3) { $ifDuplex = "half"; } elseif ($ifDuplex == 2) { $ifDuplex = "full"; } else { $ifDuplex = "unknown"; }
$ifAlias = str_replace("No Such Object available on this agent at this OID", "", $ifAlias);
$name = strtolower($name);
$ifAlias = str_replace("No Such Object available on this agent at this OID", "", $ifAlias);
$name = str_replace("no such object available on this agent at this oid", "", $name);
# if ($ifAlias == " ") { $ifAlias = str_replace(" ", "", $ifAlias); }
$ifAlias = trim(str_replace("\"", "", $ifAlias));
$ifAlias = trim($ifAlias);
if ($old_alias != $ifAlias || $old_up != $ifOperStatus || $old_up_admin != $ifAdminStatus || $old_duplex != $ifDuplex || $old_if == $name )
unset($update);
unset($update_query);
unset($seperator);
if ( $old_if != $name ) {
$update = "`if` = '$name'";
$seperator = ", ";
}
if ( $old_alias != $ifAlias ) {
$update .= $seperator . "`name` = \"$ifAlias\"";
}
if ( $old_up != $ifOperStatus ) {
$update .= $seperator . "`up` = '$ifOperStatus'";
}
if ( $old_up_admin != $ifAdminStatus ) {
$update .= $seperator . "`up_admin` = '$ifAdminStatus'";
}
if ( $old_duplex != $ifDuplex ) {
$update .= $seperator . "`duplex` = '$ifDuplex'";
}
if ($update) {
$update_query = "UPDATE `interfaces` SET ";
$update_query .= $update;
$update_query .= " WHERE `id` = '$id'";
echo("Updating : $hostname $name\n$update_query\n\n");
$update_result = mysql_query($update_query);
} else {
echo("Not Updating : $hostname $name ( $old_if )\n\n");
}
}
?>

View File

@ -1,14 +0,0 @@
#!/bin/bash
cd /opt/observer/
./poll-ifstatus.php 1 &
./poll-ifstatus.php 2 &
./poll-ifstatus.php 3 &
./poll-ifstatus.php 4 &
./poll-ifstatus.php 5 &
./poll-ifstatus.php 6 &
./poll-ifstatus.php 7 &
./poll-ifstatus.php 8 &
./poll-ifstatus.php 9 &
./poll-ifstatus.php 0 &

View File

@ -45,7 +45,7 @@ $devices_polled = 0;
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' $where ORDER BY device_id ASC");
while ($device = mysql_fetch_array($device_query)) {
echo($device['hostname'] . "(".$device['sysName'].")\n");
echo($device['hostname'] . "(".$device['sysName']."|".$device['device_id'].")\n");
include("includes/discovery/".$type.".php");