mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Wireless Sensors Overhaul (#6471)
* feature: Wireless Sensors Includes client counts for ios and unifi Graphing could use some improvement. Alerting and threshold ui not implemented WIP: starting OO based wireless sensors. Class based functionality working remove old functional files add schema file discovery needs to be enabled, not polling fix up schema fix Unifi discovery not returning an array Add some debug when discovering a sensor. Fix style. Add missing semicolin Add a null object (Generic) for OS. Fill out some phpdocs Re-organized code Each sensor type now has it's own discovery and polling interface Custom polling tested with Unifi CCQ Left to do: Implement UI (Graphs and Custom thresholds) Alerting Testing Fix event message text Remove runDiscovery and runPolling from OS, they are unused and don't belong there. Cleanups/docs Missed this file. Remove the requirement to fetch the current value to check validity. Do that automatically if current is not specified A few cleanups here and there First pass at graphing. device_ and wireless_ graphs added. Add RouterOS support Singleton OS instance isn't required right now. Remove that to allow some memory to be freed. Add wireless to the device list metrics. Make all metrics clickable Tweak graphs a bit Implement limit configuration page. Use sensors page as common code instead of duplicating. Clean up some javascript interactions: Allow enter on values to save. Cancel if update is not needed. Enable the clear custom button after setting a custom value. Add some wireless alert rules to the library. Add documentation. Add unifi client counts by ssid in addition to radio. Optimize Sensor polling a bit. Add HP MSM clients support (for full controller) Fix function accessibility Formalize the discovery and poller interfaces. Add Xirrus clients and noise floor move module interfaces to a more appropriate place. push caching code up to os, unsure about this do to the limitations No point in selectively enabling wireless discovery. We only discover if the device supports something. Add RSSI, Power, and Rate. Add these sensors for Ubnt Airos. Clean up some copyrights. Reduce the amount of files need to add new types. Leave graph files for consistency and to allow customization. Remove the old wifi clients graph completely. ciscowlc should have improved counts (total and per-ssid) Schema didn't get added. Impelement the rest of the AirOS sensors Reformat and re-organize the Airos.php class. Add several UBNT AirFiber sensors A few fixes add links to the section headers Add HP MSM mibs. * Schema file got dropped in rebase. * Add wireless menu to view sensors across all devices. Icons in the menu need help :/ * Add HeliOS, Mimosa, and Siklu support Sensors added SNR + Noise * Add power and utilization to Unifi * Update polling to prefetch all sensor data in a few snmp requests as possible * Add Extendair: tx+rx power, aggregate rate, frequency * Add a check for duplicate sensors in discovery. Just print an error for now. * Add Bit Error Ratio (named error-ratio to allow for bit error rate to be added if needed) Fix an incorrect link in the wireless sensors table * Add error rate and change all bps and Hz to use si units * Fixes to limits and frequency display * Fix overview graph frequency display A few decimal place tweaks * Don't allow switching sensor and wireless-sensor graphs, it doesn't work. Change individual distance graphs to use si units * Go through the OS and make sure I got all the sensors I can (probably missed some still) Because pollWirelessChannelAsFrequency() is generic and a little complex, so pull it up to OS. Message to help developers adding supports that don't return an array from discover functions. * Fix some issues * Remove noise and signal for now at least A couple more fixes Add a notification * Oopsie * Bonus AirFiber sensors
This commit is contained in:
@@ -23,7 +23,12 @@ if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !iss
|
||||
echo 'error with data';
|
||||
exit;
|
||||
} else {
|
||||
$update = dbUpdate(array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'], $_POST['device_id']));
|
||||
$update = dbUpdate(
|
||||
array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'),
|
||||
'sensors',
|
||||
'`sensor_id` = ? AND `device_id` = ?',
|
||||
array($_POST['sensor_id'], $_POST['device_id'])
|
||||
);
|
||||
if (!empty($update) || $update == '0') {
|
||||
echo 'success';
|
||||
exit;
|
34
html/includes/forms/wireless-sensor-alert-reset.inc.php
Normal file
34
html/includes/forms/wireless-sensor-alert-reset.inc.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
|
||||
* Copyright (c) 2017 Tony Murray <https://github.com/murrant>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
header('Content-type: text/plain');
|
||||
|
||||
// FUA
|
||||
|
||||
if (is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
for ($x = 0; $x < count($_POST['sensor_id']); $x++) {
|
||||
dbUpdate(
|
||||
array(
|
||||
'sensor_limit' => $_POST['sensor_limit'][$x],
|
||||
'sensor_limit_low' => $_POST['sensor_limit_low'][$x],
|
||||
'sensor_alert' => $_POST['sensor_alert'][$x]
|
||||
),
|
||||
'wireless_sensors',
|
||||
'`sensor_id` = ?',
|
||||
array($_POST['sensor_id'][$x])
|
||||
);
|
||||
}
|
52
html/includes/forms/wireless-sensor-alert-update.inc.php
Normal file
52
html/includes/forms/wireless-sensor-alert-update.inc.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
|
||||
* Copyright (c) 2017 Tony Murray <https://github.com/murrant>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
header('Content-type: text/plain');
|
||||
|
||||
// FUA
|
||||
|
||||
if (is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
|
||||
dbUpdate(array('sensor_custom' => 'No'), 'wireless_sensors', '`sensor_id` = ?', array($_POST['sensor_id']));
|
||||
} else {
|
||||
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) {
|
||||
echo 'error with data';
|
||||
exit;
|
||||
} else {
|
||||
if ($_POST['state'] == 'true') {
|
||||
$state = 1;
|
||||
} elseif ($_POST['state'] == 'false') {
|
||||
$state = 0;
|
||||
} else {
|
||||
$state = 0;
|
||||
}
|
||||
|
||||
$update = dbUpdate(
|
||||
array('sensor_alert' => $state),
|
||||
'wireless_sensors',
|
||||
'`sensor_id` = ? AND `device_id` = ?',
|
||||
array($_POST['sensor_id'], $_POST['device_id'])
|
||||
);
|
||||
if (!empty($update) || $update == '0') {
|
||||
echo 'success';
|
||||
exit;
|
||||
} else {
|
||||
echo 'error';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
40
html/includes/forms/wireless-sensor-update.inc.php
Normal file
40
html/includes/forms/wireless-sensor-update.inc.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
|
||||
* Copyright (c) 2017 Neil Lathwood <https://github.com/murrant>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
header('Content-type: text/plain');
|
||||
|
||||
// FUA
|
||||
|
||||
if (is_admin() === false) {
|
||||
die('ERROR: You need to be admin');
|
||||
}
|
||||
|
||||
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !isset($_POST['data'])) {
|
||||
echo 'error with data';
|
||||
exit;
|
||||
} else {
|
||||
$update = dbUpdate(
|
||||
array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'),
|
||||
'wireless_sensors',
|
||||
'`sensor_id` = ? AND `device_id` = ?',
|
||||
array($_POST['sensor_id'], $_POST['device_id'])
|
||||
);
|
||||
if (!empty($update) || $update == '0') {
|
||||
echo 'success';
|
||||
exit;
|
||||
} else {
|
||||
echo 'error';
|
||||
exit;
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
$colours = 'mixed';
|
||||
$unit_text = 'Clients';
|
||||
$scale_min = '0';
|
||||
|
||||
|
||||
$i = 1;
|
||||
$rrd_filename = rrd_name($device['hostname'], "wificlients-radio$i");
|
||||
while (rrdtool_check_rrd_exists($rrd_filename)) {
|
||||
$rrd_list[$i] =
|
||||
array(
|
||||
'filename' => $rrd_filename,
|
||||
'ds' => 'wificlients',
|
||||
'descr' => "Radio$i Clients",
|
||||
);
|
||||
$i++;
|
||||
$rrd_filename = rrd_name($device['hostname'], "wificlients-radio$i");
|
||||
};
|
||||
|
||||
require 'includes/graphs/generic_multi_line.inc.php';
|
73
html/includes/graphs/device/wireless-sensor.inc.php
Normal file
73
html/includes/graphs/device/wireless-sensor.inc.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* wireless-sensor.inc.php
|
||||
*
|
||||
* Common file for Wireless Sensor Graphs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
require 'includes/graphs/common.inc.php';
|
||||
|
||||
// escape % characters
|
||||
$unit = preg_replace('/(?<!%)%(?!%)/', '%%', $unit);
|
||||
|
||||
$output_def = 'sensor';
|
||||
$num = '%5.1lf'; // default: float
|
||||
if ($unit === '') {
|
||||
$num = '%5.0lf';
|
||||
} elseif ($unit == 'bps') {
|
||||
$num .= '%s';
|
||||
} elseif ($unit == 'Hz') {
|
||||
$output_def = 'sensorhz';
|
||||
$num = '%5.3lf%s';
|
||||
}
|
||||
|
||||
$sensors = dbFetchRows(
|
||||
'SELECT * FROM `wireless_sensors` WHERE `sensor_class` = ? AND `device_id` = ? ORDER BY `sensor_index`',
|
||||
array($class, $device['device_id'])
|
||||
);
|
||||
|
||||
|
||||
if (count($sensors) == 1 && $unit_long == $sensors[0]['sensor_descr']) {
|
||||
$unit_long = '';
|
||||
}
|
||||
|
||||
$col_w = 7 + strlen($unit);
|
||||
$rrd_options .= " COMMENT:'". str_pad($unit_long, 35) . str_pad("Cur", $col_w). str_pad("Min", $col_w) . "Max\\n'";
|
||||
|
||||
foreach ($sensors as $index => $sensor) {
|
||||
$sensor_id = $sensor['sensor_id'];
|
||||
$colour_index = $index % count($config['graph_colours']['mixed']);
|
||||
$colour = $config['graph_colours']['mixed'][$colour_index];
|
||||
|
||||
$sensor_descr_fixed = rrdtool_escape($sensor['sensor_descr'], 28);
|
||||
$rrd_file = rrd_name($device['hostname'], array('wireless-sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_index']));
|
||||
$rrd_options .= " DEF:sensor$sensor_id=$rrd_file:sensor:AVERAGE";
|
||||
|
||||
if ($unit == 'Hz') {
|
||||
$rrd_options .= " CDEF:sensorhz$sensor_id=sensor$sensor_id,1000000,*";
|
||||
}
|
||||
|
||||
$rrd_options .= " LINE1.5:$output_def$sensor_id#$colour:'$sensor_descr_fixed'";
|
||||
$rrd_options .= " GPRINT:$output_def$sensor_id:LAST:'$num$unit'";
|
||||
$rrd_options .= " GPRINT:$output_def$sensor_id:MIN:'$num$unit'";
|
||||
$rrd_options .= " GPRINT:$output_def$sensor_id:MAX:'$num$unit'\\l ";
|
||||
$iter++;
|
||||
}//end foreach
|
10
html/includes/graphs/device/wireless_capacity.inc.php
Normal file
10
html/includes/graphs/device/wireless_capacity.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$class = 'capacity';
|
||||
$unit = '%';
|
||||
$unit_long = '';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_ccq.inc.php
Normal file
10
html/includes/graphs/device/wireless_ccq.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$class = 'ccq';
|
||||
$unit = '%%';
|
||||
$unit_long = 'CCQ';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_clients.inc.php
Normal file
10
html/includes/graphs/device/wireless_clients.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
//$scale_max = '40';
|
||||
|
||||
$class = 'clients';
|
||||
$unit = '';
|
||||
$unit_long = 'Clients';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
9
html/includes/graphs/device/wireless_distance.inc.php
Normal file
9
html/includes/graphs/device/wireless_distance.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
$class = 'distance';
|
||||
$unit = 'km';
|
||||
$unit_long = '';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
9
html/includes/graphs/device/wireless_error-rate.inc.php
Normal file
9
html/includes/graphs/device/wireless_error-rate.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
$class = 'error-rate';
|
||||
$unit = 'bps';
|
||||
$unit_long = 'Error Rate';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_error-ratio.inc.php
Normal file
10
html/includes/graphs/device/wireless_error-ratio.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$class = 'error-ratio';
|
||||
$unit = '%%';
|
||||
$unit_long = 'Error Ratio';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
9
html/includes/graphs/device/wireless_frequency.inc.php
Normal file
9
html/includes/graphs/device/wireless_frequency.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
$class = 'frequency';
|
||||
$unit = 'Hz';
|
||||
$unit_long = 'Hz';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_noise-floor.inc.php
Normal file
10
html/includes/graphs/device/wireless_noise-floor.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '-175';
|
||||
$scale_max = '0';
|
||||
|
||||
$class = 'noise-floor';
|
||||
$unit = '';
|
||||
$unit_long = 'dBm/Hz';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_power.inc.php
Normal file
10
html/includes/graphs/device/wireless_power.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '40';
|
||||
|
||||
$class = 'power';
|
||||
$unit = '';
|
||||
$unit_long = 'dBm';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_quality.inc.php
Normal file
10
html/includes/graphs/device/wireless_quality.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$class = 'quality';
|
||||
$unit = '%';
|
||||
$unit_long = '';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
8
html/includes/graphs/device/wireless_rate.inc.php
Normal file
8
html/includes/graphs/device/wireless_rate.inc.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
$class = 'rate';
|
||||
$unit = 'bps';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_rssi.inc.php
Normal file
10
html/includes/graphs/device/wireless_rssi.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
//$scale_max = '100';
|
||||
|
||||
$class = 'rssi';
|
||||
$unit = '';
|
||||
$unit_long = 'dBm';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_snr.inc.php
Normal file
10
html/includes/graphs/device/wireless_snr.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
|
||||
$class = 'snr';
|
||||
$unit = '';
|
||||
$unit_long = 'dB';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
10
html/includes/graphs/device/wireless_utilization.inc.php
Normal file
10
html/includes/graphs/device/wireless_utilization.inc.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$class = 'utilization';
|
||||
$unit = '%%';
|
||||
$unit_long = 'Utilization';
|
||||
|
||||
require 'includes/graphs/device/wireless-sensor.inc.php';
|
15
html/includes/graphs/wireless/auth.inc.php
Normal file
15
html/includes/graphs/wireless/auth.inc.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
if (is_numeric($vars['id'])) {
|
||||
$sensor = dbFetchRow('SELECT * FROM `wireless_sensors` WHERE `sensor_id` = ?', array($vars['id']));
|
||||
|
||||
if (is_numeric($sensor['device_id']) && ($auth || device_permitted($sensor['device_id']))) {
|
||||
$device = device_by_id_cache($sensor['device_id']);
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], array('wireless-sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_index']));
|
||||
|
||||
$title = generate_device_link($device);
|
||||
$title .= ' :: Wireless Sensor :: '.htmlentities($sensor['sensor_descr']);
|
||||
$auth = true;
|
||||
}
|
||||
}
|
9
html/includes/graphs/wireless/capacity.inc.php
Normal file
9
html/includes/graphs/wireless/capacity.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$unit_long = 'Capacity (%)';
|
||||
$unit = '%';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
9
html/includes/graphs/wireless/ccq.inc.php
Normal file
9
html/includes/graphs/wireless/ccq.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$unit_long = 'CCQ (%)';
|
||||
$unit = '%';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
32
html/includes/graphs/wireless/clients.inc.php
Normal file
32
html/includes/graphs/wireless/clients.inc.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* clients.inc.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
$scale_min = '0';
|
||||
//$scale_max = '40';
|
||||
|
||||
$unit_long = 'Clients';
|
||||
$unit = '';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
8
html/includes/graphs/wireless/distance.inc.php
Normal file
8
html/includes/graphs/wireless/distance.inc.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
$unit_long = 'Distance (m)';
|
||||
$unit = 'm';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
8
html/includes/graphs/wireless/error-rate.inc.php
Normal file
8
html/includes/graphs/wireless/error-rate.inc.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
$unit_long = 'Error Ratio (bps)';
|
||||
$unit = 'bps';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
9
html/includes/graphs/wireless/error-ratio.inc.php
Normal file
9
html/includes/graphs/wireless/error-ratio.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$unit_long = 'Error Ratio (%)';
|
||||
$unit = '%';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
8
html/includes/graphs/wireless/frequency.inc.php
Normal file
8
html/includes/graphs/wireless/frequency.inc.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
$unit_long = 'Frequency (Hz)';
|
||||
$unit = 'Hz';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
8
html/includes/graphs/wireless/noise-floor.inc.php
Normal file
8
html/includes/graphs/wireless/noise-floor.inc.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$scale_min = '-175';
|
||||
$scale_max = '0';
|
||||
|
||||
$unit_long = 'Noise Floor (dBm/Hz)';
|
||||
$unit = 'dBm/Hz';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
9
html/includes/graphs/wireless/power.inc.php
Normal file
9
html/includes/graphs/wireless/power.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
//$scale_min = '-40';
|
||||
//$scale_max = '40';
|
||||
|
||||
$unit_long = 'Power (dBm)';
|
||||
$unit = 'dBm';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
9
html/includes/graphs/wireless/quality.inc.php
Normal file
9
html/includes/graphs/wireless/quality.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$unit_long = 'Quality (%)';
|
||||
$unit = '%';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
9
html/includes/graphs/wireless/rate.inc.php
Normal file
9
html/includes/graphs/wireless/rate.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
//$scale_max = '1000';
|
||||
|
||||
$unit_long = 'Rate (bps)';
|
||||
$unit = 'bps';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
32
html/includes/graphs/wireless/rssi.inc.php
Normal file
32
html/includes/graphs/wireless/rssi.inc.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* rssi.inc.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
$scale_min = '0';
|
||||
//$scale_max = '100';
|
||||
|
||||
$unit_long = 'RSSI (dBm)';
|
||||
$unit = 'dBm';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
8
html/includes/graphs/wireless/snr.inc.php
Normal file
8
html/includes/graphs/wireless/snr.inc.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
|
||||
$unit_long = 'SNR (dB)';
|
||||
$unit = 'dB';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
9
html/includes/graphs/wireless/utilization.inc.php
Normal file
9
html/includes/graphs/wireless/utilization.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$scale_min = '0';
|
||||
$scale_max = '100';
|
||||
|
||||
$unit_long = 'Utilization (%)';
|
||||
$unit = '%';
|
||||
|
||||
include 'wireless-sensor.inc.php';
|
82
html/includes/graphs/wireless/wireless-sensor.inc.php
Normal file
82
html/includes/graphs/wireless/wireless-sensor.inc.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* wireless-sensor.inc.php
|
||||
*
|
||||
* Common file for Wireless Sensor Graphs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
require 'includes/graphs/common.inc.php';
|
||||
|
||||
// escape % characters
|
||||
$unit = preg_replace('/(?<!%)%(?!%)/', '%%', $unit);
|
||||
|
||||
if ($unit_long == $sensor['sensor_descr']) {
|
||||
$unit_long = '';
|
||||
}
|
||||
|
||||
$col_w = 7 + strlen($unit);
|
||||
$sensor_descr_fixed = rrdtool_escape($sensor['sensor_descr'], 28);
|
||||
|
||||
$rrd_options .= " COMMENT:'". str_pad($unit_long, 35) . str_pad("Cur", $col_w). str_pad("Min", $col_w) . "Max\\n'";
|
||||
$rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE";
|
||||
|
||||
$num = '%5.2lf'; // default: float
|
||||
$output_def = 'sensor';
|
||||
$factor = 1;
|
||||
if ($unit === '') {
|
||||
$num = '%5.0lf';
|
||||
} elseif ($unit == 'bps') {
|
||||
$num = '%5.3lf%s';
|
||||
} elseif ($unit == 'Hz') {
|
||||
$num = '%5.3lf%s';
|
||||
$factor = 1000000;
|
||||
$output_def = 'sensorhz';
|
||||
$rrd_options .= " CDEF:$output_def=sensor,$factor,*";
|
||||
} elseif ($unit == 'm') {
|
||||
$num = '%5.3lf%s';
|
||||
$factor = 1000;
|
||||
$output_def = 'sensorm';
|
||||
$rrd_options .= " CDEF:$output_def=sensor,$factor,*";
|
||||
}
|
||||
|
||||
$rrd_options .= " LINE1.5:$output_def#0000cc:'$sensor_descr_fixed'";
|
||||
|
||||
if (isset($scale_min) && $scale_min >= 0) {
|
||||
$rrd_options .= " AREA:$output_def#0000cc55";
|
||||
}
|
||||
|
||||
// ---- limits ----
|
||||
|
||||
if ($vars['width'] > 300) {
|
||||
if (is_numeric($sensor['sensor_limit'])) {
|
||||
$rrd_options .= ' LINE1:'.$sensor['sensor_limit']*$factor.'#cc000060::dashes';
|
||||
}
|
||||
|
||||
if (is_numeric($sensor['sensor_limit_low'])) {
|
||||
$rrd_options .= ' LINE1:'.$sensor['sensor_limit_low']*$factor.'#cc000060::dashes';
|
||||
}
|
||||
}
|
||||
|
||||
// ---- legend ----
|
||||
|
||||
$rrd_options .= " GPRINT:$output_def:LAST:'$num$unit'";
|
||||
$rrd_options .= " GPRINT:$output_def:MIN:'$num$unit'";
|
||||
$rrd_options .= " GPRINT:$output_def:MAX:'$num$unit'\\l";
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
// FIXME - this could do with some performance improvements, i think. possible rearranging some tables and setting flags at poller time (nothing changes outside of then anyways)
|
||||
|
||||
use LibreNMS\Device\WirelessSensor;
|
||||
use LibreNMS\ObjectCache;
|
||||
|
||||
$service_status = get_service_status();
|
||||
@@ -410,6 +411,25 @@ foreach (array_keys($menu_sensors) as $item) {
|
||||
</li>
|
||||
<?php
|
||||
|
||||
$valid_wireless_types = WirelessSensor::getTypes(true);
|
||||
|
||||
if (!empty($valid_wireless_types)) {
|
||||
echo '<li class="dropdown">
|
||||
<a href="wireless/" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown">
|
||||
<i class="fa fa-wifi fa-fw fa-lg fa-nav-icons hidden-md" aria-hidden="true"></i> <span class="hidden-sm">Wireless</span></a>
|
||||
<ul class="dropdown-menu">';
|
||||
|
||||
foreach ($valid_wireless_types as $type => $meta) {
|
||||
echo '<li><a href="wireless/metric='.$type.'/">';
|
||||
echo '<i class="fa fa-'.$meta['icon'].' fa-fw fa-lg" aria-hidden="true"></i> ';
|
||||
echo $meta['short'];
|
||||
echo '</a></li>';
|
||||
}
|
||||
|
||||
echo '</ul></li>';
|
||||
}
|
||||
|
||||
|
||||
$app_list = dbFetchRows("SELECT DISTINCT(`app_type`) AS `app_type` FROM `applications` ORDER BY `app_type`");
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5' && count($app_list) > "0") {
|
||||
|
@@ -162,6 +162,7 @@ foreach (dbFetchRows($sql, $param) as $device) {
|
||||
$device['os_text'] = $config['os'][$device['os']]['text'];
|
||||
$port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id']));
|
||||
$sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id']));
|
||||
$wireless_count = dbFetchCell('SELECT COUNT(*) FROM `wireless_sensors` WHERE `device_id` = ?', array($device['device_id']));
|
||||
|
||||
$actions = '
|
||||
<div class="container-fluid">
|
||||
@@ -203,21 +204,37 @@ foreach (dbFetchRows($sql, $param) as $device) {
|
||||
} elseif ($device['hostname'] !== $device['ip']) {
|
||||
$hostname .= '<br />' . $device['hostname'];
|
||||
}
|
||||
if (empty($port_count)) {
|
||||
$port_count = 0;
|
||||
$col_port = '';
|
||||
}
|
||||
|
||||
$metrics = array();
|
||||
if ($port_count) {
|
||||
$col_port = '<i class="fa fa-link fa-lg icon-theme"></i> ' . $port_count . '<br>';
|
||||
$port_widget = '<a href="' . generate_device_url($device, array('tab' => 'ports')) . '">';
|
||||
$port_widget .= '<span><i class="fa fa-link fa-lg icon-theme"></i> ' . $port_count;
|
||||
$port_widget .= '</span></a> ';
|
||||
$metrics[] = $port_widget;
|
||||
}
|
||||
|
||||
if ($sensor_count) {
|
||||
$col_port .= '<i class="fa fa-dashboard fa-lg icon-theme"></i> ' . $sensor_count;
|
||||
$sensor_widget = '<a href="' . generate_device_url($device, array('tab' => 'health')) . '">';
|
||||
$sensor_widget .= '<span><i class="fa fa-dashboard fa-lg icon-theme"></i> ' . $sensor_count;
|
||||
$sensor_widget .= '</span></a> ';
|
||||
$metrics[] = $sensor_widget;
|
||||
}
|
||||
|
||||
if ($wireless_count) {
|
||||
$wireless_widget = '<a href="' . generate_device_url($device, array('tab' => 'wireless')) . '">';
|
||||
$wireless_widget .= '<span><i class="fa fa-wifi fa-lg icon-theme"></i> ' . $wireless_count;
|
||||
$wireless_widget .= '</span></a> ';
|
||||
$metrics[] = $wireless_widget;
|
||||
}
|
||||
|
||||
$col_port = '<div class="device-table-metrics">';
|
||||
$col_port .= implode(count($metrics) == 2 ? '<br />' : '', $metrics);
|
||||
$col_port .= '</div>';
|
||||
} else {
|
||||
$platform = $device['hardware'];
|
||||
$os = $device['os_text'] . ' ' . $device['version'];
|
||||
$uptime = formatUptime($device['uptime'], 'short');
|
||||
$col_port = '';
|
||||
}
|
||||
|
||||
$response[] = array(
|
||||
|
141
html/includes/table/sensors-common.php
Normal file
141
html/includes/table/sensors-common.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
$graph_type = mres($_POST['graph_type']);
|
||||
$unit = mres($_POST['unit']);
|
||||
$class = mres($_POST['class']);
|
||||
|
||||
$sql = " FROM `$table` AS S, `devices` AS D";
|
||||
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ', devices_perms as P';
|
||||
}
|
||||
|
||||
$sql .= " WHERE S.sensor_class=? AND S.device_id = D.device_id ";
|
||||
$param[] = mres($_POST['class']);
|
||||
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= " AND D.device_id = P.device_id AND P.user_id = ?";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `sensor_descr` LIKE '%$searchPhrase%' OR `sensor_current` LIKE '%searchPhrase')";
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`sensor_id`) $sql";
|
||||
|
||||
$count = dbFetchCell($count_sql, $param);
|
||||
if (empty($count)) {
|
||||
$count = 0;
|
||||
}
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`D`.`hostname`, `S`.`sensor_descr`';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
$sql = "SELECT * $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $sensor) {
|
||||
if (!isset($sensor['sensor_current'])) {
|
||||
$sensor['sensor_current'] = 'NaN';
|
||||
} else {
|
||||
if ($sensor['sensor_current'] >= $sensor['sensor_limit']) {
|
||||
$alert = '<i class="fa fa-flag fa-lg" style="color:red" aria-hidden="true"></i>';
|
||||
} else {
|
||||
$alert = '';
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME - make this "four graphs in popup" a function/include and "small graph" a function.
|
||||
// FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"?
|
||||
// FIXME - DUPLICATED IN device/overview/sensors
|
||||
$graph_colour = str_replace('#', '', $row_colour);
|
||||
|
||||
$graph_array = array();
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '210';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $sensor['sensor_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['legend'] = 'no';
|
||||
|
||||
$link_array = $graph_array;
|
||||
$link_array['page'] = 'graphs';
|
||||
unset($link_array['height'], $link_array['width'], $link_array['legend']);
|
||||
$link_graph = generate_url($link_array);
|
||||
|
||||
$link = generate_url(array('page' => 'device', 'device' => $sensor['device_id'], 'tab' => $tab, 'metric' => $sensor['sensor_class']));
|
||||
|
||||
$overlib_content = '<div style="width: 580px;"><h2>'.$sensor['hostname'].' - '.$sensor['sensor_descr'].'</h1>';
|
||||
foreach (array('day', 'week', 'month', 'year') as $period) {
|
||||
$graph_array['from'] = $config['time'][$period];
|
||||
$overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array));
|
||||
}
|
||||
|
||||
$overlib_content .= '</div>';
|
||||
|
||||
$graph_array['width'] = 80;
|
||||
$graph_array['height'] = 20;
|
||||
$graph_array['bg'] = 'ffffff00';
|
||||
// the 00 at the end makes the area transparent.
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$sensor_minigraph = generate_lazy_graph_tag($graph_array);
|
||||
|
||||
$sensor['sensor_descr'] = substr($sensor['sensor_descr'], 0, 48);
|
||||
|
||||
$response[] = array(
|
||||
'hostname' => generate_device_link($sensor),
|
||||
'sensor_descr' => overlib_link($link, $sensor['sensor_descr'], $overlib_content, null),
|
||||
'graph' => overlib_link($link_graph, $sensor_minigraph, $overlib_content, null),
|
||||
'alert' => $alert,
|
||||
'sensor_current' => $sensor['sensor_current'].$unit,
|
||||
'sensor_range' => round($sensor['sensor_limit_low'], 2).$unit.' - '.round($sensor['sensor_limit'], 2).$unit,
|
||||
);
|
||||
|
||||
if ($_POST['view'] == 'graphs') {
|
||||
$daily_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=211&height=100';
|
||||
$daily_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=400&height=150';
|
||||
|
||||
$weekly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=211&height=100';
|
||||
$weekly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=400&height=150';
|
||||
|
||||
$monthly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=211&height=100';
|
||||
$monthly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=400&height=150';
|
||||
|
||||
$yearly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=211&height=100';
|
||||
$yearly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=400&height=150';
|
||||
|
||||
$response[] = array(
|
||||
'hostname' => "<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$daily_graph' border=0></a> ",
|
||||
'sensor_descr' => "<a onmouseover=\"return overlib('<img src=\'$weekly_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$weekly_graph' border=0></a> ",
|
||||
'graph' => "<a onmouseover=\"return overlib('<img src=\'$monthly_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$monthly_graph' border=0></a>",
|
||||
'alert' => '',
|
||||
'sensor_current' => "<a onmouseover=\"return overlib('<img src=\'$yearly_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$yearly_graph' border=0></a>",
|
||||
'sensor_range' => '',
|
||||
);
|
||||
} //end if
|
||||
}//end foreach
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $count,
|
||||
);
|
||||
echo _json_encode($output);
|
@@ -1,141 +1,6 @@
|
||||
<?php
|
||||
|
||||
$graph_type = mres($_POST['graph_type']);
|
||||
$unit = mres($_POST['unit']);
|
||||
$class = mres($_POST['class']);
|
||||
$table = 'sensors';
|
||||
$tab = 'health';
|
||||
|
||||
$sql = ' FROM `sensors` AS S, `devices` AS D';
|
||||
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ', devices_perms as P';
|
||||
}
|
||||
|
||||
$sql .= " WHERE S.sensor_class=? AND S.device_id = D.device_id ";
|
||||
$param[] = mres($_POST['class']);
|
||||
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= " AND D.device_id = P.device_id AND P.user_id = ?";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `sensor_descr` LIKE '%$searchPhrase%' OR `sensor_current` LIKE '%searchPhrase')";
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`sensor_id`) $sql";
|
||||
|
||||
$count = dbFetchCell($count_sql, $param);
|
||||
if (empty($count)) {
|
||||
$count = 0;
|
||||
}
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`D`.`hostname`, `S`.`sensor_descr`';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
$sql = "SELECT * $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $sensor) {
|
||||
if (!isset($sensor['sensor_current'])) {
|
||||
$sensor['sensor_current'] = 'NaN';
|
||||
} else {
|
||||
if ($sensor['sensor_current'] >= $sensor['sensor_limit']) {
|
||||
$alert = '<i class="fa fa-flag fa-lg" style="color:red" aria-hidden="true"></i>';
|
||||
} else {
|
||||
$alert = '';
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME - make this "four graphs in popup" a function/include and "small graph" a function.
|
||||
// FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"?
|
||||
// FIXME - DUPLICATED IN device/overview/sensors
|
||||
$graph_colour = str_replace('#', '', $row_colour);
|
||||
|
||||
$graph_array = array();
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '210';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $sensor['sensor_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['legend'] = 'no';
|
||||
|
||||
$link_array = $graph_array;
|
||||
$link_array['page'] = 'graphs';
|
||||
unset($link_array['height'], $link_array['width'], $link_array['legend']);
|
||||
$link_graph = generate_url($link_array);
|
||||
|
||||
$link = generate_url(array('page' => 'device', 'device' => $sensor['device_id'], 'tab' => 'health', 'metric' => $sensor['sensor_class']));
|
||||
|
||||
$overlib_content = '<div style="width: 580px;"><h2>'.$sensor['hostname'].' - '.$sensor['sensor_descr'].'</h1>';
|
||||
foreach (array('day', 'week', 'month', 'year') as $period) {
|
||||
$graph_array['from'] = $config['time'][$period];
|
||||
$overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array));
|
||||
}
|
||||
|
||||
$overlib_content .= '</div>';
|
||||
|
||||
$graph_array['width'] = 80;
|
||||
$graph_array['height'] = 20;
|
||||
$graph_array['bg'] = 'ffffff00';
|
||||
// the 00 at the end makes the area transparent.
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$sensor_minigraph = generate_lazy_graph_tag($graph_array);
|
||||
|
||||
$sensor['sensor_descr'] = substr($sensor['sensor_descr'], 0, 48);
|
||||
|
||||
$response[] = array(
|
||||
'hostname' => generate_device_link($sensor),
|
||||
'sensor_descr' => overlib_link($link, $sensor['sensor_descr'], $overlib_content, null),
|
||||
'graph' => overlib_link($link_graph, $sensor_minigraph, $overlib_content, null),
|
||||
'alert' => $alert,
|
||||
'sensor_current' => $sensor['sensor_current'].$unit,
|
||||
'sensor_range' => round($sensor['sensor_limit_low'], 2).$unit.' - '.round($sensor['sensor_limit'], 2).$unit,
|
||||
);
|
||||
|
||||
if ($_POST['view'] == 'graphs') {
|
||||
$daily_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=211&height=100';
|
||||
$daily_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=400&height=150';
|
||||
|
||||
$weekly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=211&height=100';
|
||||
$weekly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['week'].'&to='.$config['time']['now'].'&width=400&height=150';
|
||||
|
||||
$monthly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=211&height=100';
|
||||
$monthly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['month'].'&to='.$config['time']['now'].'&width=400&height=150';
|
||||
|
||||
$yearly_graph = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=211&height=100';
|
||||
$yearly_url = 'graph.php?id='.$sensor['sensor_id'].'&type='.$graph_type.'&from='.$config['time']['year'].'&to='.$config['time']['now'].'&width=400&height=150';
|
||||
|
||||
$response[] = array(
|
||||
'hostname' => "<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$daily_graph' border=0></a> ",
|
||||
'sensor_descr' => "<a onmouseover=\"return overlib('<img src=\'$weekly_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$weekly_graph' border=0></a> ",
|
||||
'graph' => "<a onmouseover=\"return overlib('<img src=\'$monthly_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$monthly_graph' border=0></a>",
|
||||
'alert' => '',
|
||||
'sensor_current' => "<a onmouseover=\"return overlib('<img src=\'$yearly_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$yearly_graph' border=0></a>",
|
||||
'sensor_range' => '',
|
||||
);
|
||||
} //end if
|
||||
}//end foreach
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $count,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
include 'sensors-common.php';
|
||||
|
6
html/includes/table/wireless-sensors.inc.php
Normal file
6
html/includes/table/wireless-sensors.inc.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
$table = 'wireless_sensors';
|
||||
$tab = 'wireless';
|
||||
|
||||
include 'sensors-common.php';
|
Reference in New Issue
Block a user