Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2017-05-01 23:49:11 -05:00
<?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
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-05-01 23:49:11 -05:00
*
2021-02-09 00:29:04 +01:00
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
2017-05-01 23:49:11 -05:00
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
2019-04-11 23:26:42 -05:00
require 'includes/html/graphs/common.inc.php';
2017-05-01 23:49:11 -05:00
// 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`',
[$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'";
2017-05-01 23:49:11 -05:00
foreach ($sensors as $index => $sensor) {
$sensor_id = $sensor['sensor_id'];
2019-06-23 00:29:12 -05:00
$colour_index = $index % count(\LibreNMS\Config::get('graph_colours.mixed'));
$colour = \LibreNMS\Config::get("graph_colours.mixed.$colour_index");
2017-05-01 23:49:11 -05:00
2021-03-28 17:25:30 -05:00
$sensor_descr_fixed = \LibreNMS\Data\Store\Rrd::fixedSafeDescr($sensor['sensor_descr'], 28);
$rrd_file = Rrd::name($device['hostname'], ['wireless-sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_index']]);
2017-05-01 23:49:11 -05:00
$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 ";
2017-05-01 23:49:11 -05:00
$iter++;
}//end foreach