Skip to content

Commit

Permalink
librenms-alerts, librenms-health: Compact output is the new default a…
Browse files Browse the repository at this point in the history
…nd shows non-OK only
  • Loading branch information
markuslf committed Sep 4, 2024
1 parent 135b535 commit d816a09
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Monitoring Plugins:
* about-me: Add Mastodon detection
* about-me: Add Moodle detection
* disk-io: Re-add support for Windows after last rewrite
* librenms-alerts, librenms-health: Compact output is the new default and shows non-OK only
* nextcloud-security-scan: Handle error on https://scan.nextcloud.com/
* openstack-nova-list: No more need for keystoneauth and keystoneclient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
"librenms_alerts_always_ok": false,
"librenms_alerts_defaults_file": "/var/spool/icinga2/.my.cnf",
"librenms_alerts_defaults_group": "client",
"librenms_alerts_lengthy": true,
"librenms_alerts_lengthy": false,
"librenms_alerts_severity": "crit",
"librenms_alerts_timeout": 3
},
Expand Down Expand Up @@ -295,7 +295,7 @@
"librenms_alerts_windows_always_ok": false,
"librenms_alerts_windows_defaults_file": "/var/spool/icinga2/.my.cnf",
"librenms_alerts_windows_defaults_group": "client",
"librenms_alerts_windows_lengthy": true,
"librenms_alerts_windows_lengthy": false,
"librenms_alerts_windows_severity": "crit",
"librenms_alerts_windows_timeout": 3
},
Expand Down Expand Up @@ -572,7 +572,7 @@
"7": {
"varname": "librenms_alerts_lengthy",
"caption": "LibreNMS Alerts: Lengthy?",
"description": "Extended reporting.",
"description": "Extended reporting. ",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean",
"format": null,
"settings": {},
Expand Down Expand Up @@ -671,7 +671,7 @@
"16": {
"varname": "librenms_alerts_windows_lengthy",
"caption": "LibreNMS Alerts: Lengthy?",
"description": "Extended reporting.",
"description": "Extended reporting. ",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean",
"format": null,
"settings": {},
Expand Down
30 changes: 19 additions & 11 deletions check-plugins/librenms-alerts/librenms-alerts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2024032905'
__version__ = '2024090301'

DESCRIPTION = """This check warns of unacknowledged alerts in LibreNMS and
reports the most recent alert for each device (only for those
Expand All @@ -39,7 +39,7 @@ DESCRIPTION = """This check warns of unacknowledged alerts in LibreNMS and

DEFAULT_DEFAULTS_FILE = '/var/spool/icinga2/.my.cnf'
DEFAULT_DEFAULTS_GROUP = 'client'
DEFAULT_LENGTHY = True
DEFAULT_LENGTHY = False
DEFAULT_SERVERITY = 'crit'
DEFAULT_TIMEOUT = 3

Expand Down Expand Up @@ -117,7 +117,7 @@ def parse_args():

parser.add_argument(
'--lengthy',
help='Extended reporting.',
help='Extended reporting. ',
dest='LENGTHY',
action='store_true',
default=DEFAULT_LENGTHY,
Expand Down Expand Up @@ -213,6 +213,7 @@ def main():
data += args.DEVICE_TYPE
devices = lib.base.coe(lib.db_mysql.select(conn, sql, data))
lib.db_mysql.close(conn)
device_count = len(devices)

# enrich and analyse data
for i, device in enumerate(devices):
Expand All @@ -229,23 +230,30 @@ def main():
)
state = lib.base.get_worst(local_state, state)

# filter data if compact layout is choosen (just get everything that is not ok)
if not args.LENGTHY:
# brief data
devices = [device for device in devices if device['state'] != '[OK]']

# build the message
msg = 'Checked {} {}.'.format(
len(devices),
lib.txt.pluralize('device', len(devices)),
)
if state != STATE_OK:
msg += ' There {} {} {}.'.format(
if state == STATE_OK:
msg = 'Everything is ok. '
else:
msg = 'There {} {} {}. '.format(
lib.txt.pluralize('', alert_count, 'is,are'),
alert_count,
lib.txt.pluralize('alert', alert_count),
)
msg += 'Checked {} {}.'.format(
device_count,
lib.txt.pluralize('device', device_count),
)
msg += '\n\n'

perfdata += lib.base.get_perfdata('device_count', len(devices), None, None, None, 0, None) # pylint: disable=C0301
perfdata += lib.base.get_perfdata('device_count', device_count, None, None, None, 0, None) # pylint: disable=C0301
perfdata += lib.base.get_perfdata('alert_count', alert_count, None, None, None, 0, None) # pylint: disable=C0301

if len(devices) > 0:
if device_count > 0:
if not args.LENGTHY:
msg += lib.base.get_table(
devices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"librenms_health_always_ok": false,
"librenms_health_defaults_file": "/var/spool/icinga2/.my.cnf",
"librenms_health_defaults_group": "client",
"librenms_health_lengthy": true,
"librenms_health_lengthy": false,
"librenms_health_timeout": 3
},
"volatile": null,
Expand Down Expand Up @@ -278,7 +278,7 @@
"librenms_health_windows_always_ok": false,
"librenms_health_windows_defaults_file": "/var/spool/icinga2/.my.cnf",
"librenms_health_windows_defaults_group": "client",
"librenms_health_windows_lengthy": true,
"librenms_health_windows_lengthy": false,
"librenms_health_windows_timeout": 3
},
"volatile": null,
Expand Down Expand Up @@ -516,7 +516,7 @@
"7": {
"varname": "librenms_health_lengthy",
"caption": "LibreNMS Health: Lengthy?",
"description": "Extended reporting.",
"description": "Extended reporting. ",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean",
"format": null,
"settings": {},
Expand Down Expand Up @@ -602,7 +602,7 @@
"15": {
"varname": "librenms_health_windows_lengthy",
"caption": "LibreNMS Health: Lengthy?",
"description": "Extended reporting.",
"description": "Extended reporting. ",
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean",
"format": null,
"settings": {},
Expand Down
31 changes: 20 additions & 11 deletions check-plugins/librenms-health/librenms-health
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
STATE_UNKNOWN, STATE_WARN)

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2024032903'
__version__ = '2024090301'

DESCRIPTION = """This check plugin retrieves sensor information for each device
from a LibreNMS instance.
Expand All @@ -35,7 +35,7 @@ DESCRIPTION = """This check plugin retrieves sensor information for each device
DEFAULT_DEFAULTS_FILE = '/var/spool/icinga2/.my.cnf'
DEFAULT_DEFAULTS_GROUP = 'client'
DEFAULT_INSECURE = False
DEFAULT_LENGTHY = True
DEFAULT_LENGTHY = False
DEFAULT_NO_PROXY = False
DEFAULT_TIMEOUT = 3
DEFAULT_URL = 'http://localhost'
Expand Down Expand Up @@ -114,7 +114,7 @@ def parse_args():

parser.add_argument(
'--lengthy',
help='Extended reporting.',
help='Extended reporting. ',
dest='LENGTHY',
action='store_true',
default=DEFAULT_LENGTHY,
Expand Down Expand Up @@ -154,6 +154,7 @@ def main():
state = STATE_OK
perfdata = ''
alert_count = 0
sensors_count = 0

# fetch data
sql = '''
Expand Down Expand Up @@ -207,6 +208,7 @@ def main():
sql += ' ORDER BY d.hostname, s.sensor_class'
sensors = lib.base.coe(lib.db_mysql.select(conn, sql, data))
lib.db_mysql.close(conn)
sensors_count = len(sensors)

# enrich and analyse data
for i, sensor in enumerate(sensors):
Expand Down Expand Up @@ -234,23 +236,30 @@ def main():
)
state = lib.base.get_worst(local_state, state)

# filter data if compact layout is choosen (just get everything that is not ok)
if not args.LENGTHY:
# brief data
sensors = [sensor for sensor in sensors if sensor['state'] != '[OK]']

# build the message
msg = 'Checked {} {}.'.format(
len(sensors),
lib.txt.pluralize('sensor', len(sensors)),
)
if state != STATE_OK:
msg += ' There {} {} {}.'.format(
if state == STATE_OK:
msg = 'Everything is ok. '
else:
msg = 'There {} {} {}. '.format(
lib.txt.pluralize('', alert_count, 'is,are'),
alert_count,
lib.txt.pluralize('alert', alert_count),
)
msg += 'Checked {} {}.'.format(
sensors_count,
lib.txt.pluralize('sensor', sensors_count),
)
msg += '\n\n'

perfdata += lib.base.get_perfdata('sensor_count', len(sensors), None, None, None, 0, None) # pylint: disable=C0301
perfdata += lib.base.get_perfdata('sensor_count', sensors_count, None, None, None, 0, None) # pylint: disable=C0301
perfdata += lib.base.get_perfdata('alert_count', alert_count, None, None, None, 0, None) # pylint: disable=C0301

if len(sensors) > 0:
if sensors_count > 0:
if not args.LENGTHY:
msg += lib.base.get_table(
sensors,
Expand Down

0 comments on commit d816a09

Please sign in to comment.