52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Observium
|
|
*
|
|
* This file is part of Observium.
|
|
*
|
|
* @package observium
|
|
* @subpackage web
|
|
* @copyright (C) Adam Armstrong
|
|
*
|
|
*/
|
|
|
|
/// SEARCH SENSORS
|
|
$sql = "SELECT * FROM `sensors` LEFT JOIN `devices` USING (`device_id`)" .
|
|
generate_where_clause('`sensor_descr` LIKE ?', $GLOBALS['cache']['where']['devices_permitted']) .
|
|
" ORDER BY `sensor_descr` LIMIT $query_limit";
|
|
$results = dbFetchRows($sql, [ $query_param ]);
|
|
|
|
if (safe_empty($results)) {
|
|
return;
|
|
}
|
|
|
|
$max_len = 35;
|
|
foreach ($results as $result) {
|
|
$name = truncate($result['sensor_descr'], $max_len);
|
|
$device_name = truncate($result['hostname'], $max_len);
|
|
if ($result['hostname'] != $result['sysName'] && $result['sysName']) {
|
|
$device_name .= ' | ' . truncate($result['sysName'], $max_len);
|
|
}
|
|
|
|
$descr = strlen($result['location']) ? escape_html($result['location']) . ' | ' : '';
|
|
$descr .= nicecase($result['sensor_class']) . ' sensor';
|
|
|
|
/// FIXME: once we have alerting, colour this to the sensor's status
|
|
$tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
|
|
|
|
$sensor_search_results[] = [
|
|
'url' => 'graphs/type=sensor_' . $result['sensor_class'] . '/id=' . $result['sensor_id'] . '/',
|
|
'name' => $name,
|
|
'colour' => $tab_colour,
|
|
'icon' => $config['sensor_types'][$result['sensor_class']]['icon'],
|
|
'data' => [
|
|
'| ' . escape_html($device_name),
|
|
$descr
|
|
]
|
|
];
|
|
}
|
|
|
|
$search_results['sensors'] = [ 'descr' => 'Sensors found', 'results' => $sensor_search_results ];
|
|
|
|
// EOF
|