2010-12-02 16:45:32 +00:00
< ? php
2016-02-26 23:40:34 +01:00
if ( $sensor_class == 'state' ) {
2016-07-22 18:36:10 -05:00
$sensors = dbFetchRows ( 'SELECT * FROM `sensors` LEFT JOIN `sensors_to_state_indexes` ON sensors_to_state_indexes.sensor_id = sensors.sensor_id LEFT JOIN state_indexes ON state_indexes.state_index_id = sensors_to_state_indexes.state_index_id WHERE `sensor_class` = ? AND device_id = ? ORDER BY `sensor_type`, `sensor_index`+0, `sensor_oid`' , array ( $sensor_class , $device [ 'device_id' ]));
2016-08-18 20:28:22 -05:00
} else {
2016-04-23 20:14:22 -05:00
$sensors = dbFetchRows ( 'SELECT * FROM `sensors` WHERE `sensor_class` = ? AND device_id = ? ORDER BY `poller_type`, `sensor_oid`, `sensor_index`' , array ( $sensor_class , $device [ 'device_id' ]));
2016-02-26 23:40:34 +01:00
}
2015-07-13 20:10:26 +02:00
if ( count ( $sensors )) {
echo ' < div class = " container-fluid " >
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 " > ' ;
echo '<a href="device/device=' . $device [ 'device_id' ] . '/tab=health/metric=' . strtolower ( $sensor_type ) . '/"><img src="images/icons/' . strtolower ( $sensor_type ) . '.png"><strong> ' . $sensor_type . '</strong></a>' ;
echo ' </ div >
< table class = " table table-hover table-condensed table-striped " > ' ;
foreach ( $sensors as $sensor ) {
2016-02-26 23:40:34 +01:00
$state_translation = array ();
if ( ! empty ( $sensor [ 'state_index_id' ])) {
$state_translation = dbFetchRows ( 'SELECT * FROM `state_translations` WHERE `state_index_id` = ? AND `state_value` = ? ' , array ( $sensor [ 'state_index_id' ], $sensor [ 'sensor_current' ]));
}
2016-02-09 14:20:36 -06: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
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
2015-07-13 20:10:26 +02:00
$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' ;
2010-12-02 16:45:32 +00:00
2015-07-13 20:10:26 +02:00
$link_array = $graph_array ;
$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
2016-08-18 20:28:22 -05:00
if ( $sensor [ 'poller_type' ] == " ipmi " ) {
2016-08-10 04:55:30 +03:00
$sensor [ 'sensor_descr' ] = truncate ( ipmiSensorName ( $device [ 'hardware' ], $sensor [ 'sensor_descr' ], $ipmiSensorsNames ), 48 , '' );
} else {
$sensor [ 'sensor_descr' ] = truncate ( $sensor [ 'sensor_descr' ], 48 , '' );
}
2011-09-17 19:14:44 +00:00
2015-07-13 20:10:26 +02:00
$overlib_content = '<div style="width: 580px;"><h2>' . $device [ '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 ));
}
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
2015-07-13 20:10:26 +02:00
$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' ];
2015-07-16 12:42:58 -04:00
$sensor_minigraph = generate_lazy_graph_tag ( $graph_array );
2010-12-02 16:45:32 +00:00
2016-02-26 23:40:34 +01:00
if ( ! empty ( $state_translation [ '0' ][ 'state_descr' ])) {
$state_style = " " ;
2016-02-28 01:27:23 +01:00
switch ( $state_translation [ '0' ][ 'state_generic_value' ]) {
2016-02-26 23:40:34 +01:00
case 0 : // OK
$state_style = " class='label label-success' " ;
break ;
case 1 : // Warning
$state_style = " class='label label-warning' " ;
break ;
case 2 : // Critical
$state_style = " class='label label-danger' " ;
break ;
case 3 : // Unknown
default :
$state_style = " class='label label-default' " ;
break ;
}
echo ' < tr >
2016-02-28 02:29:51 +01: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, ' < span '.$state_style.' > '.$state_translation[' 0 '][' state_descr '].' </ span > ', $overlib_content, $sensor_class).' </ td >
2016-02-26 23:40:34 +01:00
</ tr > ' ;
2016-08-18 20:28:22 -05:00
} else {
2016-02-26 23:40:34 +01:00
echo ' < tr >
2016-02-28 02:29:51 +01: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, ' < span '.($sensor[' sensor_current '] < $sensor[' sensor_limit_low '] || $sensor[' sensor_current '] > $sensor[' sensor_limit '] ? "style=' color : red '" : ' ').' > '.$sensor[' sensor_current '].$sensor_unit.' </ span > ', $overlib_content, $sensor_class).' </ td >
2016-02-26 23:40:34 +01: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>' ;
echo '</div>' ;
} //end if