rejig events system (still not great. meh) clean up some pages.

git-svn-id: http://www.observium.org/svn/observer/trunk@1223 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-06-20 21:37:05 +00:00
parent 64628bd1fb
commit 8060d5a030
19 changed files with 89 additions and 34 deletions

View File

@@ -13,3 +13,4 @@ ALTER TABLE `devices` ADD `serial` text default NULL;
ALTER TABLE `temperature` CHANGE `temp_index` `temp_index` VARCHAR(32) NOT NULL;
ALTER TABLE `ports` CHANGE `ifDescr` `ifDescr` VARCHAR(255) NOT NULL;
CREATE TABLE IF NOT EXISTS `ucd_diskio` ( `diskio_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `diskio_index` int(11) NOT NULL, `diskio_descr` varchar(32) NOT NULL, PRIMARY KEY (`diskio_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
ALTER TABLE `eventlog` CHANGE `type` `type` VARCHAR( 64 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;

View File

@@ -61,6 +61,10 @@ if (file_exists('.svn'))
$db_rev = 0;
}
if ($dbu_rev+0 < "1223") {
include("fix-events.php"); ## Fix events table (needs to copy some data around, so needs script)
}
if ($dbu_rev+0 > $db_rev)
{
if($db_rev+0 < "1000") {

19
fix-events.php Executable file
View File

@@ -0,0 +1,19 @@
<?php
mysql_query("ALTER TABLE `eventlog` DROP `id`");
mysql_query("ALTER TABLE `eventlog` ADD `event_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
$s = "SELECT * FROM eventlog";
$q = mysql_query($s);
while ($event = mysql_fetch_array($q)) {
if($event['interface']) {
mysql_query("UPDATE `eventlog` SET `interface` = NULL, `type` = 'interface', `reference` = '".$event['interface']."' WHERE `event_id` = '".$event['event_id']."'");
}
$i++;
}
mysql_query("ALTER TABLE `eventlog` DROP `interface`");
?>

View File

@@ -1,15 +1,17 @@
<?php
$descr = $_POST['descr'];
$ignore = $_POST['ignore'];
$type = $_POST['type'];
$disabled = $_POST['disabled'];
$community = $_POST['community'];
$snmpver = $_POST['snmpver'];
$descr = mres($_POST['descr']);
$ignore = mres($_POST['ignore']);
$type = mres($_POST['type']);
$disabled = mres($_POST['disabled']);
$community = mres($_POST['community']);
$snmpver = mres($_POST['snmpver']);
$port = mres($_POST['port']);
#FIXME needs more sanity checking!
$sql = "UPDATE `devices` SET `purpose` = '" . mysql_escape_string($descr) . "', `community` = '" . mysql_escape_string($community) . "', `type` = '$type'";
$sql .= ", `snmpver` = '" . mysql_escape_string($snmpver) . "', `ignore` = '$ignore', `disabled` = '$disabled' WHERE `device_id` = '$_GET[id]'";
#FIXME needs more sanity checking! and better feedback
$sql = "UPDATE `devices` SET `purpose` = '" . $descr . "', `community` = '" . $community . "', `type` = '$type'";
$sql .= ", `snmpver` = '" . $snmpver . "', `ignore` = '$ignore', `disabled` = '$disabled', `port` = '$port' WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
$rows_updated = mysql_affected_rows();

View File

@@ -24,11 +24,15 @@ if(isset($bg) && $bg == $list_colour_a) { $bg = $list_colour_b; } else { $bg=$li
</td>");
}
echo('<td class="syslog" width="100">');
if($entry['interface']) {
echo(generateiflink(getifbyid($entry['interface'])));
if($entry['type'] == "interface") {
$entry['link'] = "<b>".generateiflink(getifbyid($entry['reference']))."</b>";
} else {
$entry['link'] = "System";
}
echo("</td><td>" . htmlspecialchars($entry['message']) . "</td>
echo("<td>".$entry['link']."</td>");
echo("<td>".htmlspecialchars($entry['message']) . "</td>
</tr>");

View File

@@ -11,7 +11,7 @@ if(!is_integer($syslog_iter/2)) { $bg_colour = $list_colour_a; } else { $bg_colo
echo("<tr style=\"background-color: $bg_colour\">
<td width=0></td>");
echo("<td class=syslog width=125>" . $entry['date'] . "</td>");
echo("<td class=syslog width=140>" . $entry['date'] . "</td>");
$entry['hostname'] = shorthost($entry['hostname'], 20);

View File

@@ -36,12 +36,22 @@ echo("<table cellpadding=0 cellspacing=0><tr><td>
<tr>
<td width='300'><div align='right'>SNMP Community</div></td>
<td colspan='3'><input name='community' size='20' value='" . $device['community'] . "'></input>
<select name='snmpver'>
</td>
</tr>
<tr>
<td><div align=right>SNMP Version</div></td>
<td><select name='snmpver'>
<option value='v1'>v1</option>
<option value='v2c'" . ($device['snmpver'] == 'v2c' ? 'selected=selected' : '') . ">v2c</option>
</select>
</td>
</tr>
<tr>
<td width='300'><div align='right'>SNMP Port</div></td>
<td colspan='3'><input name='port' size='20' value='" . $device['port'] . "'></input>
</td>
</tr>
<tr>
<td align='right'>
Type

View File

@@ -2,7 +2,7 @@
$query = "SELECT *,DATE_FORMAT(datetime, '%D %b %Y %T') as humandate FROM `eventlog` WHERE `host` = '$_GET[id]' ORDER BY `datetime` DESC LIMIT 0,250";
$data = mysql_query($query);
echo('<table cellspacing="0" cellpadding="1" width="100%">');
echo('<table cellspacing="0" cellpadding="2" width="100%">');
while($entry = mysql_fetch_array($data)) {
include("includes/print-event.inc");

View File

@@ -17,7 +17,7 @@
$text_descr = str_replace("DFC Card", "DFC", $text_descr);
$proc_popup = "onmouseover=\"return overlib('<div class=list-large>".$device['hostname']." - ".$text_descr;
$proc_popup .= "</div><img src=\'graph.php?id=" . $proc['proc_id'] . "&type=proc&from=$month&to=$now&width=400&height=125\'>";
$proc_popup .= "</div><img src=\'graph.php?id=" . $proc['processor_id'] . "&type=processor&from=$month&to=$now&width=400&height=125\'>";
$proc_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"";
$perc = round($proc['processor_usage']);

View File

@@ -65,6 +65,19 @@ echo("
}
$sql = "SELECT *, DATE_FORMAT(timestamp, '%d/%b/%y %T') AS date from syslog WHERE device_id = '" . $_GET['id'] . "' $where";
$sql .= " ORDER BY timestamp DESC LIMIT 20";
$query = mysql_query($sql);
if(mysql_affected_rows() > "0"){
echo("<div style='background-color: #eeeeee; margin: 5px; padding: 5px;'>");
echo("<p style='padding: 0px 5px 5px;' class=sectionhead><img align='absmiddle' src='".$config['base_url']."/images/16/printer.png'> Recent Syslog</p>");
echo("<table cellspacing=0 cellpadding=2 width=100%>");
while($entry = mysql_fetch_array($query)) { include("includes/print-syslog.inc"); }
echo("</table>");
echo("</div>");
}
echo("</div>");
echo("<div style='float:right; width: 50%;'>");

View File

@@ -24,7 +24,7 @@
$mini_url = $config['base_url'] . "/graph.php?id=".$proc['processor_id']."&type=processor&from=".$day."&to=".$now."&width=80&height=20&bg=f4f4f4";
$proc_popup = "onmouseover=\"return overlib('<div class=list-large>".$device['hostname']." - ".$text_descr;
$proc_popup .= "</div><img src=\'graph.php?id=" . $proc['proc_id'] . "&type=proc&from=$month&to=$now&width=400&height=125\'>";
$proc_popup .= "</div><img src=\'graph.php?id=" . $proc['processor_id'] . "&type=processor&from=$month&to=$now&width=400&height=125\'>";
$proc_popup .= "', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\"";
$perc = round($proc['processor_usage']);

View File

@@ -727,6 +727,8 @@ function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
{
global $debug;
if(!is_array($device)) { $device = device_by_id_cache($device); }
$event_query = "INSERT INTO eventlog (host, reference, type, datetime, message) VALUES (" . ($device['device_id'] ? $device['device_id'] : "NULL");
$event_query .= ", '" . ($reference ? $reference : "NULL") . "', '" . ($type ? $type : "NULL") . "', NOW(), '" . mres($text) . "')";
if ($debug) { echo($event_query . "\n"); }

View File

@@ -80,17 +80,17 @@ if ($device['os'] == "junos")
if ($peer['bgpPeerState'] == $bgpPeerState)
{
mail($email, "BGP Session flapped: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session flapped " . formatUptime($bgpPeerFsmEstablishedTime) . " ago.\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')', $config['email_headers']);
eventlog('BGP Session Flap: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
log_event('BGP Session Flap: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id);
}
else if ($bgpPeerState == "established")
{
mail($email, "BGP Session up: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session up since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')', $config['email_headers']);
eventlog('BGP Session Up: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
log_event('BGP Session Up: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id);
}
else if ($peer['bgpPeerState'] == "established")
{
mail($email, "BGP Session down: " . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ' - ' . $peer['astext'] . ')', "BGP Session down since " . formatUptime($bgpPeerFsmEstablishedTime) . ".\n\nHostname : " . $device['hostname'] . "\nPeer IP : " . $peer['bgpPeerIdentifier'] . "\nRemote AS: " . $peer['bgpPeerRemoteAs'] . ' ('.$peer['astext'].')', $config['email_headers']);
eventlog('BGP Session Down: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id']);
log_event('BGP Session Down: ' . $peer['bgpPeerIdentifier'] . ' (AS' . $peer['bgpPeerRemoteAs'] . ')', $device['device_id'], 'bgpPeer', $bgpPeer_id);
}
}
}

View File

@@ -38,7 +38,7 @@ while($dbcurrent = mysql_fetch_array($current_data)) {
$msg .= "A) at " . date($config['timestamp_format']);
mail($email, "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $dbcurrent['current_descr'] . "\n");
eventlog('Current ' . $dbcurrent['current_descr'] . " under threshold: " . $current . " A (< " . $dbcurrent['current_limit_low'] . " A)", $device['device_id']);
log_event('Current ' . $dbcurrent['current_descr'] . " under threshold: " . $current . " A (< " . $dbcurrent['current_limit_low'] . " A)", $device['device_id'], 'current', $current['current_id']);
}
else if($dbcurrent['current_current'] < $dbcurrent['current_limit'] && $current >= $dbcurrent['current_limit'])
{
@@ -47,7 +47,7 @@ while($dbcurrent = mysql_fetch_array($current_data)) {
$msg .= "A) at " . date($config['timestamp_format']);
mail($email, "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $dbcurrent['current_descr'] . "\n");
eventlog('Current ' . $dbcurrent['current_descr'] . " above threshold: " . $current . " A (> " . $dbcurrent['current_limit'] . " A)", $device['device_id']);
log_event('Current ' . $dbcurrent['current_descr'] . " above threshold: " . $current . " A (> " . $dbcurrent['current_limit'] . " A)", $device['device_id'], 'current', $current['current_id']);
}
mysql_query("UPDATE current SET current_current = '$current' WHERE current_id = '" . $dbcurrent['current_id'] . "'");

View File

@@ -33,7 +33,7 @@ while($fanspeed = mysql_fetch_array($fan_data)) {
$msg .= "rpm) at " . date($config['timestamp_format']);
mail($email, "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['fan_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $fanspeed['fan_descr'] . "\n");
eventlog('Fan speed ' . $fanspeed['fan_descr'] . " under threshold: " . $fanspeed['fan_current'] . " rpm (&gt; " . $fanspeed['fan_limit'] . " rpm)", $device['device_id']);
log_event('Fan speed ' . $fanspeed['fan_descr'] . " under threshold: " . $fanspeed['fan_current'] . " rpm (&gt; " . $fanspeed['fan_limit'] . " rpm)", $device['device_id'], 'fanspeed', $fanspeed['fan_id']);
}
mysql_query("UPDATE fanspeed SET fan_current = '$fan' WHERE fan_id = '" . $fanspeed['fan_id'] . "'");

View File

@@ -37,7 +37,7 @@ while($frequency = mysql_fetch_array($freq_data)) {
$msg .= "Hz) at " . date($config['timestamp_format']);
mail($email, "Frequency Alarm: " . $device['hostname'] . " " . $frequency['freq_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $frequency['freq_descr'] . "\n");
eventlog('Frequency ' . $frequency['freq_descr'] . " under threshold: " . $freq . " Hz (< " . $frequency['freq_limit_low'] . " Hz)", $device['device_id']);
log_event('Frequency ' . $frequency['freq_descr'] . " under threshold: " . $freq . " Hz (< " . $frequency['freq_limit_low'] . " Hz)", $device['device_id'] , 'frequency', $frequency['freq_id']);
}
else if($frequency['freq_current'] < $frequency['freq_limit'] && $freq >= $frequency['freq_limit'])
{
@@ -46,7 +46,7 @@ while($frequency = mysql_fetch_array($freq_data)) {
$msg .= "Hz) at " . date($config['timestamp_format']);
mail($email, "Frequency Alarm: " . $device['hostname'] . " " . $frequency['freq_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $frequency['freq_descr'] . "\n");
eventlog('Frequency ' . $frequency['freq_descr'] . " above threshold: " . $freq . " Hz (> " . $frequency['freq_limit'] . " Hz)", $device['device_id']);
log_event('Frequency ' . $frequency['freq_descr'] . " above threshold: " . $freq . " Hz (> " . $frequency['freq_limit'] . " Hz)", $device['device_id'], 'frequency', $frequency['freq_id']);
}
mysql_query("UPDATE frequency SET freq_current = '$freq' WHERE freq_id = '" . $frequency['freq_id'] . "'");

View File

@@ -83,11 +83,11 @@
foreach ($data_oids as $oid) {
if ( $port[$oid] != $this_port[$oid] && !isset($this_port[$oid])) {
$update .= ", `$oid` = NULL";
eventlog($oid . ": ".$port[$oid]." -> NULL", $device['device_id'], $port['interface_id']);
log_event($oid . ": ".$port[$oid]." -> NULL", $device['device_id'], 'interface', $port['interface_id']);
if($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); }
} elseif ( $port[$oid] != $this_port[$oid] ) {
$update .= ", `$oid` = '".mres($this_port[$oid])."'";
eventlog($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device['device_id'], $port['interface_id']);
log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device['device_id'], 'interface', $port['interface_id']);
if($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); }
}
}
@@ -106,7 +106,7 @@
if($port_ifAlias[$attrib] != $port[$attrib_key])
{
$update .= ", `".$attrib_key."` = '".$port_ifAlias[$attrib]."'";
eventlog($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device['device_id'], $port['interface_id']);
log_event($attrib . ": ".$port[$attrib_key]." -> " . $port_ifAlias[$attrib], $device['device_id'], 'interface', $port['interface_id']);
}
}
}
@@ -167,7 +167,7 @@
if ( $this_port[$oid] != $port[$oid] ) { // If data has changed, build a query
$update .= ", `$oid` = '".mres($this_port[$oid])."'";
echo("PAgP ");
eventlog("$oid -> ".$this_port[$oid], $device['device_id'], $port['interface_id']);
log_event("$oid -> ".$this_port[$oid], $device['device_id'], 'interface', $port['interface_id']);
}
}
}

View File

@@ -40,7 +40,7 @@ while($temperature = mysql_fetch_array($temp_data)) {
$msg .= ") at " . date($config['timestamp_format']);
mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $temperature['temp_descr'] . "\n");
eventlog('Temperature ' . $temperature['temp_descr'] . " over threshold: " . $temp . " <20>C (> " . $temperature['temp_limit'] . " <20>C)", $device['device_id']);
log_event('Temperature ' . $temperature['temp_descr'] . " over threshold: " . $temp . " <20>C (> " . $temperature['temp_limit'] . " <20>C)", $device['device_id'], 'temperature', $temperature['temp_id']);
}
mysql_query("UPDATE temperature SET temp_current = '$temp' WHERE temp_id = '" . $temperature['temp_id'] . "'");

View File

@@ -37,7 +37,7 @@ while($voltage = mysql_fetch_array($volt_data)) {
$msg .= "V) at " . date($config['timestamp_format']);
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n");
eventlog('Voltage ' . $voltage['volt_descr'] . " under threshold: " . $volt . " V (< " . $voltage['volt_limit_low'] . " V)", $device['device_id']);
log_event('Voltage ' . $voltage['volt_descr'] . " under threshold: " . $volt . " V (< " . $voltage['volt_limit_low'] . " V)", $device['device_id'], 'voltage', $voltage['volt_id']);
}
else if($voltage['volt_current'] < $voltage['volt_limit'] && $volt >= $voltage['volt_limit'])
{
@@ -46,7 +46,7 @@ while($voltage = mysql_fetch_array($volt_data)) {
$msg .= "V) at " . date($config['timestamp_format']);
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n");
eventlog('Voltage ' . $voltage['volt_descr'] . " above threshold: " . $volt . " V (> " . $voltage['volt_limit'] . " V)", $device['device_id']);
log_event('Voltage ' . $voltage['volt_descr'] . " above threshold: " . $volt . " V (> " . $voltage['volt_limit'] . " V)", $device['device_id'], 'voltage', $voltage['volt_id']);
}
mysql_query("UPDATE voltage SET volt_current = '$volt' WHERE volt_id = '" . $voltage['volt_id'] . "'");