diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ef87bcf..fd1edc50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/check-plugins/librenms-alerts/icingaweb2-module-director/librenms-alerts.json b/check-plugins/librenms-alerts/icingaweb2-module-director/librenms-alerts.json index 437897fb..803f7b61 100644 --- a/check-plugins/librenms-alerts/icingaweb2-module-director/librenms-alerts.json +++ b/check-plugins/librenms-alerts/icingaweb2-module-director/librenms-alerts.json @@ -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 }, @@ -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 }, @@ -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": {}, @@ -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": {}, diff --git a/check-plugins/librenms-alerts/librenms-alerts b/check-plugins/librenms-alerts/librenms-alerts index e706823c..189643ae 100755 --- a/check-plugins/librenms-alerts/librenms-alerts +++ b/check-plugins/librenms-alerts/librenms-alerts @@ -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 @@ -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 @@ -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, @@ -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): @@ -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, diff --git a/check-plugins/librenms-health/icingaweb2-module-director/librenms-health.json b/check-plugins/librenms-health/icingaweb2-module-director/librenms-health.json index e6bdceb5..c53a2f51 100644 --- a/check-plugins/librenms-health/icingaweb2-module-director/librenms-health.json +++ b/check-plugins/librenms-health/icingaweb2-module-director/librenms-health.json @@ -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, @@ -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, @@ -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": {}, @@ -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": {}, diff --git a/check-plugins/librenms-health/librenms-health b/check-plugins/librenms-health/librenms-health index 6316f06f..458e619a 100755 --- a/check-plugins/librenms-health/librenms-health +++ b/check-plugins/librenms-health/librenms-health @@ -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. @@ -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' @@ -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, @@ -154,6 +154,7 @@ def main(): state = STATE_OK perfdata = '' alert_count = 0 + sensors_count = 0 # fetch data sql = ''' @@ -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): @@ -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,