Skip to content

Commit

Permalink
Added support for Himoinsa gensets status state sensors (librenms#13456)
Browse files Browse the repository at this point in the history
* Fix missing mib_dir in definition

* Added state sensors

* snmprec data

* json data

* delete unused snmprec

* License and Author

* remove unused json data

* Fix style issues

* Fix more style issues coz im blind

* Fix more style issues coz im blind last

* Refactored

* Why do we loop?

* Fix style issues

* Update polling

* Refactor to use methods

* Fix a pair of style issues

* Updated test files

* Convert to yaml

* Wrong description on Mode

* Added another state + fixed some indexes

* Dunno what happened

* Fix for phpstan level 6

* Fix forstyleci

Co-authored-by: Tony Murray <murraytony@gmail.com>
  • Loading branch information
TheGreatDoc and murrant committed Nov 26, 2021
1 parent 364fa54 commit 82d008c
Show file tree
Hide file tree
Showing 7 changed files with 765 additions and 165 deletions.
131 changes: 131 additions & 0 deletions LibreNMS/OS/HimoinsaGensets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
/**
* HimoinsaGensets.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2021 Daniel Baeza & Tony Murray
* @author TheGreatDoc <doctoruve@gmail.com> & murrant <murraytony@gmail.com>
*/

namespace LibreNMS\OS;

use LibreNMS\OS;

class HimoinsaGensets extends OS
{
/* state parsing functions
CEC7 (a.k.a CEA7CC2) bitmap status ( R G B T Mn Au Al)
statusConm.0
R = Mains commutator closed
G = Gen commutator closed
B = Blocked mode
T = Test mode
Mn = Manual mode
Au = Auto mode
Al = Active commutator alarm
In LibreNMS it equals to 3 state sensors:
Closed commutator: Mains or Genset (what commutator is closed, so where the power comes from)
Genset Mode: Block, Test, Manual, Auto (the 4 modes of the genset)
Alarm: Yes or No (If there is a commutator alarm)
Example:
Value = 66
Value binary = 1000010
States equals to:
- Alarm: No active alarm
- Genset Mode: Auto
- Closed commutator: Mains
CEA7 / CEM7 (CEA7 is a combination of CEC7 + CEM7 in a single Central) bitmap status (R G Al Bt B T Mn Au P A)
status.0
R = Mains commutator closed
G = Gen commutator closed
Al = Active Alarm
Bt = Transfer Pump
B = Blocked mode
T = Test mode
Mn = Manual mode
Au = Auto mode
P = Motor Stopped
A = Motor Running
*/

/**
* @param int $value
*/
public static function motorStatus($value): int
{
return ($value & 1) | ($value & 2);
}

/**
* @param int $value
*/
public static function modeStatus($value): int
{
return ($value & 4) | ($value & 8) | ($value & 16) | ($value & 32);
}

/**
* @param int $value
*/
public static function alarmStatus($value): int
{
return $value & 128;
}

/**
* @param int $value
*/
public static function transferPumpStatus($value): int
{
return $value & 64;
}

/**
* @param int $value
*/
public static function commStatus($value): int
{
return ($value & 512) | ($value & 256);
}

/**
* @param int $value
*/
public static function cec7CommStatus($value): int
{
return ($value & 32) | ($value & 64);
}

/**
* @param int $value
*/
public static function cec7CommAlarmStatus($value): int
{
return $value & 1;
}

/**
* @param int $value
*/
public static function cec7ModeStatus($value): int
{
return ($value & 2) | ($value & 4) | ($value & 8) | ($value & 16);
}
}
99 changes: 99 additions & 0 deletions includes/definitions/discovery/himoinsa-gensets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,102 @@ modules:
descr: Fuel level
divisor: 10
group: Genset
state:
data:
-
oid: status
num_oid: '.1.3.6.1.4.1.41809.1.46.{{ $index }}'
user_func: \LibreNMS\OS\HimoinsaGensets::motorStatus
index: motor
descr: Motor
group: 'CEA7/CEM7'
state_name: HimoinsaMotorStatus
states:
- {value: 1, generic: 2, graph: 0, descr: Running}
- {value: 2, generic: 0, graph: 0, descr: Stopped}
- {value: 0, generic: 3, graph: 0, descr: Unknown}
-
oid: status
num_oid: '.1.3.6.1.4.1.41809.1.46.{{ $index }}'
user_func: \LibreNMS\OS\HimoinsaGensets::modeStatus
index: mode
descr: Mode
group: 'CEA7/CEM7'
state_name: HimoinsaModeStatus
states:
- {value: 4, generic: 0, graph: 0, descr: Auto}
- {value: 8, generic: 2, graph: 0, descr: Manual}
- {value: 16, generic: 1, graph: 0, descr: Test}
- {value: 32, generic: 2, graph: 0, descr: Blocked}
- {value: 0, generic: 3, graph: 0, descr: Unknown}
-
oid: status
num_oid: '.1.3.6.1.4.1.41809.1.46.{{ $index }}'
user_func: \LibreNMS\OS\HimoinsaGensets::transferPumpStatus
index: transfer_pump
descr: Transfer Pump
group: 'CEA7/CEM7'
state_name: HimoinsaTransferPumpStatus
states:
- {value: 0, generic: 0, graph: 0, descr: Off}
- {value: 64, generic: 1, graph: 0, descr: On}
-
oid: status
num_oid: '.1.3.6.1.4.1.41809.1.46.{{ $index }}'
user_func: \LibreNMS\OS\HimoinsaGensets::alarmStatus
index: alarm
descr: Alarm
group: 'CEA7/CEM7'
state_name: HimoinsaAlarmStatus
states:
- {value: 0, generic: 0, graph: 0, descr: No Alarm}
- {value: 128, generic: 2, graph: 0, descr: Alarm}
-
oid: status
num_oid: '.1.3.6.1.4.1.41809.1.46.{{ $index }}'
user_func: \LibreNMS\OS\HimoinsaGensets::commStatus
index: comm
descr: Commutator Mode
group: 'CEA7/CEM7'
state_name: HimoinsaCommStatus
states:
- {value: 512, generic: 2, graph: 0, descr: Genset}
- {value: 256, generic: 0, graph: 0, descr: Mains}
- {value: 0, generic: 3, graph: 0, descr: Unknown}
-
oid: statusConm
num_oid: '.1.3.6.1.4.1.41809.1.55.1.28.{{ $index }}'
user_func: \LibreNMS\OS\HimoinsaGensets::cec7CommStatus
index: 'cec7_comm.{{ $index }}'
descr: Commutator Mode
group: 'CEC7'
state_name: HimoinsaCec7CommStatus
states:
- {value: 32, generic: 2, graph: 0, descr: Genset}
- {value: 64, generic: 0, graph: 0, descr: Mains}
- {value: 0, generic: 3, graph: 0, descr: Unknown}
-
oid: statusConm
num_oid: '.1.3.6.1.4.1.41809.1.55.1.28.{{ $index }}'
user_func: \LibreNMS\OS\HimoinsaGensets::cec7CommAlarmStatus
index: 'cec7_alarm.{{ $index }}'
descr: Alarm
group: 'CEC7'
state_name: HimoinsaCec7AlarmStatus
states:
- {value: 0, generic: 0, graph: 0, descr: No Alarm}
- {value: 1, generic: 2, graph: 0, descr: Alarm}
-
oid: statusConm
num_oid: '.1.3.6.1.4.1.41809.1.55.1.28.{{ $index }}'
user_func: \LibreNMS\OS\HimoinsaGensets::cec7ModeStatus
index: 'cec7_mode.{{ $index }}'
descr: Mode
group: 'CEC7'
state_name: HimoinsaCec7ModeStatus
states:
- {value: 2, generic: 0, graph: 0, descr: Auto}
- {value: 4, generic: 2, graph: 0, descr: Manual}
- {value: 8, generic: 1, graph: 0, descr: Test}
- {value: 16, generic: 2, graph: 0, descr: Blocked}
- {value: 0, generic: 3, graph: 0, descr: Unknown}
1 change: 1 addition & 0 deletions includes/definitions/himoinsa-gensets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ text: 'Himoinsa Generator Sets'
type: power
icon: himoinsa
group: himoinsa
mib_dir: himoinsa
over:
- { graph: device_uptime, text: 'Device Uptime' }
discovery:
Expand Down
3 changes: 3 additions & 0 deletions misc/discovery_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@
"string"
]
},
"user_func": {
"type": "string"
},
"states": {
"type": "array",
"items": {
Expand Down
Loading

0 comments on commit 82d008c

Please sign in to comment.