mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
speedups to syslog page, caching of device_id
git-svn-id: http://www.observium.org/svn/observer/trunk@743 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
|
||||
<?php
|
||||
|
||||
if($bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$list_colour_a; }
|
||||
|
||||
$syslog_iter++;
|
||||
if(!is_integer($syslog_iter/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; }
|
||||
|
||||
|
||||
if(!$entry['processed']) { $entry = process_syslog($entry, 1); }
|
||||
if(!$entry['deleted']) {
|
||||
|
||||
echo("<tr style=\"background-color: $bg\">
|
||||
echo("<tr style=\"background-color: $bg_colour\">
|
||||
<td width=0></td>");
|
||||
|
||||
echo("<td class=syslog width=125>" . $entry['date'] . "</td>");
|
||||
|
||||
@@ -102,7 +102,10 @@ if($config['enable_syslog']) {
|
||||
$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"); }
|
||||
while($entry = mysql_fetch_array($query)) {
|
||||
$entry = array_merge($entry, device_by_id_cache($entry['device_id']));
|
||||
include("includes/print-syslog.inc");
|
||||
}
|
||||
echo("</table>");
|
||||
|
||||
echo("</div>"); ## Close Syslog Div
|
||||
|
||||
@@ -72,8 +72,8 @@ echo("
|
||||
<h3>Recent Syslog Messages</h3>
|
||||
|
||||
");
|
||||
|
||||
$sql = "SELECT *, DATE_FORMAT(datetime, '%D %b %T') AS date from syslog ORDER BY datetime DESC LIMIT 20";
|
||||
$sql = "SELECT *, DATE_FORMAT(datetime, '%D %b %T') AS date from syslog AS S, devices AS D
|
||||
WHERE S.device_id = D.device_id 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"); }
|
||||
|
||||
@@ -67,7 +67,10 @@ if($_SESSION['userlevel'] >= '5') {
|
||||
|
||||
$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)) {
|
||||
$entry = array_merge($entry, device_by_id_cache($entry['device_id']));
|
||||
include("includes/print-syslog.inc");
|
||||
}
|
||||
echo("</table>");
|
||||
|
||||
?>
|
||||
|
||||
@@ -24,6 +24,17 @@ require('collectd/config.php');
|
||||
require('collectd/functions.php');
|
||||
require('collectd/definitions.php');
|
||||
|
||||
function device_by_id_cache($device_id) {
|
||||
global $device_cache;
|
||||
if(is_array($device_cache[$device_id])) {
|
||||
$device = $device_cache[$device_id];
|
||||
} else {
|
||||
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'"));
|
||||
$device_cache[$device_id] = $device;
|
||||
}
|
||||
return $device;
|
||||
}
|
||||
|
||||
function mac_clean_to_readable($mac){
|
||||
|
||||
$r = substr($mac, 0, 2);
|
||||
|
||||
+14
-8
@@ -13,17 +13,23 @@ function process_syslog ($entry, $update) {
|
||||
$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;
|
||||
$entry['device_id'] = $device_id_host;
|
||||
} else {
|
||||
$device_id_ip = @mysql_result(mysql_query("SELECT D.device_id as device_id FROM ipv4_addresses AS A, interfaces AS I, devices AS D WHERE A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id AND D.device_id = I.device_id"),0);
|
||||
$device_id_ip = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, interfaces AS I WHERE
|
||||
A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id"),0);
|
||||
|
||||
echo("SELECT device_id FROM ipv4_addresses AS A, interfaces AS I WHERE
|
||||
A.ipv4_address = '" . $entry['host']."' AND I.interface_id = A.interface_id");
|
||||
|
||||
if($device_id_ip) {
|
||||
$device_id = $device_id_ip;
|
||||
$entry['device_id'] = $device_id_ip;
|
||||
}
|
||||
}
|
||||
|
||||
if($device_id && !$delete) {
|
||||
$entry['device_id'] = $device_id;
|
||||
$os = mysql_result(mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$device_id'"),0);
|
||||
print_r($entry);
|
||||
|
||||
if($entry['device_id'] && !$delete) {
|
||||
$os = mysql_result(mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '".$entry['device_id']."'"),0);
|
||||
if($os == "ios" || $os == "iosxe") {
|
||||
if(strstr($entry[msg], "%")) {
|
||||
$entry['msg'] = preg_replace("/^%(.+?):\ /", "\\1||", $entry['msg']);
|
||||
@@ -58,9 +64,9 @@ function process_syslog ($entry, $update) {
|
||||
list($entry['program'], $entry['msg']) = explode("||", $entry['msg']);
|
||||
}
|
||||
}
|
||||
$x = "UPDATE `syslog` set `device_id` = '$device_id', `program` = '".$entry['program']."', `msg` = '" . mysql_real_escape_string($entry['msg']) . "', processed = '1' WHERE `seq` = '" . $entry['seq'] . "'";
|
||||
$x = "UPDATE `syslog` set `device_id` = '".$entry['device_id']."', `program` = '".$entry['program']."', `msg` = '" . mysql_real_escape_string($entry['msg']) . "', processed = '1' WHERE `seq` = '" . $entry['seq'] . "'";
|
||||
$entry['processed'] = 1;
|
||||
if($update) { mysql_query($x); }
|
||||
if($update) { mysql_query($x); echo($x); }
|
||||
unset ($fix);
|
||||
} else {
|
||||
$x = "DELETE FROM `syslog` where `seq` = '" . $entry['seq'] . "'";
|
||||
|
||||
Reference in New Issue
Block a user