2010-12-02 16:45:32 +00:00
<? php
2020-09-21 15:40:17 +02:00
$sensors = dbFetchRows ( 'SELECT * FROM `sensors` WHERE `sensor_class` = ? AND device_id = ? ORDER BY `group`, `sensor_descr`, `sensor_oid`, `sensor_index`' , [ $sensor_class , $device [ 'device_id' ]]);
2016-02-26 23:40:34 +01:00
2015-07-13 20:10:26 +02:00
if ( count ( $sensors )) {
2019-01-20 13:37:08 -06:00
$icons = \App\Models\Sensor :: getIconMap ();
$sensor_fa_icon = 'fa-' . ( isset ( $icons [ $sensor_class ]) ? $icons [ $sensor_class ] : 'delicious' );
2017-01-21 13:24:05 +02:00
2018-11-29 19:23:40 -06:00
echo '
2015-02-26 09:31:24 -07:00
<div class="row">
2015-07-13 20:10:26 +02:00
<div class="col-md-12">
<div class="panel panel-default panel-condensed">
<div class="panel-heading">' ;
2020-09-21 15:40:17 +02:00
echo '<a href="device/device=' . $device [ 'device_id' ] . '/tab=health/metric=' . strtolower ( $sensor_type ) . '/"><i class="fa ' . $sensor_fa_icon . ' fa-lg icon-theme" aria-hidden="true"></i><strong> ' . nicecase ( $sensor_type ) . '</strong></a>' ;
2015-07-13 20:10:26 +02:00
echo ' </div>
<table class="table table-hover table-condensed table-striped">' ;
2019-01-11 16:42:56 -06:00
$group = '' ;
2015-07-13 20:10:26 +02:00
foreach ( $sensors as $sensor ) {
2020-09-21 15:40:17 +02:00
if ( ! isset ( $sensor [ 'sensor_current' ])) {
2015-07-13 20:10:26 +02:00
$sensor [ 'sensor_current' ] = 'NaN' ;
}
2011-05-17 19:21:20 +00:00
2019-01-11 16:42:56 -06:00
if ( $group != $sensor [ 'group' ]) {
$group = $sensor [ 'group' ];
echo "<tr><td colspan='3'><strong> $group </strong></td></tr>" ;
}
2015-07-13 20:10:26 +02:00
// 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 health/sensors
$graph_colour = str_replace ( '#' , '' , $row_colour );
2010-12-02 16:45:32 +00:00
2020-09-21 15:40:17 +02:00
$graph_array = [];
2015-07-13 20:10:26 +02:00
$graph_array [ 'height' ] = '100' ;
2020-09-21 15:40:17 +02:00
$graph_array [ 'width' ] = '210' ;
2019-06-23 00:29:12 -05:00
$graph_array [ 'to' ] = \LibreNMS\Config :: get ( 'time.now' );
2020-09-21 15:40:17 +02:00
$graph_array [ 'id' ] = $sensor [ 'sensor_id' ];
$graph_array [ 'type' ] = $graph_type ;
2019-06-23 00:29:12 -05:00
$graph_array [ 'from' ] = \LibreNMS\Config :: get ( 'time.day' );
2015-07-13 20:10:26 +02:00
$graph_array [ 'legend' ] = 'no' ;
2010-12-02 16:45:32 +00:00
2020-09-21 15:40:17 +02:00
$link_array = $graph_array ;
2015-07-13 20:10:26 +02:00
$link_array [ 'page' ] = 'graphs' ;
unset ( $link_array [ 'height' ], $link_array [ 'width' ], $link_array [ 'legend' ]);
$link = generate_url ( $link_array );
2016-08-10 04:55:30 +03:00
2020-09-21 15:59:34 +02:00
if ( $sensor [ 'poller_type' ] == 'ipmi' ) {
2017-07-03 15:38:58 -05:00
$sensor [ 'sensor_descr' ] = substr ( ipmiSensorName ( $device [ 'hardware' ], $sensor [ 'sensor_descr' ]), 0 , 48 );
2016-08-10 04:55:30 +03:00
} else {
2016-11-20 05:12:25 -06:00
$sensor [ 'sensor_descr' ] = substr ( $sensor [ 'sensor_descr' ], 0 , 48 );
2016-08-10 04:55:30 +03:00
}
2011-09-17 19:14:44 +00:00
2017-11-18 10:26:12 +00:00
$overlib_content = '<div class=overlib><span class=overlib-text>' . $device [ 'hostname' ] . ' - ' . $sensor [ 'sensor_descr' ] . '</span><br />' ;
2020-09-21 15:40:17 +02:00
foreach ([ 'day' , 'week' , 'month' , 'year' ] as $period ) {
2019-06-23 00:29:12 -05:00
$graph_array [ 'from' ] = \LibreNMS\Config :: get ( "time. $period " );
2020-09-21 15:40:17 +02:00
$overlib_content .= str_replace ( '"' , "\'" , generate_graph_tag ( $graph_array ));
2015-07-13 20:10:26 +02:00
}
2011-09-17 19:14:44 +00:00
2015-07-13 20:10:26 +02:00
$overlib_content .= '</div>' ;
2011-09-17 19:14:44 +00:00
2020-09-21 15:40:17 +02:00
$graph_array [ 'width' ] = 80 ;
2015-07-13 20:10:26 +02:00
$graph_array [ 'height' ] = 20 ;
2020-09-21 15:40:17 +02:00
$graph_array [ 'bg' ] = 'ffffff00' ;
2015-07-13 20:10:26 +02:00
// the 00 at the end makes the area transparent.
2019-06-23 00:29:12 -05:00
$graph_array [ 'from' ] = \LibreNMS\Config :: get ( 'time.day' );
2020-09-21 15:40:17 +02:00
$sensor_minigraph = generate_lazy_graph_tag ( $graph_array );
2010-12-02 16:45:32 +00:00
2019-06-27 00:30:10 -05:00
$sensor_current = $graph_type == 'sensor_state' ? get_state_label ( $sensor ) : get_sensor_label_color ( $sensor );
2019-01-22 17:06:27 -06:00
2019-06-27 00:30:10 -05:00
echo '<tr>
2020-09-21 15:40:17 +02:00
<td class="col-md-4">' . overlib_link ( $link , shorten_interface_type ( $sensor [ 'sensor_descr' ]), $overlib_content , $sensor_class ) . '</td>
<td class="col-md-4">' . overlib_link ( $link , $sensor_minigraph , $overlib_content , $sensor_class ) . '</td>
<td class="col-md-4">' . overlib_link ( $link , $sensor_current , $overlib_content , $sensor_class ) . '</td>
2019-06-27 00:30:10 -05:00
</tr>' ;
2015-07-13 20:10:26 +02:00
} //end foreach
2011-03-16 23:10:10 +00:00
2015-07-13 20:10:26 +02:00
echo '</table>' ;
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
} //end if