mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Added support Entity State polling (#7625)
* Entity state sensors?? * feature: Entity State polling Display entity state on the Inventory page. Allows for alerting based on states. * fix empty last changed, timezones, alarm parsing, and db updates * do not display unavailable alarms (80) add tooltip with state value * remove debug * Entity state sensors?? * feature: Entity State polling Display entity state on the Inventory page. Allows for alerting based on states. * fix empty last changed, timezones, alarm parsing, and db updates * do not display unavailable alarms (80) add tooltip with state value * remove debug * Use a discovery module and only fetch the rest of the data if entStateLastChanged is updated. * A little more efficient sql use in the case nothing has changed. * disabled by default, add to docs. * moved schema file to 220.sql
This commit is contained in:
committed by
Neil Lathwood
parent
4bb722a7ca
commit
a21a3fb2b6
@@ -1432,3 +1432,95 @@ function return_number($value)
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function get_units_from_sensor($sensor)
|
||||
{
|
||||
switch ($sensor['sensor_class']) {
|
||||
case 'airflow':
|
||||
return 'cfm';
|
||||
case 'current':
|
||||
return 'A';
|
||||
case 'dbm':
|
||||
case 'signal':
|
||||
return 'dBm';
|
||||
case 'fanspeed':
|
||||
return 'rpm';
|
||||
case 'frequency':
|
||||
return 'Hz';
|
||||
case 'charge':
|
||||
case 'humidity':
|
||||
case 'load':
|
||||
return '%';
|
||||
case 'cooling':
|
||||
case 'power':
|
||||
return 'W';
|
||||
case 'pressure':
|
||||
return 'kPa';
|
||||
case 'runtime':
|
||||
return 'Min';
|
||||
case 'snr':
|
||||
return 'SNR';
|
||||
case 'state':
|
||||
return '#';
|
||||
case 'temperature':
|
||||
return 'C';
|
||||
case 'voltage':
|
||||
return 'V';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function parse_entity_state($state, $value)
|
||||
{
|
||||
$data = array(
|
||||
'entStateOper' => array(
|
||||
1 => array('text' => 'unavailable', 'color' => 'default'),
|
||||
2 => array('text' => 'disabled', 'color' => 'danger'),
|
||||
3 => array('text' => 'enabled', 'color' => 'success'),
|
||||
4 => array('text' => 'testing', 'color' => 'warning'),
|
||||
),
|
||||
'entStateUsage' => array(
|
||||
1 => array('text' => 'unavailable', 'color' => 'default'),
|
||||
2 => array('text' => 'idle', 'color' => 'info'),
|
||||
3 => array('text' => 'active', 'color' => 'success'),
|
||||
4 => array('text' => 'busy', 'color' => 'success'),
|
||||
),
|
||||
'entStateStandby' => array(
|
||||
1 => array('text' => 'unavailable', 'color' => 'default'),
|
||||
2 => array('text' => 'hotStandby', 'color' => 'info'),
|
||||
3 => array('text' => 'coldStandby', 'color' => 'info'),
|
||||
4 => array('text' => 'providingService', 'color' => 'success'),
|
||||
),
|
||||
'entStateAdmin' => array(
|
||||
1 => array('text' => 'unknown', 'color' => 'default'),
|
||||
2 => array('text' => 'locked', 'color' => 'info'),
|
||||
3 => array('text' => 'shuttingDown', 'color' => 'warning'),
|
||||
4 => array('text' => 'unlocked', 'color' => 'success'),
|
||||
),
|
||||
);
|
||||
|
||||
if (isset($data[$state][$value])) {
|
||||
return $data[$state][$value];
|
||||
}
|
||||
|
||||
return array('text'=>'na', 'color'=>'default');
|
||||
}
|
||||
|
||||
function parse_entity_state_alarm($bits)
|
||||
{
|
||||
// not sure if this is correct
|
||||
$data = array(
|
||||
0 => array('text' => 'unavailable', 'color' => 'default'),
|
||||
1 => array('text' => 'underRepair', 'color' => 'warning'),
|
||||
2 => array('text' => 'critical', 'color' => 'danger'),
|
||||
3 => array('text' => 'major', 'color' => 'danger'),
|
||||
4 => array('text' => 'minor', 'color' => 'info'),
|
||||
5 => array('text' => 'warning', 'color' => 'warning'),
|
||||
6 => array('text' => 'indeterminate', 'color' => 'default'),
|
||||
);
|
||||
|
||||
$alarms = str_split(base_convert($bits, 16, 2));
|
||||
$active_alarms = array_filter($alarms);
|
||||
return array_intersect_key($data, $active_alarms);
|
||||
}
|
||||
|
Reference in New Issue
Block a user