syslog improvements :)

git-svn-id: http://www.observium.org/svn/observer/trunk@198 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong 2008-03-23 15:40:58 +00:00
parent 3ed9d4b2a4
commit 7394b0c1db
8 changed files with 125 additions and 101 deletions

View File

@ -6,8 +6,8 @@
include("config.php");
include("includes/functions.php");
$query = "SELECT *,A.id as id FROM ipaddr AS A, interfaces as I, devices as D
WHERE A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.status = '1'";
#$query = "SELECT *,A.id as id FROM ipaddr AS A, interfaces as I, devices as D
# WHERE A.interface_id = I.interface_id AND I.device_id = D.device_id AND D.status = '1'";
$data = mysql_query($query);
while($row = mysql_fetch_array($data)) {
@ -22,8 +22,8 @@ while($row = mysql_fetch_array($data)) {
}
}
$query = "SELECT * FROM interfaces AS I, devices as D
WHERE I.device_id = D.device_id AND D.status = '1'";
#$query = "SELECT * FROM interfaces AS I, devices as D
# WHERE I.device_id = D.device_id AND D.status = '1'";
$data = mysql_query($query);
while($row = mysql_fetch_array($data)) {
$index = $row[ifIndex];
@ -40,8 +40,8 @@ while($row = mysql_fetch_array($data)) {
}
}
echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces`"), 0) . " interfaces at start\n");
$interface_query = mysql_query("SELECT interface_id,device_id FROM `interfaces`");
#echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces`"), 0) . " interfaces at start\n");
#$interface_query = mysql_query("SELECT interface_id,device_id FROM `interfaces`");
while ($interface = mysql_fetch_array($interface_query)) {
$device_id = $interface['device_id'];
$interface_id = $interface['interface_id'];
@ -52,8 +52,8 @@ while ($interface = mysql_fetch_array($interface_query)) {
}
echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces`"), 0) . " interfaces at end\n");
echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at start\n");
$link_query = mysql_query("SELECT id,src_if,dst_if FROM `links`");
#echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at start\n");
#$link_query = mysql_query("SELECT id,src_if,dst_if FROM `links`");
while ($link = mysql_fetch_array($link_query)) {
$id = $link['id'];
$src = $link['src_if'];
@ -66,7 +66,7 @@ while ($link = mysql_fetch_array($link_query)) {
echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at end\n");
echo(mysql_result(mysql_query("SELECT COUNT(adj_id) FROM `adjacencies`"), 0) . " adjacencies at start\n");
$link_query = mysql_query("SELECT * FROM `adjacencies` AS A, `interfaces` AS I, `devices` AS D, networks AS N WHERE I.interface_id = A.interface_id AND D.device_id = I.device_id AND N.id = A.network_id;");
$link_query = mysql_query("SELECT * FROM `adjacencies` AS A, `interfaces` AS I, `devices` AS D, networks AS N WHERE I.interface_id = A.interface_id AND D.device_id = I.device_id AND N.id = A.network_id");
while ($link = mysql_fetch_array($link_query)) {
$id = $link['adj_id'];
$netid = $link['network_id'];
@ -76,16 +76,20 @@ while ($link = mysql_fetch_array($link_query)) {
echo("Removed Interface!\n");
}
echo($link['if'] . " (" . $link['interface_id'] . ") -> " . $link['cidr'] . " \n");
list($network, $cidr) = explode("/", $link['cidr']);
$q = mysql_query("SELECT * FROM `ipaddr` WHERE `interface_id` = '" . $link['interface_id'] . "'");
$checksql = "SELECT COUNT(*) FROM `ipaddr` WHERE `interface_id` = '" . $link['interface_id'] . "' AND `cidr` = '$cidr' AND `network` = '$network'";
if(mysql_result(mysql_query($checksql),0) == 0) { $remove = 1; }
# echo($link['if'] . " (" . $link['interface_id'] . ") -> " . $link['cidr'] . " \n");
if($link['cidr'] == "") { $remove = 1; echo("Broken CIDR entry!"); }
if($remove) {
mysql_query("delete from adjacencies where `adj_id` = '$id'");
echo("Deleting link $id \n");
echo("Deleting link $id (".$link['cidr']." - ". $link['hostname'] ." - ". $link['ifDescr'] .")\n");
}
unset($remove);
}

View File

@ -79,6 +79,9 @@ $config['show_locations'] = 1; # Enable Locations on menu
$config['enable_bgp'] = 1; # Enable BGP session collection and display
$config['enable_syslog'] = 1; # Enable Syslog
## If a syslog entry contails these strings it is deleted from the database
$config['syslog_filter'] = array("last message repeated", "Connection from UDP: [127.0.0.1]:");
### Interface name strings to ignore
$config['bad_if'] = array("null", "virtual-", "unrouted", "eobc", "mpls", "sl0", "lp0", "faith0",
"-atm layer", "-atm subif", "-shdsl", "-adsl", "-aal5", "-atm",

View File

@ -3,24 +3,21 @@
if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; }
# if($entry['interface']) {
# $interface = fixifname(getifbyid($entry['interface']));
# }
if(!$entry['processed']) { $entry = process_syslog($entry, 1); }
if(!$entry['deleted']) {
$entry['hostname'] = gethostbyid($entry['device_id']);
unset($icon);
# $icon = geteventicon($entry['message']);
# if($icon) {$icon = "<img src='images/16/$icon'>"; }
echo("<tr style=\"background-color: $bg\">
<td width=0></td>");
echo("<td class=syslog width=125>" . $entry['date'] . "</td>");
if($_GET['page'] == "syslog") {
echo("<td width=200><strong>".generatedevicelink($entry['device_id'], $entry['hostname'])."</strong></td>");
$entry['hostname'] = shorthost($entry['hostname'], 20);
if($_GET['page'] != "device") {
echo("<td width=160><strong>".generatedevicelink($entry)."</strong></td>");
}
@ -31,4 +28,6 @@ if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; }
<td></td>
</tr>");
}
?>

View File

@ -2,7 +2,9 @@
<table border=0 cellpadding=10 cellspacing=10 width=100%>
<tr>
<td bgcolor=#e5e5e5 valign=top>
<table width=100% border=0><tr><td><div style="margin-bottom: 5px; font-size: 18px; font-weight: bold;">Devices with Alerts</div></td><td width=35 align=center><div class=tablehead>Host</div></td><td align=center width=35><div class=tablehead>Int</div></td><td align=center width=35><div class=tablehead>Srv</div></tr>
<?php
# <table width=100% border=0><tr><td><div style="margin-bottom: 5px; font-size: 18px; font-weight: bold;">Devices with Alerts</div></td><td width=35 align=center><div class=tablehead>Host</div></td><td align=center width=35><div class=tablehead>Int</div></td><td align=center width=35><div class=tablehead>Srv</div></tr>
?>
<?php
$nodes = array();
@ -77,7 +79,9 @@ foreach($nodes as $node) {
$intlist = array();
$sql = mysql_query("SELECT `ifDescr`, `ifAlias` FROM interfaces WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `device_id` = '$node'");
$rebooted = mysql_result(mysql_query("SELECT attrib_value FROM `devices` AS D, `devices_attribs` AS A WHERE D.device_id = '$node' AND D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime' AND A.attrib_value > '0' AND A.attrib_value < '86400'"),0);
$uptime = mysql_result(mysql_query("SELECT attrib_value FROM `devices` AS D, `devices_attribs` AS A WHERE D.device_id = '$node' AND D.status = '1' AND A.device_id = D.device_id AND A.attrib_type = 'uptime'"),0);
if($uptime < "86000") { $rebooted = 1; } else { $rebooted = 0; }
while($int = mysql_fetch_row($sql)) { $intlist[] = "<b>$int[0]</b> - $int[1]"; }
foreach ($intlist as $intname) { $intpop .= "$br $intname"; $br = "<br />"; }
@ -97,35 +101,66 @@ foreach($nodes as $node) {
$mouseover = "onmouseover=\"return overlib('<img src=\'graph.php?host=$node&from=$week&to=$now&width=400&height=120&type=cpu\'>');\"
onmouseout=\"return nd();\"";
if(hoststatus($node)) { $statimg = "<img align=absmiddle src=images/16/lightbulb.png alt='Host Up'>"; }
else { $statimg = "<img align=absmiddle src=images/16/lightbulb_off.png alt='Host Down'>";}
if(hoststatus($node)) { $statimg = "<img align=absmiddle src=images/16/lightbulb.png alt='Host Up'>"; $box_bg = "#ffffaa"; }
else { $statimg = "<img align=absmiddle src=images/16/lightbulb_off.png alt='Host Down'>"; $box_bg = "#ffaaaa"; }
if($rebooted) { $statimg = "<img align=absmiddle src=images/16/lightning.png alt='Host Rebooted'>"; }
if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; }
if(devicepermitted($node)) {
echo("<tr bgcolor=$bg>
<td><a href='?page=device&id=$node' $mouseover>$host</a></td>
<td align=center>$statimg</td>
<td align=center><a $intpop>$ints</a></td>
<td align=center><a $srvpop>$services</a></td></tr>");
list ($first, $second, $third) = explode(".", $host);
$shorthost = $first;
if(strlen($first.".".$second) < 16) { $shorthost = $first.".".$second; }
$errorboxes .= "<div style='float: left; padding: 5px; width: 124px; height: 100px; background: $box_bg; margin: 4px;'>
<center><strong>".$shorthost."</strong><br />";
if(hoststatus($node)) {$errorboxes .= " <span class=body-date-1>".formatuptime($uptime, short)."</span> <br />";
} else { $errorboxes .= " <span class=body-date-1>Unreachable</span> <br />"; }
$errorboxes .= " <img src='images/16/disconnect.png' align=absmiddle> <a $intpop><b>$ints</b></a>
<img src='images/16/cog_error.png' align=absmiddle> <a $srvpop><b>$services</b></a>
</center></div>";
# echo("<tr bgcolor=$bg>
# <td><a href='?page=device&id=$node' $mouseover>$host</a></td>
# <td align=center>$statimg</td>
# <td align=center><a $intpop>$ints</a></td>
# <td align=center><a $srvpop>$services</a></td></tr>");
#
}
unset($int, $ints, $intlist, $intpop, $srv, $srvlist, $srvname, $srvpop);
}
#echo("</table>");
#echo("
# </td>
# <td bgcolor=#e5e5e5 width=400 valign=top>
echo("
<div style='clear: both;'>$errorboxes</div> <div style='margin: 4px; clear: both;'> ");
$sql = "SELECT *, DATE_FORMAT(datetime, '%D %b %T') AS date from syslog ORDER BY datetime DESC LIMIT 20";
$query = mysql_query($sql);
echo("<table cellspacing=0 cellpadding=2 width=100%>");
while($entry = mysql_fetch_array($query)) { include("includes/print-syslog.inc"); }
echo("</table>");
echo(" </td>
<td bgcolor=#e5e5e5 width=400 valign=top>
echo("</div>
</td>
<td bgcolor=#e5e5e5 width=275 valign=top>");
/// VOSTRON
/// this stuff can be customised to show whatever you want....
if($_SESSION['userlevel'] >= '5') {

View File

@ -34,7 +34,7 @@ echo("<table cellpadding=0 cellspacing=0><tr><td>
<table width='200' border='0'>
<tr>
<td width='300'><div align='right'>Description</div></td>
<td colspan='3'><input name='descr' width='50'>$descr</input></td>
<td colspan='3'><input name='descr' size='32' value='$descr'></input></td>
</tr>
<tr>
<td>

View File

@ -2,16 +2,9 @@
<?
$sql = "SELECT *, DATE_FORMAT(datetime, '%D %b %T') AS date from syslog ORDER BY datetime DESC LIMIT 1000";
$query = mysql_query($sql);
echo("<table cellspacing=0 cellpadding=2 width=100%>");
while($entry = mysql_fetch_array($query))
{
include("includes/print-syslog.inc");
}
while($entry = mysql_fetch_array($query)) { include("includes/print-syslog.inc"); }
echo("</table>");
?>

View File

@ -11,6 +11,31 @@ include("print-functions.php");
include("billing-functions.php");
include("cisco-entities.php");
include("syslog.php");
function shorthost($hostname, $len=16) {
list ($first, $second, $third, $fourth, $fifth) = explode(".", $hostname);
$shorthost = $first;
if(strlen($first.".".$second) < $len && $second) {
$shorthost = $first.".".$second;
if(strlen($shorthost.".".$third) < $len && $third) {
$shorthost = $shorthost.".".$third;
if(strlen($shorthost.".".$fourth) < $len && $fourth) {
$shorthost = $shorthost.".".$fourth;
if(strlen($shorthost.".".$fifth) < $len && $fifth) {
$shorthost = $shorthost.".".$fifth;
}
}
}
}
return ($shorthost);
}
function rrdtool_update($rrdfile, $rrdupdate) {
global $rrdtool;
return `$rrdtool update $rrdfile $rrdupdate`;
@ -373,7 +398,9 @@ function cidr2netmask() {
<< (32-$netmask)));
}
function formatUptime($diff) {
function formatUptime($diff, $format="long") {
$yearsDiff = floor($diff/31536000);
$diff -= $yearsDiff*31536000;
$daysDiff = floor($diff/86400);
$diff -= $daysDiff*86400;
$hrsDiff = floor($diff/60/60);
@ -381,10 +408,19 @@ function formatUptime($diff) {
$minsDiff = floor($diff/60);
$diff -= $minsDiff*60;
$secsDiff = $diff;
if($daysDiff > '0'){ $uptime .= "$daysDiff days, "; }
if($hrsDiff > '0'){ $uptime .= $hrsDiff . "h "; }
if($minsDiff > '0'){ $uptime .= $minsDiff . "m "; }
if($secsDiff > '0'){ $uptime .= $secsDiff . "s "; }
if($format == "short") {
if($yearsDiff > '0'){ $uptime .= $yearsDiff . "y "; }
if($daysDiff > '0'){ $uptime .= $daysDiff . "d "; }
if($hrsDiff > '0'){ $uptime .= $hrsDiff . "h "; }
if($minsDiff > '0'){ $uptime .= $minsDiff . "m "; }
if($secsDiff > '0'){ $uptime .= $secsDiff . "s "; }
} else {
if($yearsDiff > '0'){ $uptime .= $yearsDiff . " years, "; }
if($daysDiff > '0'){ $uptime .= $daysDiff . " days, "; }
if($hrsDiff > '0'){ $uptime .= $hrsDiff . "h "; }
if($minsDiff > '0'){ $uptime .= $minsDiff . "m "; }
if($secsDiff > '0'){ $uptime .= $secsDiff . "s "; }
}
return "$uptime";
}

View File

@ -4,67 +4,21 @@
include("config.php");
include("includes/functions.php");
if(!$config['enable_syslog']) { echo("Syslog support disabled.\n"); exit(); }
$add = 0;
$discard = 0;
$total = 0;
mysql_query("DELETE FROM `syslog` WHERE `msg` LIKE '%last message repeated%'");
mysql_query("DELETE FROM `syslog` WHERE `msg` LIKE '%Connection from UDP: [89.21.224.44]:%'");
mysql_query("DELETE FROM `syslog` WHERE `msg` LIKE '%Connection from UDP: [89.21.224.35]:%'");
if(!$config['enable_syslog']) {
echo("Syslog support disabled.\n");
exit();
}
$q = mysql_query("SELECT * FROM `syslog` where `processed` = '0'");
while($entry = mysql_fetch_array($q)){
unset($device_id);
unset($maybehost);
unset($perhapshost);
$device_id_host = @mysql_result(mysql_query("SELECT device_id FROM devices WHERE `hostname` = '".$entry['host']."'"),0);
if($device_id_host) {
$device_id = $device_id_host;
} else {
$device_id_ip = @mysql_result(mysql_query("SELECT D.device_id as device_id FROM ipaddr AS A, interfaces AS I, devices AS D WHERE A.addr = '" . $entry['host']."' AND I.interface_id = A.interface_id AND D.device_id = I.device_id"),0);
if($device_id_ip) {
$device_id = $device_id_ip;
}
}
if($device_id) {
if(mysql_result(mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$device_id'"),0) == "IOS") {
list(,$entry[msg]) = split(": %", $entry['msg']);
$entry['msg'] = "%" . $entry['msg'];
$entry['msg'] = preg_replace("/^%(.+?):\ /", "\\1||", $entry['msg']);
list($entry['program'], $entry['msg']) = explode("||", $entry['msg']);
} else {
$program = preg_quote($entry['program'],'/');
$entry['msg'] = preg_replace("/^$program:\ /", "", $entry['msg']);
if(preg_match("/^[a-zA-Z\/]+\[[0-9]+\]:/", $entry['msg'])) {
$entry['msg'] = preg_replace("/^(.+?)\[[0-9]+\]:\ /", "\\1||", $entry['msg']);
list($entry['program'], $entry['msg']) = explode("||", $entry['msg']);
echo("fix! -> " . $entry['program'] . " -> " . $entry['msg'] . "\n");
}
}
$x = "UPDATE `syslog` set `device_id` = '$device_id', `program` = '".$entry['program']."', `msg` = '" . mysql_real_escape_string($entry['msg']) . "', processed = '1' WHERE `seq` = '" . $entry['seq'] . "'";
# echo("$x \n");
mysql_query($x);
unset ($fix);
$add++;
} else {
echo("Failed entry from '" . $entry['host'] . "'");
$x = "DELETE FROM `syslog` where `seq` = '" . $entry['seq'] . "'";
mysql_query($x);
$discard++;
}
$total++;
process_syslog($entry, 1);
}
#echo("$total records processed: $add added to database, $discard discarded");
?>