1<?php 2/** 3 * wireless-sensor.inc.php 4 * 5 * Common file for Wireless Sensor Graphs 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 * 20 * @link https://www.librenms.org 21 * @copyright 2017 Tony Murray 22 * @author Tony Murray <murraytony@gmail.com> 23 */ 24require 'includes/html/graphs/common.inc.php'; 25 26// escape % characters 27$unit = preg_replace('/(?<!%)%(?!%)/', '%%', $unit); 28 29if ($unit_long == $sensor['sensor_descr']) { 30 $unit_long = ''; 31} 32 33$col_w = 7 + strlen($unit); 34$sensor_descr_fixed = \LibreNMS\Data\Store\Rrd::fixedSafeDescr($sensor['sensor_descr'], 28); 35 36$rrd_options .= " COMMENT:'" . str_pad($unit_long, 35) . str_pad('Cur', $col_w) . str_pad('Min', $col_w) . "Max\\n'"; 37$rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE"; 38 39$num = '%5.2lf'; // default: float 40$output_def = 'sensor'; 41$factor = 1; 42if ($unit === '') { 43 $num = '%5.0lf'; 44} elseif ($unit == 'bps') { 45 $num = '%5.3lf%s'; 46} elseif ($unit == 'Hz') { 47 $num = '%5.3lf%s'; 48 $factor = 1000000; 49 $output_def = 'sensorhz'; 50 $rrd_options .= " CDEF:$output_def=sensor,$factor,*"; 51} elseif ($unit == 'm') { 52 $num = '%5.3lf%s'; 53 $factor = 1000; 54 $output_def = 'sensorm'; 55 $rrd_options .= " CDEF:$output_def=sensor,$factor,*"; 56} 57 58$rrd_options .= " LINE1.5:$output_def#0000cc:'$sensor_descr_fixed'"; 59 60if (isset($scale_min) && $scale_min >= 0) { 61 $rrd_options .= " AREA:$output_def#0000cc55"; 62} 63 64// ---- limits ---- 65 66if ($vars['width'] > 300) { 67 if (is_numeric($sensor['sensor_limit'])) { 68 $rrd_options .= ' LINE1:' . $sensor['sensor_limit'] * $factor . '#cc000060::dashes'; 69 } 70 71 if (is_numeric($sensor['sensor_limit_low'])) { 72 $rrd_options .= ' LINE1:' . $sensor['sensor_limit_low'] * $factor . '#cc000060::dashes'; 73 } 74} 75 76// ---- legend ---- 77 78$rrd_options .= " GPRINT:$output_def:LAST:'$num$unit'"; 79$rrd_options .= " GPRINT:$output_def:MIN:'$num$unit'"; 80$rrd_options .= " GPRINT:$output_def:MAX:'$num$unit'\\l"; 81