Skip to content

Commit ccafb94

Browse files
committed
fix(librenms): treat WORSE, BETTER and CHANGED as open alert states in get_state()
LibreNMS encodes the alert lifecycle in alerts.state with six values (CLEAR, ACTIVE, ACKNOWLEDGED, WORSE, BETTER, CHANGED). Only ACTIVE was mapped to WARN/CRIT, so open alerts in the transitional states 3/4/5 were silently reported as OK. Also accept 3, 4 and 5, matching the LibreNMS "notifiable alert" definition used by the alerter itself.
1 parent ff24fa9 commit ccafb94

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11-
tbd
11+
### Fixed
12+
13+
* librenms.py: `get_state()` now also maps the LibreNMS alert states `WORSE` (3), `BETTER` (4) and `CHANGED` (5) to WARN/CRIT. Previously only `ACTIVE` (1) was treated as an alerting state, so open alerts in any of those three states were silently reported as OK. `WORSE` and `BETTER` exist in LibreNMS since 1.54 (July 2019); `CHANGED` was added in LibreNMS 25.2.0 (February 2025) and is now triggered whenever the alert `diff` detects a change
1214

1315

1416
## [v3.4.0] - 2026-04-22

librenms.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
needed by LibreNMS check plugins."""
1313

1414
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
15-
__version__ = '2025042001'
15+
__version__ = '2026042401'
1616

1717
from . import (
1818
base, # pylint: disable=C0413
@@ -124,12 +124,17 @@ def get_state(librestate, severity='crit'):
124124
"""
125125
Translate LibreNMS service state to a Nagios-compatible state.
126126
127-
LibreNMS returns a custom service state where:
128-
- 0 = OK
129-
- 1 = Alert
130-
- 2 = Acknowledged
127+
LibreNMS encodes the alert lifecycle in `alerts.state` (see
128+
`LibreNMS/Enum/AlertState.php`):
129+
- 0 = CLEAR / RECOVERED
130+
- 1 = ACTIVE
131+
- 2 = ACKNOWLEDGED
132+
- 3 = WORSE
133+
- 4 = BETTER
134+
- 5 = CHANGED
131135
132-
This function maps these LibreNMS states to Nagios exit codes.
136+
ACTIVE, WORSE, BETTER and CHANGED all represent an open, notifiable
137+
alert, so they map to WARN/CRIT. ACKNOWLEDGED and CLEAR map to OK.
133138
134139
### Parameters
135140
- **librestate** (`int`):
@@ -154,8 +159,10 @@ def get_state(librestate, severity='crit'):
154159
1
155160
>>> get_state(1, severity='crit')
156161
2
162+
>>> get_state(3, severity='crit')
163+
2
157164
"""
158165

159-
if librestate != 1:
166+
if librestate not in (1, 3, 4, 5):
160167
return STATE_OK
161168
return STATE_CRIT if severity == 'crit' else STATE_WARN

0 commit comments

Comments
 (0)