Skip to content

Commit 0e7e7a6

Browse files
committed
feat(librenms-alerts,librenms-health): add device-type "management"
1 parent 4c79cf6 commit 0e7e7a6

File tree

7 files changed

+79
-71
lines changed

7 files changed

+79
-71
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Monitoring Plugins:
3838
* by-winrm: executes commands on remote Windows hosts by WinRM, supporting JEA (including the JEA endpoint via `--winrm-configuration-name`)
3939
* infomaniak-swiss-backup-devices: add `--ignore-customer`, `--ignore-name`, `--ignore-tag`, `--ignore-user` parameters to skip devices by regex
4040
* infomaniak-swiss-backup-products: add `--ignore-customer`, `--ignore-tag` parameters to skip products by regex
41+
* librenms-alerts: add device-type `management`
42+
* librenms-health: add device-type `management`
4143
* nextcloud-enterprise: provides information about an installed Nextcloud Enterprise subscription
4244
* procs: add `--lengthy` parameter for extended `--top` table output with all platform-specific memory fields
4345
* procs: add `--top` parameter to list the top N processes by CPU time and memory usage

check-plugins/librenms-alerts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ usage: librenms-alerts [-h] [-V] [--always-ok] [--defaults-file DEFAULTS_FILE]
3232
[--defaults-group DEFAULTS_GROUP]
3333
[--device-group DEVICE_GROUP]
3434
[--device-hostname DEVICE_HOSTNAME]
35-
[--device-type {appliance,collaboration,environment,firewall,loadbalancer,network,power,printer,server,storage,wireless,workstation}]
35+
[--device-type {appliance,collaboration,environment,firewall,loadbalancer,management,network,power,printer,server,storage,wireless,workstation}]
3636
[--lengthy] [--severity {warn,crit}]
3737
[--timeout TIMEOUT]
3838
@@ -63,7 +63,7 @@ options:
6363
Wildcards.
6464
--device-hostname DEVICE_HOSTNAME
6565
Filter by LibreNMS Hostname (repeating).
66-
--device-type {appliance,collaboration,environment,firewall,loadbalancer,network,power,printer,server,storage,wireless,workstation}
66+
--device-type {appliance,collaboration,environment,firewall,loadbalancer,management,network,power,printer,server,storage,wireless,workstation}
6767
Filter by LibreNMS Device Type (repeating).
6868
--lengthy Extended reporting.
6969
--severity {warn,crit}

check-plugins/librenms-alerts/icingaweb2-module-director/librenms-alerts.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@
182182
"format": "string",
183183
"allowed_roles": null
184184
},
185+
{
186+
"entry_name": "management",
187+
"entry_value": "Management",
188+
"format": "string",
189+
"allowed_roles": null
190+
},
185191
{
186192
"entry_name": "network",
187193
"entry_value": "Network",

check-plugins/librenms-alerts/librenms-alerts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
"""See the check's README for more details.
1212
"""
1313

14-
import argparse # pylint: disable=C0413
15-
import sys # pylint: disable=C0413
16-
17-
import lib.base # pylint: disable=C0413
18-
import lib.db_mysql # pylint: disable=C0413
19-
import lib.human # pylint: disable=C0413
20-
import lib.librenms # pylint: disable=C0413
21-
import lib.txt # pylint: disable=C0413
22-
from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
14+
import argparse
15+
import sys
16+
17+
import lib.base
18+
import lib.db_mysql
19+
import lib.human
20+
import lib.librenms
21+
import lib.txt
22+
from lib.globals import (STATE_CRIT, STATE_OK,
2323
STATE_UNKNOWN, STATE_WARN)
2424

2525
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
26-
__version__ = '2025100601'
26+
__version__ = '2026040801'
2727

2828
DESCRIPTION = """This check warns of unacknowledged alerts in LibreNMS and
2929
reports the most recent alert for each device (only for those
@@ -52,7 +52,7 @@ def parse_args():
5252
parser.add_argument(
5353
'-V', '--version',
5454
action='version',
55-
version='{0}: v{1} by {2}'.format('%(prog)s', __version__, __author__)
55+
version=f'%(prog)s: v{__version__} by {__author__}'
5656
)
5757

5858
parser.add_argument(
@@ -99,12 +99,13 @@ def parse_args():
9999
help='Filter by LibreNMS Device Type (repeating).',
100100
dest='DEVICE_TYPE',
101101
action='append',
102-
choices=[ # taken from the librenms source file misc/config_definitions.json
102+
choices=[ # taken from the librenms source file resources/definitions/config_definitions.json
103103
'appliance',
104104
'collaboration',
105105
'environment',
106106
'firewall',
107107
'loadbalancer',
108+
'management',
108109
'network',
109110
'power',
110111
'printer',
@@ -171,7 +172,7 @@ def main():
171172

172173
# fetch data
173174
sql = '''
174-
SELECT
175+
SELECT
175176
d.hardware,
176177
d.hostname,
177178
d.os,
@@ -203,14 +204,10 @@ def main():
203204
sql += ' AND dg.name LIKE %s '
204205
data.append(args.DEVICE_GROUP)
205206
if args.DEVICE_HOSTNAME:
206-
sql += ' AND d.hostname IN ({}) '.format(
207-
', '.join('%s' for d in args.DEVICE_HOSTNAME), # print "%s" for each argument
208-
)
207+
sql += f' AND d.hostname IN ({", ".join("%s" for _ in args.DEVICE_HOSTNAME)}) '
209208
data += args.DEVICE_HOSTNAME
210209
if args.DEVICE_TYPE:
211-
sql += ' AND d.type IN ({}) '.format(
212-
', '.join('%s' for d in args.DEVICE_TYPE), # print "%s" for each argument
213-
)
210+
sql += f' AND d.type IN ({", ".join("%s" for _ in args.DEVICE_TYPE)}) '
214211
data += args.DEVICE_TYPE
215212
devices = lib.base.coe(lib.db_mysql.select(conn, sql, data))
216213
lib.db_mysql.close(conn)
@@ -240,19 +237,21 @@ def main():
240237
if state == STATE_OK:
241238
msg = 'Everything is ok. '
242239
else:
243-
msg = 'There {} {} {}. '.format(
244-
lib.txt.pluralize('', alert_count, 'is,are'),
245-
alert_count,
246-
lib.txt.pluralize('alert', alert_count),
247-
)
248-
msg += 'Checked {} {}.'.format(
249-
device_count,
250-
lib.txt.pluralize('device', device_count),
251-
)
240+
msg = f'There {lib.txt.pluralize("", alert_count, "is,are")} ' \
241+
f'{alert_count} {lib.txt.pluralize("alert", alert_count)}. '
242+
msg += f'Checked {device_count} {lib.txt.pluralize("device", device_count)}.'
252243
msg += '\n\n'
253244

254-
perfdata += lib.base.get_perfdata('device_count', device_count, None, None, None, 0, None) # pylint: disable=C0301
255-
perfdata += lib.base.get_perfdata('alert_count', alert_count, None, None, None, 0, None) # pylint: disable=C0301
245+
perfdata += lib.base.get_perfdata(
246+
'device_count',
247+
device_count,
248+
_min=0,
249+
)
250+
perfdata += lib.base.get_perfdata(
251+
'alert_count',
252+
alert_count,
253+
_min=0,
254+
)
256255

257256
if device_count > 0:
258257
if not args.LENGTHY:
@@ -305,5 +304,5 @@ def main():
305304
if __name__ == '__main__':
306305
try:
307306
main()
308-
except Exception: # pylint: disable=W0703
307+
except Exception:
309308
lib.base.cu()

check-plugins/librenms-health/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ usage: librenms-health [-h] [-V] [--always-ok] [--defaults-file DEFAULTS_FILE]
3232
[--defaults-group DEFAULTS_GROUP]
3333
[--device-group DEVICE_GROUP]
3434
[--device-hostname DEVICE_HOSTNAME]
35-
[--device-type {appliance,collaboration,environment,firewall,loadbalancer,network,power,printer,server,storage,wireless,workstation}]
35+
[--device-type {appliance,collaboration,environment,firewall,loadbalancer,management,network,power,printer,server,storage,wireless,workstation}]
3636
[--lengthy] [--timeout TIMEOUT]
3737
3838
This check plugin retrieves sensor information for each device from a LibreNMS
@@ -58,7 +58,7 @@ options:
5858
Wildcards.
5959
--device-hostname DEVICE_HOSTNAME
6060
Filter by LibreNMS Hostname (repeating).
61-
--device-type {appliance,collaboration,environment,firewall,loadbalancer,network,power,printer,server,storage,wireless,workstation}
61+
--device-type {appliance,collaboration,environment,firewall,loadbalancer,management,network,power,printer,server,storage,wireless,workstation}
6262
Filter by LibreNMS Device Type (repeating).
6363
--lengthy Extended reporting.
6464
--timeout TIMEOUT Network timeout in seconds. Default: 3 (seconds)

check-plugins/librenms-health/icingaweb2-module-director/librenms-health.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@
173173
"format": "string",
174174
"allowed_roles": null
175175
},
176+
{
177+
"entry_name": "management",
178+
"entry_value": "Management",
179+
"format": "string",
180+
"allowed_roles": null
181+
},
176182
{
177183
"entry_name": "network",
178184
"entry_value": "Network",

check-plugins/librenms-health/librenms-health

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
"""See the check's README for more details.
1212
"""
1313

14-
import argparse # pylint: disable=C0413
15-
import sys # pylint: disable=C0413
16-
17-
import lib.base # pylint: disable=C0413
18-
import lib.db_mysql # pylint: disable=C0413
19-
import lib.human # pylint: disable=C0413
20-
import lib.librenms # pylint: disable=C0413
21-
import lib.time # pylint: disable=C0413
22-
from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
14+
import argparse
15+
import sys
16+
17+
import lib.base
18+
import lib.db_mysql
19+
import lib.human
20+
import lib.librenms
21+
import lib.time
22+
from lib.globals import (STATE_CRIT, STATE_OK,
2323
STATE_UNKNOWN, STATE_WARN)
2424

2525
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
26-
__version__ = '2025100601'
26+
__version__ = '2026040801'
2727

2828
DESCRIPTION = """This check plugin retrieves sensor information for each device
2929
from a LibreNMS instance.
@@ -49,7 +49,7 @@ def parse_args():
4949
parser.add_argument(
5050
'-V', '--version',
5151
action='version',
52-
version='%(prog)s: v{} by {}'.format(__version__, __author__)
52+
version=f'%(prog)s: v{__version__} by {__author__}'
5353
)
5454

5555
parser.add_argument(
@@ -96,12 +96,13 @@ def parse_args():
9696
help='Filter by LibreNMS Device Type (repeating).',
9797
dest='DEVICE_TYPE',
9898
action='append',
99-
choices=[ # taken from the librenms source file misc/config_definitions.json
99+
choices=[ # taken from the librenms source file resources/definitions/config_definitions.json
100100
'appliance',
101101
'collaboration',
102102
'environment',
103103
'firewall',
104104
'loadbalancer',
105+
'management',
105106
'network',
106107
'power',
107108
'printer',
@@ -159,7 +160,7 @@ def main():
159160

160161
# fetch data
161162
sql = '''
162-
SELECT
163+
SELECT
163164
d.hostname,
164165
d.sysName,
165166
d.sysDescr,
@@ -197,14 +198,10 @@ def main():
197198
sql += ' AND dg.name LIKE %s '
198199
data.append(args.DEVICE_GROUP)
199200
if args.DEVICE_HOSTNAME:
200-
sql += ' AND d.hostname IN ({}) '.format(
201-
', '.join('%s' for d in args.DEVICE_HOSTNAME), # print "%s" for each argument
202-
)
201+
sql += f' AND d.hostname IN ({", ".join("%s" for _ in args.DEVICE_HOSTNAME)}) '
203202
data += args.DEVICE_HOSTNAME
204203
if args.DEVICE_TYPE:
205-
sql += ' AND d.type IN ({}) '.format(
206-
', '.join('%s' for d in args.DEVICE_TYPE), # print "%s" for each argument
207-
)
204+
sql += f' AND d.type IN ({", ".join("%s" for _ in args.DEVICE_TYPE)}) '
208205
data += args.DEVICE_TYPE
209206
sql += ' ORDER BY d.hostname, s.sensor_class'
210207
sensors = lib.base.coe(lib.db_mysql.select(conn, sql, data))
@@ -218,11 +215,7 @@ def main():
218215
if sensor['sensor_class'] == 'state':
219216
sensors[i]['sensor_current'] = sensor['state_descr']
220217
if all([sensor['sensor_limit_low'], sensor['sensor_limit']]):
221-
sensor['sensor_current'] = '{} ({}..{})'.format(
222-
sensor['sensor_current'],
223-
sensor['sensor_limit_low'],
224-
sensor['sensor_limit'],
225-
)
218+
sensor['sensor_current'] = f'{sensor["sensor_current"]} ({sensor["sensor_limit_low"]}..{sensor["sensor_limit"]})'
226219
if sensor['lastupdate']:
227220
delta = lib.time.now(as_type='datetime') - sensor['lastupdate']
228221
sensor['lastupdate'] = lib.human.seconds2human(delta.total_seconds())
@@ -246,19 +239,21 @@ def main():
246239
if state == STATE_OK:
247240
msg = 'Everything is ok. '
248241
else:
249-
msg = 'There {} {} {}. '.format(
250-
lib.txt.pluralize('', alert_count, 'is,are'),
251-
alert_count,
252-
lib.txt.pluralize('alert', alert_count),
253-
)
254-
msg += 'Checked {} {}.'.format(
255-
sensors_count,
256-
lib.txt.pluralize('sensor', sensors_count),
257-
)
242+
msg = f'There {lib.txt.pluralize("", alert_count, "is,are")} ' \
243+
f'{alert_count} {lib.txt.pluralize("alert", alert_count)}. '
244+
msg += f'Checked {sensors_count} {lib.txt.pluralize("sensor", sensors_count)}.'
258245
msg += '\n\n'
259246

260-
perfdata += lib.base.get_perfdata('sensor_count', sensors_count, None, None, None, 0, None) # pylint: disable=C0301
261-
perfdata += lib.base.get_perfdata('alert_count', alert_count, None, None, None, 0, None) # pylint: disable=C0301
247+
perfdata += lib.base.get_perfdata(
248+
'sensor_count',
249+
sensors_count,
250+
_min=0,
251+
)
252+
perfdata += lib.base.get_perfdata(
253+
'alert_count',
254+
alert_count,
255+
_min=0,
256+
)
262257

263258
if sensors_count > 0:
264259
if not args.LENGTHY:
@@ -313,5 +308,5 @@ def main():
313308
if __name__ == '__main__':
314309
try:
315310
main()
316-
except Exception: # pylint: disable=W0703
311+
except Exception:
317312
lib.base.cu()

0 commit comments

Comments
 (0)