2008-11-28 12:59:33 +00:00
|
|
|
<?php
|
|
|
|
|
2019-06-23 00:29:12 -05:00
|
|
|
use LibreNMS\Config;
|
2018-09-24 02:07:00 -05:00
|
|
|
use LibreNMS\Util\Rewrite;
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function rewrite_location($location)
|
|
|
|
{
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
return \LibreNMS\Util\Rewrite::location($location);
|
2012-05-14 12:55:19 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function formatMac($mac)
|
|
|
|
{
|
2019-01-20 08:43:36 -06:00
|
|
|
return \LibreNMS\Util\Rewrite::readableMac($mac);
|
2009-09-18 09:11:52 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function rewrite_entity_descr($descr)
|
|
|
|
{
|
2015-07-13 20:10:26 +02:00
|
|
|
$descr = str_replace('Distributed Forwarding Card', 'DFC', $descr);
|
|
|
|
$descr = preg_replace('/7600 Series SPA Interface Processor-/', '7600 SIP-', $descr);
|
|
|
|
$descr = preg_replace('/Rev\.\ [0-9\.]+\ /', '', $descr);
|
|
|
|
$descr = preg_replace('/12000 Series Performance Route Processor/', '12000 PRP', $descr);
|
|
|
|
$descr = preg_replace('/^12000/', '', $descr);
|
|
|
|
$descr = preg_replace('/Gigabit Ethernet/', 'GigE', $descr);
|
|
|
|
$descr = preg_replace('/^ASR1000\ /', '', $descr);
|
|
|
|
$descr = str_replace('Routing Processor', 'RP', $descr);
|
|
|
|
$descr = str_replace('Route Processor', 'RP', $descr);
|
|
|
|
$descr = str_replace('Switching Processor', 'SP', $descr);
|
|
|
|
$descr = str_replace('Sub-Module', 'Module ', $descr);
|
|
|
|
$descr = str_replace('DFC Card', 'DFC', $descr);
|
|
|
|
$descr = str_replace('Centralized Forwarding Card', 'CFC', $descr);
|
|
|
|
$descr = str_replace('Power Supply Module', 'PSU ', $descr);
|
|
|
|
$descr = str_replace('/Voltage Sensor/', 'Voltage', $descr);
|
2016-01-14 20:50:08 +01:00
|
|
|
$descr = str_replace('Sensor', '', $descr);
|
2018-08-27 11:11:16 +02:00
|
|
|
$descr = str_replace('PMOD', 'PSU', $descr);
|
2015-07-13 20:10:26 +02:00
|
|
|
$descr = preg_replace('/^temperatures /', '', $descr);
|
|
|
|
$descr = preg_replace('/^voltages /', '', $descr);
|
2020-08-18 15:36:14 +02:00
|
|
|
$descr = str_replace('PowerSupply', 'PSU ', $descr);
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
return $descr;
|
2010-08-04 17:17:00 +00:00
|
|
|
}
|
2009-09-18 09:11:52 +00:00
|
|
|
|
2017-04-04 08:08:23 +01:00
|
|
|
/**
|
|
|
|
* Clean port values for html display
|
|
|
|
* Add label to the port array (usually one of ifAlias, ifName, ifDescr)
|
|
|
|
*
|
|
|
|
* @param array $interface
|
|
|
|
* @param null|array $device
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function cleanPort($interface, $device = null)
|
2016-08-28 12:32:58 -05:00
|
|
|
{
|
2016-10-15 20:45:18 +01:00
|
|
|
$interface['ifAlias'] = display($interface['ifAlias']);
|
2020-09-21 15:40:17 +02:00
|
|
|
$interface['ifName'] = display($interface['ifName']);
|
2017-04-04 08:08:23 +01:00
|
|
|
$interface['ifDescr'] = display($interface['ifDescr']);
|
2016-10-15 20:45:18 +01:00
|
|
|
|
2020-09-21 15:40:17 +02:00
|
|
|
if (! $device) {
|
2015-07-13 20:10:26 +02:00
|
|
|
$device = device_by_id_cache($interface['device_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$os = strtolower($device['os']);
|
2011-03-23 09:54:56 +00:00
|
|
|
|
2019-06-23 00:29:12 -05:00
|
|
|
if (Config::get("os.$os.ifname")) {
|
2015-07-13 20:10:26 +02:00
|
|
|
$interface['label'] = $interface['ifName'];
|
2011-04-19 21:54:43 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
if ($interface['ifName'] == '') {
|
|
|
|
$interface['label'] = $interface['ifDescr'];
|
|
|
|
}
|
2019-06-23 00:29:12 -05:00
|
|
|
} elseif (Config::get("os.$os.ifalias")) {
|
2015-07-13 20:10:26 +02:00
|
|
|
$interface['label'] = $interface['ifAlias'];
|
2016-08-28 12:32:58 -05:00
|
|
|
} else {
|
2015-07-13 20:10:26 +02:00
|
|
|
$interface['label'] = $interface['ifDescr'];
|
2019-06-23 00:29:12 -05:00
|
|
|
if (Config::get("os.$os.ifindex")) {
|
2020-09-21 15:40:17 +02:00
|
|
|
$interface['label'] = $interface['label'] . ' ' . $interface['ifIndex'];
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
2011-04-19 21:54:43 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
if ($device['os'] == 'speedtouch') {
|
2020-09-18 08:12:07 -05:00
|
|
|
[$interface['label']] = explode('thomson', $interface['label']);
|
2011-03-11 18:03:49 +00:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2019-06-23 00:29:12 -05:00
|
|
|
if (is_array(Config::get('rewrite_if'))) {
|
|
|
|
foreach (Config::get('rewrite_if') as $src => $val) {
|
2015-07-13 20:10:26 +02:00
|
|
|
if (stristr($interface['label'], $src)) {
|
|
|
|
$interface['label'] = $val;
|
|
|
|
}
|
|
|
|
}
|
2015-05-09 12:33:11 +00:00
|
|
|
}
|
|
|
|
|
2019-06-23 00:29:12 -05:00
|
|
|
if (is_array(Config::get('rewrite_if_regexp'))) {
|
|
|
|
foreach (Config::get('rewrite_if_regexp') as $reg => $val) {
|
2020-09-21 15:40:17 +02:00
|
|
|
if (preg_match($reg . 'i', $interface['label'])) {
|
|
|
|
$interface['label'] = preg_replace($reg . 'i', $val, $interface['label']);
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-09 12:33:11 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
return $interface;
|
2009-09-18 09:11:52 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function translate_ifOperStatus($ifOperStatus)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$translate_ifOperStatus = [
|
2017-07-03 15:38:58 -05:00
|
|
|
'1' => 'up',
|
|
|
|
'2' => 'down',
|
|
|
|
'3' => 'testing',
|
|
|
|
'4' => 'unknown',
|
|
|
|
'5' => 'dormant',
|
|
|
|
'6' => 'notPresent',
|
|
|
|
'7' => 'lowerLayerDown',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
2011-03-11 18:03:49 +00:00
|
|
|
|
2017-07-03 15:38:58 -05:00
|
|
|
if (isset($translate_ifOperStatus[$ifOperStatus])) {
|
|
|
|
$ifOperStatus = $translate_ifOperStatus[$ifOperStatus];
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $ifOperStatus;
|
2009-05-07 13:47:51 +00:00
|
|
|
}
|
2009-04-02 15:57:38 +00:00
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function translate_ifAdminStatus($ifAdminStatus)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$translate_ifAdminStatus = [
|
2017-07-03 15:38:58 -05:00
|
|
|
'1' => 'up',
|
|
|
|
'2' => 'down',
|
|
|
|
'3' => 'testing',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
2011-03-11 18:03:49 +00:00
|
|
|
|
2017-07-03 15:38:58 -05:00
|
|
|
if (isset($translate_ifAdminStatus[$ifAdminStatus])) {
|
2015-07-13 20:10:26 +02:00
|
|
|
$ifAdminStatus = $translate_ifAdminStatus[$ifAdminStatus];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ifAdminStatus;
|
2009-05-07 13:47:51 +00:00
|
|
|
}
|
2009-04-02 15:57:38 +00:00
|
|
|
|
2008-11-28 12:59:33 +00:00
|
|
|
// Specific rewrite functions
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function makeshortif($if)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$rewrite_shortif = [
|
2017-08-24 22:08:42 +02:00
|
|
|
'tengigabitethernet' => 'Te',
|
|
|
|
'ten-gigabitethernet' => 'Te',
|
|
|
|
'tengige' => 'Te',
|
|
|
|
'gigabitethernet' => 'Gi',
|
|
|
|
'fastethernet' => 'Fa',
|
|
|
|
'ethernet' => 'Et',
|
|
|
|
'serial' => 'Se',
|
|
|
|
'pos' => 'Pos',
|
|
|
|
'port-channel' => 'Po',
|
|
|
|
'atm' => 'Atm',
|
|
|
|
'null' => 'Null',
|
|
|
|
'loopback' => 'Lo',
|
|
|
|
'dialer' => 'Di',
|
|
|
|
'vlan' => 'Vlan',
|
|
|
|
'tunnel' => 'Tunnel',
|
|
|
|
'serviceinstance' => 'SI',
|
|
|
|
'dwdm' => 'DWDM',
|
2017-09-01 17:14:03 +01:00
|
|
|
'bundle-ether' => 'BE',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
$if = fixifName($if);
|
|
|
|
$if = strtolower($if);
|
|
|
|
$if = array_str_replace($rewrite_shortif, $if);
|
2020-09-21 15:40:17 +02:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
return $if;
|
2008-11-28 12:59:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function rewrite_ios_features($features)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$rewrite_ios_features = [
|
2017-07-03 15:38:58 -05:00
|
|
|
'PK9S' => 'IP w/SSH LAN Only',
|
|
|
|
'LANBASEK9' => 'Lan Base Crypto',
|
|
|
|
'LANBASE' => 'Lan Base',
|
|
|
|
'ADVENTERPRISEK9_IVS' => 'Advanced Enterprise Crypto Voice',
|
|
|
|
'ADVENTERPRISEK9' => 'Advanced Enterprise Crypto',
|
|
|
|
'ADVSECURITYK9' => 'Advanced Security Crypto',
|
|
|
|
'K91P' => 'Provider Crypto',
|
|
|
|
'K4P' => 'Provider Crypto',
|
|
|
|
'ADVIPSERVICESK9' => 'Adv IP Services Crypto',
|
|
|
|
'ADVIPSERVICES' => 'Adv IP Services',
|
|
|
|
'IK9P' => 'IP Plus Crypto',
|
|
|
|
'K9O3SY7' => 'IP ADSL FW IDS Plus IPSEC 3DES',
|
|
|
|
'SPSERVICESK9' => 'SP Services Crypto',
|
|
|
|
'PK9SV' => 'IP MPLS/IPV6 W/SSH + BGP',
|
|
|
|
'IS' => 'IP Plus',
|
|
|
|
'IPSERVICESK9' => 'IP Services Crypto',
|
|
|
|
'BROADBAND' => 'Broadband',
|
|
|
|
'IPBASE' => 'IP Base',
|
|
|
|
'IPSERVICE' => 'IP Services',
|
|
|
|
'P' => 'Service Provider',
|
|
|
|
'P11' => 'Broadband Router',
|
|
|
|
'G4P5' => 'NRP',
|
|
|
|
'JK9S' => 'Enterprise Plus Crypto',
|
|
|
|
'IK9S' => 'IP Plus Crypto',
|
|
|
|
'JK' => 'Enterprise Plus',
|
|
|
|
'I6Q4L2' => 'Layer 2',
|
|
|
|
'I6K2L2Q4' => 'Layer 2 Crypto',
|
|
|
|
'C3H2S' => 'Layer 2 SI/EI',
|
|
|
|
'_WAN' => ' + WAN',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
$type = array_preg_replace($rewrite_ios_features, $features);
|
2011-03-11 18:03:49 +00:00
|
|
|
|
2020-09-21 15:40:17 +02:00
|
|
|
return $features;
|
2009-03-23 17:32:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function rewrite_junose_hardware($hardware)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$rewrite_junose_hardware = [
|
2017-07-03 15:38:58 -05:00
|
|
|
'juniErx1400' => 'ERX-1400',
|
|
|
|
'juniErx700' => 'ERX-700',
|
|
|
|
'juniErx1440' => 'ERX-1440',
|
|
|
|
'juniErx705' => 'ERX-705',
|
|
|
|
'juniErx310' => 'ERX-310',
|
|
|
|
'juniE320' => 'E320',
|
|
|
|
'juniE120' => 'E120',
|
|
|
|
'juniSsx1400' => 'SSX-1400',
|
|
|
|
'juniSsx700' => 'SSX-700',
|
|
|
|
'juniSsx1440' => 'SSX-1440',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
$hardware = array_str_replace($rewrite_junose_hardware, $hardware);
|
2011-03-11 18:03:49 +00:00
|
|
|
|
2020-09-21 15:40:17 +02:00
|
|
|
return $hardware;
|
2010-02-13 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-01-31 09:09:56 +01:00
|
|
|
function rewrite_generic_hardware($hardware)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$rewrite_GenericHW = [
|
2017-07-03 15:38:58 -05:00
|
|
|
' Computer Corporation' => '',
|
|
|
|
' Corporation' => '',
|
|
|
|
' Inc.' => '',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
|
|
|
|
2017-01-31 09:09:56 +01:00
|
|
|
return array_str_replace($rewrite_GenericHW, $hardware);
|
|
|
|
}
|
2011-03-11 18:03:49 +00:00
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function fixiftype($type)
|
|
|
|
{
|
2018-09-24 02:07:00 -05:00
|
|
|
return Rewrite::normalizeIfType($type);
|
2008-11-28 12:59:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function fixifName($inf)
|
|
|
|
{
|
2018-09-24 02:07:00 -05:00
|
|
|
return Rewrite::normalizeIfName($inf);
|
2008-11-28 12:59:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function short_hrDeviceDescr($dev)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$rewrite_hrDevice = [
|
2017-07-03 15:38:58 -05:00
|
|
|
'GenuineIntel:' => '',
|
|
|
|
'AuthenticAMD:' => '',
|
|
|
|
'Intel(R)' => '',
|
|
|
|
'CPU' => '',
|
|
|
|
'(R)' => '',
|
|
|
|
' ' => ' ',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
$dev = array_str_replace($rewrite_hrDevice, $dev);
|
|
|
|
$dev = preg_replace('/\ +/', ' ', $dev);
|
|
|
|
$dev = trim($dev);
|
2011-03-11 18:03:49 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
return $dev;
|
2009-11-11 18:20:32 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function short_port_descr($desc)
|
|
|
|
{
|
2020-09-18 08:12:07 -05:00
|
|
|
[$desc] = explode('(', $desc);
|
|
|
|
[$desc] = explode('[', $desc);
|
|
|
|
[$desc] = explode('{', $desc);
|
|
|
|
[$desc] = explode('|', $desc);
|
|
|
|
[$desc] = explode('<', $desc);
|
2020-09-21 15:40:17 +02:00
|
|
|
$desc = trim($desc);
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
return $desc;
|
2009-07-31 10:53:54 +00:00
|
|
|
}
|
|
|
|
|
2008-11-28 12:59:33 +00:00
|
|
|
// Underlying rewrite functions
|
2016-08-28 12:32:58 -05:00
|
|
|
function array_str_replace($array, $string)
|
|
|
|
{
|
2015-07-13 20:10:26 +02:00
|
|
|
foreach ($array as $search => $replace) {
|
|
|
|
$string = str_replace($search, $replace, $string);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $string;
|
2011-03-11 18:03:49 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function array_preg_replace($array, $string)
|
|
|
|
{
|
2015-07-13 20:10:26 +02:00
|
|
|
foreach ($array as $search => $replace) {
|
|
|
|
$string = preg_replace($search, $replace, $string);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $string;
|
2011-03-11 18:03:49 +00:00
|
|
|
}
|
2008-11-28 12:59:33 +00:00
|
|
|
|
2016-08-28 12:32:58 -05:00
|
|
|
function rewrite_adslLineType($adslLineType)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$adslLineTypes = [
|
2015-07-13 20:10:26 +02:00
|
|
|
'noChannel' => 'No Channel',
|
|
|
|
'fastOnly' => 'Fastpath',
|
|
|
|
'interleavedOnly' => 'Interleaved',
|
|
|
|
'fastOrInterleaved' => 'Fast/Interleaved',
|
|
|
|
'fastAndInterleaved' => 'Fast+Interleaved',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
foreach ($adslLineTypes as $type => $text) {
|
|
|
|
if ($adslLineType == $type) {
|
|
|
|
$adslLineType = $text;
|
|
|
|
}
|
2011-03-30 12:07:08 +00:00
|
|
|
}
|
2011-03-30 16:28:24 +00:00
|
|
|
|
2020-09-21 15:40:17 +02:00
|
|
|
return $adslLineType;
|
2011-03-30 12:07:08 +00:00
|
|
|
}
|
2016-08-07 04:50:31 +03:00
|
|
|
|
2017-07-03 15:38:58 -05:00
|
|
|
function ipmiSensorName($hardwareId, $sensorIpmi)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$ipmiSensorsNames = [
|
|
|
|
"HP ProLiant BL460c G6" => [
|
2017-07-03 15:38:58 -05:00
|
|
|
"Temp 1" => "Ambient zone",
|
|
|
|
"Temp 2" => "CPU 1",
|
|
|
|
"Temp 3" => "CPU 2",
|
|
|
|
"Temp 4" => "Memory zone",
|
|
|
|
"Temp 5" => "Memory zone",
|
|
|
|
"Temp 6" => "Memory zone",
|
|
|
|
"Temp 7" => "System zone",
|
|
|
|
"Temp 8" => "System zone",
|
|
|
|
"Temp 9" => "System zone",
|
|
|
|
"Temp 10" => "Storage zone",
|
|
|
|
"Power Meter" => "Power usage",
|
2020-09-21 15:40:17 +02:00
|
|
|
],
|
|
|
|
"HP ProLiant BL460c G1" => [
|
2017-07-03 15:38:58 -05:00
|
|
|
"Temp 1" => "System zone",
|
|
|
|
"Temp 2" => "CPU 1 zone",
|
|
|
|
"Temp 3" => "CPU 1",
|
|
|
|
"Temp 4" => "CPU 1",
|
|
|
|
"Temp 5" => "CPU 2 zone",
|
|
|
|
"Temp 6" => "CPU 2",
|
|
|
|
"Temp 7" => "CPU 2",
|
|
|
|
"Temp 8" => "Memory zone",
|
|
|
|
"Temp 9" => "Ambient zone",
|
|
|
|
"Power Meter" => "Power usage",
|
2020-09-21 15:40:17 +02:00
|
|
|
],
|
|
|
|
];
|
2017-07-03 15:38:58 -05:00
|
|
|
|
|
|
|
if (isset($ipmiSensorsNames[$hardwareId], $ipmiSensorsNames[$hardwareId][$sensorIpmi])) {
|
|
|
|
return $ipmiSensorsNames[$hardwareId][$sensorIpmi];
|
|
|
|
}
|
2020-09-21 15:40:17 +02:00
|
|
|
|
2017-07-03 15:38:58 -05:00
|
|
|
return $sensorIpmi;
|
|
|
|
}
|
2016-12-07 15:24:56 +00:00
|
|
|
|
2017-01-07 00:09:41 +00:00
|
|
|
/**
|
|
|
|
* @param $descr
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function get_nagios_state($descr)
|
|
|
|
{
|
|
|
|
switch ($descr) {
|
|
|
|
case 'On':
|
|
|
|
case 'Okay':
|
|
|
|
case 'Ok':
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case 'Standby':
|
|
|
|
case 'Idle':
|
|
|
|
case 'Maintenance':
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case 'Under':
|
|
|
|
case 'Over':
|
|
|
|
return 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-02-09 07:59:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $state
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function apc_relay_state($state)
|
|
|
|
{
|
|
|
|
switch ($state) {
|
|
|
|
case 'immediateCloseEMS':
|
|
|
|
case 'immediateOnEMS':
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case 'immediateOpenEMS':
|
|
|
|
case 'immediateOffEMS':
|
|
|
|
return 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-19 20:22:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function return_number($value)
|
|
|
|
{
|
|
|
|
preg_match('/[\d\.\-]+/', $value, $temp_response);
|
2020-09-21 15:40:17 +02:00
|
|
|
if (! empty($temp_response[0])) {
|
2017-08-19 20:22:23 +01:00
|
|
|
$value = $temp_response[0];
|
|
|
|
}
|
2020-09-21 15:40:17 +02:00
|
|
|
|
2017-08-19 20:22:23 +01:00
|
|
|
return $value;
|
|
|
|
}
|
2017-12-02 14:23:56 -06:00
|
|
|
|
|
|
|
function parse_entity_state($state, $value)
|
|
|
|
{
|
2020-09-21 15:40:17 +02:00
|
|
|
$data = [
|
|
|
|
'entStateOper' => [
|
|
|
|
1 => ['text' => 'unavailable', 'color' => 'default'],
|
|
|
|
2 => ['text' => 'disabled', 'color' => 'danger'],
|
|
|
|
3 => ['text' => 'enabled', 'color' => 'success'],
|
|
|
|
4 => ['text' => 'testing', 'color' => 'warning'],
|
|
|
|
],
|
|
|
|
'entStateUsage' => [
|
|
|
|
1 => ['text' => 'unavailable', 'color' => 'default'],
|
|
|
|
2 => ['text' => 'idle', 'color' => 'info'],
|
|
|
|
3 => ['text' => 'active', 'color' => 'success'],
|
|
|
|
4 => ['text' => 'busy', 'color' => 'success'],
|
|
|
|
],
|
|
|
|
'entStateStandby' => [
|
|
|
|
1 => ['text' => 'unavailable', 'color' => 'default'],
|
|
|
|
2 => ['text' => 'hotStandby', 'color' => 'info'],
|
|
|
|
3 => ['text' => 'coldStandby', 'color' => 'info'],
|
|
|
|
4 => ['text' => 'providingService', 'color' => 'success'],
|
|
|
|
],
|
|
|
|
'entStateAdmin' => [
|
|
|
|
1 => ['text' => 'unknown', 'color' => 'default'],
|
|
|
|
2 => ['text' => 'locked', 'color' => 'info'],
|
|
|
|
3 => ['text' => 'shuttingDown', 'color' => 'warning'],
|
|
|
|
4 => ['text' => 'unlocked', 'color' => 'success'],
|
|
|
|
],
|
|
|
|
];
|
2017-12-02 14:23:56 -06:00
|
|
|
|
|
|
|
if (isset($data[$state][$value])) {
|
|
|
|
return $data[$state][$value];
|
|
|
|
}
|
|
|
|
|
2020-09-21 15:40:17 +02:00
|
|
|
return ['text'=>'na', 'color'=>'default'];
|
2017-12-02 14:23:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function parse_entity_state_alarm($bits)
|
|
|
|
{
|
|
|
|
// not sure if this is correct
|
2020-09-21 15:40:17 +02:00
|
|
|
$data = [
|
|
|
|
0 => ['text' => 'unavailable', 'color' => 'default'],
|
|
|
|
1 => ['text' => 'underRepair', 'color' => 'warning'],
|
|
|
|
2 => ['text' => 'critical', 'color' => 'danger'],
|
|
|
|
3 => ['text' => 'major', 'color' => 'danger'],
|
|
|
|
4 => ['text' => 'minor', 'color' => 'info'],
|
|
|
|
5 => ['text' => 'warning', 'color' => 'warning'],
|
|
|
|
6 => ['text' => 'indeterminate', 'color' => 'default'],
|
|
|
|
];
|
2017-12-02 14:23:56 -06:00
|
|
|
|
|
|
|
$alarms = str_split(base_convert($bits, 16, 2));
|
|
|
|
$active_alarms = array_filter($alarms);
|
2020-09-21 15:40:17 +02:00
|
|
|
|
2017-12-02 14:23:56 -06:00
|
|
|
return array_intersect_key($data, $active_alarms);
|
|
|
|
}
|