diff --git a/cleanup.php b/cleanup.php index 854e08799..e3b6c26cc 100755 --- a/cleanup.php +++ b/cleanup.php @@ -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); } diff --git a/config.php.default b/config.php.default index 522d4dfd8..ca11d0b70 100755 --- a/config.php.default +++ b/config.php.default @@ -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", diff --git a/html/includes/print-syslog.inc b/html/includes/print-syslog.inc index 538afdb67..5d17cfe67 100644 --- a/html/includes/print-syslog.inc +++ b/html/includes/print-syslog.inc @@ -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 = ""; } - echo(" "); echo("" . $entry['date'] . ""); - if($_GET['page'] == "syslog") { - echo("".generatedevicelink($entry['device_id'], $entry['hostname']).""); + $entry['hostname'] = shorthost($entry['hostname'], 20); + + if($_GET['page'] != "device") { + echo("".generatedevicelink($entry).""); } @@ -31,4 +28,6 @@ if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; } "); + } + ?> diff --git a/html/pages/default.php b/html/pages/default.php index a7e2eaa24..9fa7e3ec5 100644 --- a/html/pages/default.php +++ b/html/pages/default.php @@ -2,7 +2,9 @@ +# -
- + +?> '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[] = "$int[0] - $int[1]"; } foreach ($intlist as $intname) { $intpop .= "$br $intname"; $br = "
"; } @@ -97,35 +101,66 @@ foreach($nodes as $node) { $mouseover = "onmouseover=\"return overlib('');\" onmouseout=\"return nd();\""; - if(hoststatus($node)) { $statimg = "Host Up"; } - else { $statimg = "Host Down";} + if(hoststatus($node)) { $statimg = "Host Up"; $box_bg = "#ffffaa"; } + else { $statimg = "Host Down"; $box_bg = "#ffaaaa"; } + if($rebooted) { $statimg = "Host Rebooted"; } if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; } if(devicepermitted($node)) { - echo(" - - - - "); + list ($first, $second, $third) = explode(".", $host); + $shorthost = $first; + if(strlen($first.".".$second) < 16) { $shorthost = $first.".".$second; } + + + $errorboxes .= "
+
".$shorthost."
"; + + if(hoststatus($node)) {$errorboxes .= " ".formatuptime($uptime, short)."
"; + } else { $errorboxes .= " Unreachable
"; } + + $errorboxes .= " $ints + $services +
"; + + +# echo(" +# +# +# +# "); +# } unset($int, $ints, $intlist, $intpop, $srv, $srvlist, $srvname, $srvpop); } +#echo("
Devices with Alerts
Host
Int
Srv
Devices with Alerts
Host
Int
Srv
$host$statimg$ints$services
$host$statimg$ints$services
"); + +#echo(" +#
+ +echo(" + +
$errorboxes
"); + +$sql = "SELECT *, DATE_FORMAT(datetime, '%D %b %T') AS date from syslog ORDER BY datetime DESC LIMIT 20"; +$query = mysql_query($sql); +echo(""); +while($entry = mysql_fetch_array($query)) { include("includes/print-syslog.inc"); } echo("
"); -echo("
+echo(" "); -/// VOSTRON +/// this stuff can be customised to show whatever you want.... if($_SESSION['userlevel'] >= '5') { diff --git a/html/pages/device/dev-edit.inc b/html/pages/device/dev-edit.inc index c3c6e0535..7e73c1379 100644 --- a/html/pages/device/dev-edit.inc +++ b/html/pages/device/dev-edit.inc @@ -34,7 +34,7 @@ echo("
- +
Description
$descr
diff --git a/html/pages/syslog.php b/html/pages/syslog.php index c17af350d..771652fd8 100644 --- a/html/pages/syslog.php +++ b/html/pages/syslog.php @@ -2,16 +2,9 @@ "); - -while($entry = mysql_fetch_array($query)) -{ - include("includes/print-syslog.inc"); -} - +while($entry = mysql_fetch_array($query)) { include("includes/print-syslog.inc"); } echo("
"); ?> diff --git a/includes/functions.php b/includes/functions.php index 75d368f0f..ab8274dc7 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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"; } diff --git a/process-syslog.php b/process-syslog.php index 4cb7a9964..957bab883 100755 --- a/process-syslog.php +++ b/process-syslog.php @@ -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"); - ?>