mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Widget Eventlog Sensors Link and Mouseover functionality (#11380)
* Global Settings - Alert Default Settings * Revert "Global Settings - Alert Default Settings" This reverts commita1af62b146
. * Widget Eventlog - Sensors link and overlib Image * travis fix * handling via AppServiceProvider * collect function * Travis ... * static list of Sensor Types * adding all sensor graph_types * remove collect * correct getTypes - remove change to lower case * class sensor_descr switch * class sensor_descr switch - revert * Use standard sensor type names * move types to attribute list * going back to changes from9eee7fad58
Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
@@ -171,6 +171,53 @@ class Url
|
||||
return Rewrite::normalizeIfName($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Sensor $sensor
|
||||
* @param string $text
|
||||
* @param string $type
|
||||
* @param boolean $overlib
|
||||
* @param boolean $single_graph
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function sensorLink($sensor, $text = null, $type = null, $overlib = true, $single_graph = false)
|
||||
{
|
||||
|
||||
$label = $sensor->sensor_descr;
|
||||
if (!$text) {
|
||||
$text = $label;
|
||||
}
|
||||
|
||||
$content = '<div class=list-large>' . addslashes(htmlentities($sensor->device->displayName() . ' - ' . $label)) . '</div>';
|
||||
|
||||
$content .= "<div style=\'width: 850px\'>";
|
||||
$graph_array = [
|
||||
'type' => $type ?: 'sensor_' . $sensor->sensor_class,
|
||||
'legend' => 'yes',
|
||||
'height' => 100,
|
||||
'width' => 340,
|
||||
'to' => Carbon::now()->timestamp,
|
||||
'from' => Carbon::now()->subDay()->timestamp,
|
||||
'id' => $sensor->sensor_id,
|
||||
];
|
||||
|
||||
$content .= self::graphTag($graph_array);
|
||||
if (!$single_graph) {
|
||||
$graph_array['from'] = Carbon::now()->subWeek()->timestamp;
|
||||
$content .= self::graphTag($graph_array);
|
||||
$graph_array['from'] = Carbon::now()->subMonth()->timestamp;
|
||||
$content .= self::graphTag($graph_array);
|
||||
$graph_array['from'] = Carbon::now()->subYear()->timestamp;
|
||||
$content .= self::graphTag($graph_array);
|
||||
}
|
||||
|
||||
$content .= '</div>';
|
||||
|
||||
if (!$overlib) {
|
||||
return $content;
|
||||
}
|
||||
return self::overlibLink(self::sensorUrl($sensor), $text, $content, self::sensorLinkDisplayClass($sensor));
|
||||
}
|
||||
|
||||
public static function deviceUrl($device, $vars = [])
|
||||
{
|
||||
return self::generate(['page' => 'device', 'device' => $device->device_id], $vars);
|
||||
@@ -181,6 +228,11 @@ class Url
|
||||
return self::generate(['page' => 'device', 'device' => $port->device_id, 'tab' => 'port', 'port' => $port->port_id], $vars);
|
||||
}
|
||||
|
||||
public static function sensorUrl($sensor, $vars = [])
|
||||
{
|
||||
return self::generate(['page' => 'device', 'device' => $sensor->device_id, 'tab' => 'health' , 'metric' => $sensor->sensor_class], $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Port $port
|
||||
* @return string
|
||||
@@ -369,6 +421,25 @@ class Url
|
||||
return "interface-upup";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get html class for a sensor
|
||||
*
|
||||
* @param Sensor $sensor
|
||||
* @return string
|
||||
*/
|
||||
public static function sensorLinkDisplayClass($sensor)
|
||||
{
|
||||
if ($sensor->sensor_current >> $sensor->sensor_limit) {
|
||||
return "sensor-high";
|
||||
}
|
||||
|
||||
if ($sensor->sensor_current << $sensor->sensor_limit_low) {
|
||||
return "sensor-low";
|
||||
}
|
||||
|
||||
return 'sensor-ok';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $os
|
||||
* @param string $feature
|
||||
|
@@ -89,6 +89,13 @@ class EventlogController extends TableController
|
||||
return '<b>' . Url::portLink($port, $port->getShortLabel()) . '</b>';
|
||||
}
|
||||
}
|
||||
} elseif (in_array($eventlog->type, \App\Models\Sensor::getTypes())) {
|
||||
if (is_numeric($eventlog->reference)) {
|
||||
$sensor = $eventlog->related;
|
||||
if (isset($sensor)) {
|
||||
return '<b>' . Url::sensorLink($sensor, $sensor->sensor_descr) . '</b>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $eventlog->type;
|
||||
|
@@ -6,35 +6,34 @@ class Sensor extends DeviceRelatedModel
|
||||
{
|
||||
public $timestamps = false;
|
||||
protected $primaryKey = 'sensor_id';
|
||||
|
||||
protected static $icons = array(
|
||||
'airflow' => 'angle-double-right',
|
||||
'ber' => 'sort-amount-desc',
|
||||
'charge' => 'battery-half',
|
||||
protected static $icons = [
|
||||
'airflow' => 'angle-double-right',
|
||||
'ber' => 'sort-amount-desc',
|
||||
'charge' => 'battery-half',
|
||||
'chromatic_dispersion' => 'indent',
|
||||
'cooling' => 'thermometer-full',
|
||||
'count' => 'hashtag',
|
||||
'current' => 'bolt fa-flip-horizontal',
|
||||
'dbm' => 'sun-o',
|
||||
'delay' => 'clock-o',
|
||||
'eer' => 'snowflake-o',
|
||||
'fanspeed' => 'refresh',
|
||||
'frequency' => 'line-chart',
|
||||
'humidity' => 'tint',
|
||||
'load' => 'percent',
|
||||
'power' => 'power-off',
|
||||
'power_consumed' => 'plug',
|
||||
'power_factor' => 'calculator',
|
||||
'pressure' => 'thermometer-empty',
|
||||
'quality_factor' => 'arrows',
|
||||
'runtime' => 'hourglass-half',
|
||||
'signal' => 'wifi',
|
||||
'snr' => 'signal',
|
||||
'state' => 'bullseye',
|
||||
'temperature' => 'thermometer-three-quarters',
|
||||
'voltage' => 'bolt',
|
||||
'waterflow' => 'tint',
|
||||
);
|
||||
'cooling' => 'thermometer-full',
|
||||
'count' => 'hashtag',
|
||||
'current' => 'bolt fa-flip-horizontal',
|
||||
'dbm' => 'sun-o',
|
||||
'delay' => 'clock-o',
|
||||
'eer' => 'snowflake-o',
|
||||
'fanspeed' => 'refresh',
|
||||
'frequency' => 'line-chart',
|
||||
'humidity' => 'tint',
|
||||
'load' => 'percent',
|
||||
'power' => 'power-off',
|
||||
'power_consumed' => 'plug',
|
||||
'power_factor' => 'calculator',
|
||||
'pressure' => 'thermometer-empty',
|
||||
'quality_factor' => 'arrows',
|
||||
'runtime' => 'hourglass-half',
|
||||
'signal' => 'wifi',
|
||||
'snr' => 'signal',
|
||||
'state' => 'bullseye',
|
||||
'temperature' => 'thermometer-three-quarters',
|
||||
'voltage' => 'bolt',
|
||||
'waterflow' => 'tint',
|
||||
];
|
||||
|
||||
// ---- Helper Functions ----
|
||||
|
||||
@@ -54,6 +53,11 @@ class Sensor extends DeviceRelatedModel
|
||||
return collect(self::$icons)->get($this->sensor_class, 'delicius');
|
||||
}
|
||||
|
||||
public static function getTypes()
|
||||
{
|
||||
return array_keys(self::$icons);
|
||||
}
|
||||
|
||||
// for the legacy menu
|
||||
public static function getIconMap()
|
||||
{
|
||||
|
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Models\Sensor;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Permissions;
|
||||
use LibreNMS\Util\IP;
|
||||
@@ -74,12 +75,16 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
private function configureMorphAliases()
|
||||
{
|
||||
Relation::morphMap([
|
||||
$sensor_types = [];
|
||||
foreach (Sensor::getTypes() as $sensor_type) {
|
||||
$sensor_types[$sensor_type] = \App\Models\Sensor::class;
|
||||
};
|
||||
Relation::morphMap(array_merge([
|
||||
'interface' => \App\Models\Port::class,
|
||||
'sensor' => \App\Models\Sensor::class,
|
||||
'device' => \App\Models\Device::class,
|
||||
'device_group' => \App\Models\DeviceGroup::class,
|
||||
]);
|
||||
], $sensor_types));
|
||||
}
|
||||
|
||||
private function registerFacades()
|
||||
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class EventlogSensorReferenceCleanup extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
foreach (\App\Models\Sensor::getTypes() as $type) {
|
||||
DB::table('eventlog')->where('type', ucfirst($type))->update(['type' => $type]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
foreach (\App\Models\Sensor::getTypes() as $type) {
|
||||
DB::table('eventlog')->where('type', $type)->update(['type' => ucfirst($type)]);
|
||||
}
|
||||
}
|
||||
}
|
@@ -822,6 +822,22 @@ a.interface-upup:hover, a.interface-updown:hover, a.interface-admindown:hover {
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.sensor-low, a.sensor-low, a.sensor-low:visited {
|
||||
color: #c11;
|
||||
}
|
||||
|
||||
.sensor-high, a.sensor-high, a.sensor-high:visited {
|
||||
color: #c11;
|
||||
}
|
||||
|
||||
.sensor-ok, a.sensor-ok, a.sensor-ok:visited {
|
||||
color: #11a;
|
||||
}
|
||||
|
||||
a.sensor-ok:hover, a.sensor-low:hover, a.sensor-high:hover {
|
||||
color: #990099;
|
||||
}
|
||||
|
||||
#top {
|
||||
height:17px;
|
||||
padding:2px 21px 0px 21px;
|
||||
|
@@ -200,10 +200,10 @@ function record_sensor_data($device, $all_sensors)
|
||||
// FIXME also warn when crossing WARN level!
|
||||
if ($sensor['sensor_limit_low'] != '' && $prev_sensor_value > $sensor['sensor_limit_low'] && $sensor_value < $sensor['sensor_limit_low'] && $sensor['sensor_alert'] == 1) {
|
||||
echo 'Alerting for '.$device['hostname'].' '.$sensor['sensor_descr']."\n";
|
||||
log_event("$class {$sensor['sensor_descr']} under threshold: $sensor_value $unit (< {$sensor['sensor_limit_low']} $unit)", $device, $class, 4, $sensor['sensor_id']);
|
||||
log_event("$class under threshold: $sensor_value $unit (< {$sensor['sensor_limit_low']} $unit)", $device, $sensor['sensor_class'], 4, $sensor['sensor_id']);
|
||||
} elseif ($sensor['sensor_limit'] != '' && $prev_sensor_value < $sensor['sensor_limit'] && $sensor_value > $sensor['sensor_limit'] && $sensor['sensor_alert'] == 1) {
|
||||
echo 'Alerting for '.$device['hostname'].' '.$sensor['sensor_descr']."\n";
|
||||
log_event("$class {$sensor['sensor_descr']} above threshold: $sensor_value $unit (> {$sensor['sensor_limit']} $unit)", $device, $class, 4, $sensor['sensor_id']);
|
||||
log_event("$class above threshold: $sensor_value $unit (> {$sensor['sensor_limit']} $unit)", $device, $sensor['sensor_class'], 4, $sensor['sensor_id']);
|
||||
}
|
||||
if ($sensor['sensor_class'] == 'state' && $prev_sensor_value != $sensor_value) {
|
||||
$trans = array_column(
|
||||
|
Reference in New Issue
Block a user