Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webui: New eventlog severity classification #5830

Merged
merged 14 commits into from Feb 12, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions alerts.php
Expand Up @@ -349,13 +349,13 @@ function ExtTransports($obj)
$prefix[4] = &$prefix[0];
if ($tmp === true) {
echo 'OK';
log_event('Issued '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id']);
log_event('Issued '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id'], null, null, 1);
} elseif ($tmp === false) {
echo 'ERROR';
log_event('Could not issue '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id']);
log_event('Could not issue '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id'], null, null, 5);
} else {
echo 'ERROR: '.$tmp."\r\n";
log_event('Could not issue '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."' Error: ".$tmp, $obj['device_id']);
log_event('Could not issue '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."' Error: ".$tmp, $obj['device_id'], null, null, 5);
}
}

Expand Down
71 changes: 31 additions & 40 deletions html/includes/functions.inc.php
Expand Up @@ -711,46 +711,6 @@ function print_optionbar_end()
}//end print_optionbar_end()


function geteventicon($message)
{
if ($message == 'Device status changed to Down from check') {
$icon = 'fa-bookmark';
$icon_colour = 'red';
}

if ($message == 'Device status changed to Up from check') {
$icon = 'fa-bookmark';
$icon_colour = 'green';
}

if ($message == 'Interface went down' || $message == 'Interface changed state to Down' || $message == 'ifOperStatus: up -> down') {
$icon = 'fa-bookmark';
$icon_colour = 'red';
}

if ($message == 'Interface went up' || $message == 'Interface changed state to Up' || $message == 'ifOperStatus: down -> up') {
$icon = 'fa-bookmark';
$icon_colour = 'green';
}

if ($message == 'Interface disabled' || $message == 'ifAdminStatus: up -> down') {
$icon = 'fa-bookmark';
$icon_colour = 'grey';
}

if ($message == 'Interface enabled' || $message == 'ifAdminStatus: down -> up') {
$icon = 'fa-bookmark';
$icon_colour = 'green';
}

if (isset($icon)) {
return array('icon' => $icon,'colour' => $icon_colour);
} else {
return false;
}
}//end geteventicon()


function overlibprint($text)
{
return "onmouseover=\"return overlib('".$text."');\" onmouseout=\"return nd();\"";
Expand Down Expand Up @@ -1426,3 +1386,34 @@ function array_to_htmljson($data)
return false;
}
}

/**
* @param $eventlog_severity
* @return $eventlog_severity_icon
*/
function eventlog_severity($eventlog_severity)
{
switch ($eventlog_severity) {
case 1:
return "green"; //OK
break;
case 2:
return "royalblue"; //Informational
break;
case 3:
return "gold"; //Notice
break;
case 4:
return "darkorange"; //Warning
break;
case 5:
return "red"; //Critical
break;
case 0:
return "darkgrey"; //Unknown
break;
default:
return "black"; //Unset
break;
}
} // end eventlog_severity
10 changes: 2 additions & 8 deletions html/includes/print-event-short.inc.php
Expand Up @@ -7,15 +7,9 @@
}

unset($icon);
$icon_returned = geteventicon($entry['message']);
$icon_type = $icon_returned['icon'];
$icon_colour = $icon_returned['colour'];
$severity_colour = eventlog_severity($entry['severity']);

if ($icon_type) {
$icon = "<i class='fa $icon_type fa-lg' style='color:$icon_colour' aria-hidden='true'></i>";
} else {
$icon = "<i class='fa fa-bookmark-o fa-lg' style='color:black' aria-hidden='true'></i>";
}
$icon = "<i class='fa fa-bookmark fa-lg' style='color:$severity_colour' aria-hidden='true'></i>";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually sorry to be a pain, one last change. Rather than doing style='color' can you not just create styles in styles.css called log-$colourname and then tack log-darkgrey on the end of fa-lg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm worth a shot! Let me give it a bash, i don't mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, giving it a little thought, I dont think that would work as it would not allow for any future customization of the colours (mine might not be so great!). I think from what I can see we have 2 options,....

  1. Leave it as is
  2. Move the "style=color:xxx" attribute in to the function that determines the colour and just have the $severity_colour variable included?


echo '<tr">
<td>'.$icon.'&nbsp;
Expand Down
10 changes: 2 additions & 8 deletions html/includes/print-event.inc.php
Expand Up @@ -3,15 +3,9 @@
$hostname = gethostbyid($entry['host']);

unset($icon);
$icon_returned = geteventicon($entry['message']);
$icon_type = $icon_returned['icon'];
$icon_colour = $icon_returned['colour'];
$severity_colour = eventlog_severity($entry['severity']);

if ($icon_type) {
$icon = "<i class='fa $icon_type fa-lg' style='color:$icon_colour' aria-hidden='true'></i>";
} else {
$icon = "<i class='fa fa-bookmark-o fa-lg' style='color:black' aria-hidden='true'></i>";
}
$icon = "<i class='fa fa-bookmark fa-lg' style='color:$severity_colour' aria-hidden='true'></i>";

echo '<tr>
<td>'.$icon.'&nbsp;
Expand Down
2 changes: 1 addition & 1 deletion includes/common.php
Expand Up @@ -1543,7 +1543,7 @@ function load_os(&$device)

// Set type to a predefined type for the OS if it's not already set
if ($device['attribs']['override_device_type'] != 1 && $config['os'][$device['os']]['type'] != $device['type']) {
log_event('Device type changed '.$device['type'].' => '.$config['os'][$device['os']]['type'], $device, 'system');
log_event('Device type changed '.$device['type'].' => '.$config['os'][$device['os']]['type'], $device, 'system', null, 3);
$device['type'] = $config['os'][$device['os']]['type'];
dbUpdate(array('type' => $device['type']), 'devices', 'device_id=?', array($device['device_id']));
echo "Device type changed to " . $device['type'] . "!\n";
Expand Down
4 changes: 2 additions & 2 deletions includes/discovery/os.inc.php
Expand Up @@ -2,15 +2,15 @@

$os = getHostOS($device);
if ($os != $device['os']) {
log_event('Device OS changed '.$device['os']." => $os", $device, 'system');
log_event('Device OS changed '.$device['os']." => $os", $device, 'system', null, 3);
$device['os'] = $os;
$sql = dbUpdate(array('os' => $os), 'devices', 'device_id=?', array($device['device_id']));
echo "Changed OS! : $os\n";
}

$icon = getImageName($device, false);
if ($icon != $device['icon']) {
log_event('Device Icon changed '.$device['icon']." => $icon", $device, 'system');
log_event('Device Icon changed '.$device['icon']." => $icon", $device, 'system', null, 3);
$device['icon'] = $icon;
$sql = dbUpdate(array('icon' => $icon), 'devices', 'device_id=?', array($device['device_id']));
echo "Changed Icon! : $icon\n";
Expand Down
9 changes: 5 additions & 4 deletions includes/functions.php
Expand Up @@ -306,9 +306,9 @@ function renamehost($id, $new, $source = 'console')
$host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id));
if (!is_dir($config['rrd_dir']."/$new") && rename($config['rrd_dir']."/$host", $config['rrd_dir']."/$new") === true) {
dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id));
log_event("Hostname changed -> $new ($source)", $id, 'system');
log_event("Hostname changed -> $new ($source)", $id, 'system', null, 3);
} else {
log_event("Renaming of $host failed", $id, 'system');
log_event("Renaming of $host failed", $id, 'system', null, 5);
if (__FILE__ === $_SERVER['SCRIPT_FILE_NAME']) {
echo "Renaming of $host failed\n";
} else {
Expand Down Expand Up @@ -362,7 +362,7 @@ function delete_device($id)
}

$ret .= "Removed device $host\n";
log_event("Device $host has been removed", 0, 'system');
log_event("Device $host has been removed", 0, 'system', null, 3);
return $ret;
}

Expand Down Expand Up @@ -796,7 +796,7 @@ function get_astext($asn)
}

# Use this function to write to the eventlog table
function log_event($text, $device = null, $type = null, $reference = null)
function log_event($text, $device = null, $type = null, $reference = null, $severity = 2)
{
if (!is_array($device)) {
$device = device_by_id_cache($device);
Expand All @@ -807,6 +807,7 @@ function log_event($text, $device = null, $type = null, $reference = null)
'reference' => ($reference ? $reference : "NULL"),
'type' => ($type ? $type : "NULL"),
'datetime' => array("NOW()"),
'severity' => $severity,
'message' => $text);

dbInsert($insert, 'eventlog');
Expand Down
2 changes: 1 addition & 1 deletion includes/polling/core.inc.php
Expand Up @@ -52,7 +52,7 @@

if (is_numeric($uptime) && ($config['os'][$device['os']]['bad_uptime'] !== true)) {
if ($uptime < $device['uptime']) {
log_event('Device rebooted after ' . formatUptime($device['uptime']), $device, 'reboot', $device['uptime']);
log_event('Device rebooted after ' . formatUptime($device['uptime']), $device, 'reboot', $device['uptime'], 4);
}

$tags = array(
Expand Down
4 changes: 2 additions & 2 deletions includes/rrdtool.inc.php
Expand Up @@ -424,10 +424,10 @@ function rrd_file_rename($device, $oldname, $newname)
$newrrd = rrd_name($device['hostname'], $newname);
if (is_file($oldrrd) && !is_file($newrrd)) {
if (rename($oldrrd, $newrrd)) {
log_event("Renamed $oldrrd to $newrrd", $device, "poller");
log_event("Renamed $oldrrd to $newrrd", $device, "poller", null, 1);
return true;
} else {
log_event("Failed to rename $oldrrd to $newrrd", $device, "poller");
log_event("Failed to rename $oldrrd to $newrrd", $device, "poller", null, 5);
return false;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion includes/services.inc.php
Expand Up @@ -105,7 +105,7 @@ function discover_service($device, $service)
{
if (! dbFetchCell('SELECT COUNT(service_id) FROM `services` WHERE `service_type`= ? AND `device_id` = ?', array($service, $device['device_id']))) {
add_service($device, $service, "(Auto discovered) $service");
log_event('Autodiscovered service: type '.mres($service), $device, 'service');
log_event('Autodiscovered service: type '.mres($service), $device, 'service', null, 2);
echo '+';
}
echo "$service ";
Expand Down
4 changes: 2 additions & 2 deletions includes/snmptrap/linkDown.inc.php
Expand Up @@ -8,13 +8,13 @@

$ifOperStatus = 'down';
// $ifAdminStatus = "down";
log_event('SNMP Trap: linkDown '.$interface['ifDescr'], $device, 'interface', $interface['port_id']);
log_event('SNMP Trap: linkDown '.$interface['ifDescr'], $device, 'interface', $interface['port_id'], 5);

// if ($ifAdminStatus != $interface['ifAdminStatus'])
// {
// log_event("Interface Disabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
// }
if ($ifOperStatus != $interface['ifOperStatus']) {
log_event('Interface went Down : '.$interface['ifDescr'].' (TRAP)', $device, 'interface', $interface['port_id']);
log_event('Interface went Down : '.$interface['ifDescr'].' (TRAP)', $device, 'interface', $interface['port_id'], 5);
dbUpdate(array('ifOperStatus' => 'down'), 'ports', 'port_id=?', array($interface['port_id']));
}
6 changes: 3 additions & 3 deletions includes/snmptrap/linkUp.inc.php
Expand Up @@ -9,14 +9,14 @@
$ifOperStatus = "up";
$ifAdminStatus = "up";

log_event("SNMP Trap: linkUp $ifAdminStatus/$ifOperStatus " . $interface['ifDescr'], $device, "interface", $interface['port_id']);
log_event("SNMP Trap: linkUp $ifAdminStatus/$ifOperStatus " . $interface['ifDescr'], $device, "interface", $interface['port_id'], 1);

if ($ifAdminStatus != $interface['ifAdminStatus']) {
log_event("Interface Enabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
log_event("Interface Enabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id'], 3);
dbUpdate(array('ifAdminStatus' => 'up'), 'ports', 'port_id=?', array($interface['port_id']));
}

if ($ifOperStatus != $interface['ifOperStatus']) {
log_event("Interface went Up : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']);
log_event("Interface went Up : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id'], 1);
dbUpdate(array('ifOperStatus' => 'up'), 'ports', 'port_id=?', array($interface['port_id']));
}
1 change: 1 addition & 0 deletions sql-schema/161.sql
@@ -0,0 +1 @@
ALTER TABLE `eventlog` ADD COLUMN `severity` INT(1) NULL DEFAULT 2 AFTER `reference`;