From 661749cdae40b8cdb0e31c1d6a8954803c6ef520 Mon Sep 17 00:00:00 2001 From: baechir Date: Thu, 20 Jun 2024 09:22:59 +0200 Subject: [PATCH 01/13] avelon-tickets: new plugin for avelon cloud tickets (alarms) --- check-plugins/avelon-tickets/.windows | 0 check-plugins/avelon-tickets/README.rst | 106 ++++++++ check-plugins/avelon-tickets/avelon-tickets | 240 ++++++++++++++++++ check-plugins/avelon-tickets/unit-test/run | 35 +++ .../avelon-tickets/unit-test/stdout/tickets | 119 +++++++++ 5 files changed, 500 insertions(+) create mode 100644 check-plugins/avelon-tickets/.windows create mode 100644 check-plugins/avelon-tickets/README.rst create mode 100755 check-plugins/avelon-tickets/avelon-tickets create mode 100755 check-plugins/avelon-tickets/unit-test/run create mode 100644 check-plugins/avelon-tickets/unit-test/stdout/tickets diff --git a/check-plugins/avelon-tickets/.windows b/check-plugins/avelon-tickets/.windows new file mode 100644 index 000000000..e69de29bb diff --git a/check-plugins/avelon-tickets/README.rst b/check-plugins/avelon-tickets/README.rst new file mode 100644 index 000000000..b0160d275 --- /dev/null +++ b/check-plugins/avelon-tickets/README.rst @@ -0,0 +1,106 @@ +Check avelon-tickets +==================== + +Overview +-------- + +Check if there are any pending tickets (alarms) on the Avelon Cloud and whether they are still open, acknowledged, or closed. + +What is the Avelon Cloud? +Avelon's products and services have been used in professional building operations for over 20 years. From commercial and industrial buildings to office buildings, airports, and railway facilities. The Avelon Cloud propels buildings into a professional era. Avelon takes care of security and maintenance throughout the entire usage period. With Avelon Cloud, operations become cheaper and more professional. + +Notes: +To use this monitoring plugin, you need to have a REST API license from Avelon. + +If you already have a license, log in to Avelon and click on Settings in the user menu at the top right. On the General tab, you will see a section called Public OAuth API Key. The Client ID and Client Secret displayed there are required to authenticate with our API (Monitoring-Plugin). + +Links: + +- [Avelon](https://avelon.com/) +- [Avelon Cloud Platform](https://avelon.cloud/) +- [Avelon Documentation](https://avelon.cloud/docs/) +- [API Documentation](https://avelon.cloud/swagger/swagger-ui/index.html?urls.primaryName=Public%20API#/) + + + +Fact Sheet +---------- + +.. csv-table:: + :widths: 30, 70 + + "Check Plugin Download", "https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/avelon-tickets" + "Check Interval Recommendation", "Once a minute" + "Can be called without parameters", "No" + "Compiled for", "Linux" + + +Help +---- + +.. code-block:: text + + usage: avelon-tickets [-h] [-V] [--always-ok] [--client-id] [--client-secret] + [--username] [--password] [--no-closed-ticket] + [--verify] [--proxies] [--timeout] [--test] + + The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts or warnings can be triggered. You + need a license to access the public API of the Avelon Cloud. + + options: + -h, --help show this help message and exit + -V, --version show program's version number and exit + --always-ok Always returns OK. + --client-id Avelon API client_id. + --client-secret Avelon API client_secret. + --username Avelon Cloud username. + --password Avelon Cloud password. + --no-closed-ticket The option allows viewing the closed alarms as well. Default: True + --verify This option explicitly allows to perform "insecure" SSL connections. Default: True + --proxies This option allows you to set specific proxies. For no proxy: {"http": None, "https": None}. Default: {} (System Proxy) + --timeout Network timeout in seconds. Default: 8 (seconds) + --test For unit tests. Needs "path-to-stdout-file,path-to-stderr-file,expected-retc". + + +Usage Examples +-------------- + +.. code-block:: bash + ./avelon-tickets --client-id "CLIENT_ID" --client-secret "CLIENT_SECRET" --username "USER" --password "PASSWORD" --no-closed-ticket "False" + +Output: + +.. code-block:: text + + There are open alarm ticket(s). + + ID ! Timestamp ! Type ! Message ! Status ! State + ---------+-------------------------------+-------+-------------------------------------------------------------------------+--------------+------------ + 13910313 ! 2024-06-13T07:43:53.000+02:00 ! ALARM ! ALARM: Abschaltend: 6102/5/33: Differenzdruck DP101 zu tief ! CLOSED ! + 13910314 ! 2024-06-13T07:43:54.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED ! + 13911337 ! 2024-06-13T13:40:39.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED ! + 13912010 ! 2024-06-13T17:37:13.000+02:00 ! ALARM ! ALARM: Störung: 6102/0/6: Vorlauftemperatur TT201 ! CLOSED ! + 13915922 ! 2024-06-14T23:58:36.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED ! + 13915923 ! 2024-06-14T23:58:36.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED ! + 13916766 ! 2024-06-15T07:19:26.000+02:00 ! ALARM ! ALARM: Störung: 6102/0/6: Vorlauftemperatur TT201 ! CLOSED ! + 13927572 ! 2024-06-18T19:46:56.000+02:00 ! ALARM ! ALARM: Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN ! [CRITICAL] + 13927573 ! 2024-06-18T19:46:56.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED ! [WARNING] + + +States +------ + +Needs to be added. + + +Perfdata / Metrics +------------------ + +Needs to be added. + + +Credits, License +---------------- + +* Authors: `Linuxfabrik GmbH, Zurich `_ +* License: The Unlicense, see `LICENSE file `_. diff --git a/check-plugins/avelon-tickets/avelon-tickets b/check-plugins/avelon-tickets/avelon-tickets new file mode 100755 index 000000000..0fea673f0 --- /dev/null +++ b/check-plugins/avelon-tickets/avelon-tickets @@ -0,0 +1,240 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8; py-indent-offset: 4 -*- +# +# Author: Linuxfabrik GmbH, Zurich, Switzerland +# Contact: info (at) linuxfabrik (dot) ch +# https://www.linuxfabrik.ch/ +# License: The Unlicense, see LICENSE file. + +# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.rst + +"""See the check's README for more details. +""" + +import argparse # pylint: disable=C0413 +import json # pylint: disable=C0413 +import re # pylint: disable=C0413 +import sys # pylint: disable=C0413 + +import lib.args # pylint: disable=C0413 +import lib.base # pylint: disable=C0413 +import lib.human # pylint: disable=C0413 +import lib.avelon # pylint: disable=C0413 +import lib.test # pylint: disable=C0413 +import lib.time # pylint: disable=C0413 +import lib.txt # pylint: disable=C0413 +from lib.globals import (STATE_OK, STATE_UNKNOWN, # pylint: disable=C0413 + STATE_WARN, STATE_CRIT) + +__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland' +__version__ = '2024033002' + +DESCRIPTION = """The current tickets (alerts) of your Avelon Cloud are being reviewed, + and depending on their status, critical alerts or warnings can be triggered. + You need a license to access the public API of the Avelon Cloud.""" + +DEFAULT_NO_CLOSED_TICKET = True +DEFAULT_VERIFY = True +DEFAULT_PROXIES = {} +DEFAULT_TIMEOUT = 8 + + + +def parse_args(): + """Parse command line arguments using argparse. + """ + parser = argparse.ArgumentParser(description=DESCRIPTION) + + parser.add_argument( + '-V', '--version', + action='version', + version='%(prog)s: v{} by {}'.format(__version__, __author__) + ) + + parser.add_argument( + '--always-ok', + help='Always returns OK.', + dest='ALWAYS_OK', + action='store_true', + default=False, + ) + + parser.add_argument( + '--client-id', + help='Avelon API client_id. ', + dest='CLIENT_ID', + required=True, + ) + + parser.add_argument( + '--client-secret', + help='Avelon API client_secret. ', + dest='CLIENT_SECRET', + required=True, + ) + + parser.add_argument( + '--username', + help='Avelon Cloud username. ', + dest='USERNAME', + required=True, + ) + + parser.add_argument( + '--password', + help='Avelon Cloud password.', + dest='PASSWORD', + required=True, + ) + + parser.add_argument( + '--no-closed-ticket', + help='The option allows viewing the closed alarms as well. ' + 'Default: %(default)s', + dest='NO_CLOSED_TICKET', + default=DEFAULT_NO_CLOSED_TICKET, + ) + + parser.add_argument( + '--verify', + help='This option explicitly allows to perform "insecure" SSL ' + 'connections. ' + 'Default: %(default)s', + dest='VERIFY', + default=DEFAULT_VERIFY, + ) + + parser.add_argument( + '--proxies', + help='This option allows you to set specific proxies. ' + 'For no proxy: {"http": None, "https": None}. ' + 'Default: %(default)s (System Proxy)', + dest='PROXIES', + action='store_true', + default=DEFAULT_PROXIES, + ) + + parser.add_argument( + '--timeout', + help='Network timeout in seconds. ' + 'Default: %(default)s (seconds)', + dest='TIMEOUT', + type=int, + default=DEFAULT_TIMEOUT, + ) + + parser.add_argument( + '--test', + help='For unit tests. ' + 'Needs "path-to-stdout-file,path-to-stderr-file,expected-retc".', + dest='TEST', + type=lib.args.csv, + ) + + return parser.parse_args() + + +def main(): + """The main function. + """ + + # parse the command line, exit with UNKNOWN if it fails + try: + args = parse_args() + except SystemExit: + sys.exit(STATE_UNKNOWN) + + # init some vars + msg = '' + state = STATE_OK + ticket_data = [] + + if args.TEST is None: + # get token + token = lib.avelon.get_token( + client_id=args.CLIENT_ID, + client_secret=args.CLIENT_SECRET, + username=args.USERNAME, + password=args.PASSWORD, + verify=args.VERIFY, + proxies=args.PROXIES, + timeout=args.TIMEOUT, + ) + + # get tickets + tickets = lib.avelon.get_tickets( + access_token=token['access_token'], + verify=args.VERIFY, + proxies=args.PROXIES, + timeout=args.TIMEOUT, + ) + else: + # do not call the command, put in test data + stdout, stderr, retc = lib.test.test(args.TEST) + tickets = json.loads(stdout) + + # analyze tickets + used_state = STATE_OK + locked_state = STATE_OK + + + for ticket in tickets: + state = lib.base.get_worst(state, used_state) + + if ticket['type'] == 'ALARM' and ticket['status'] == 'CLOSED': + locked_state = STATE_OK + if ticket['type'] == 'ALARM' and ticket['status'] == 'ACKNOWLEDGED': + locked_state = STATE_WARN + elif ticket['type'] == 'ALARM' and ticket['status'] == 'OPEN': + locked_state = STATE_CRIT + + state = lib.base.get_worst(state, locked_state) + ticket['state'] = lib.base.state2str(locked_state, prefix='') + + # Ticket filter + if args.NO_CLOSED_TICKET == 'True' and ticket['status'] != 'CLOSED': + ticket_data.append(ticket) + elif args.NO_CLOSED_TICKET == 'False': + ticket_data.append(ticket) + + if state == STATE_CRIT: + msg = 'There are open alarm ticket(s).\n\n' + msg + elif state == STATE_WARN: + msg = 'There are acknowledged alarm ticket(s).\n\n' + msg + else: + msg = 'Everything is ok.\n\n' + msg + + # build the message + if ticket_data: + keys = [ + 'id', + 'created', + 'type', + 'message', + 'status', + 'state', + ] + headers = [ + 'ID', + 'Timestamp', + 'Type', + 'Message', + 'Status', + 'State', + ] + + if ticket_data: + msg += lib.base.get_table( + sorted(ticket_data, key=lambda d: d['id']), + keys, + header=headers, + ) + + # over and out + lib.base.oao(msg, state, always_ok=args.ALWAYS_OK) + +if __name__ == '__main__': + try: + main() + except Exception: # pylint: disable=W0703 + lib.base.cu() diff --git a/check-plugins/avelon-tickets/unit-test/run b/check-plugins/avelon-tickets/unit-test/run new file mode 100755 index 000000000..72f139795 --- /dev/null +++ b/check-plugins/avelon-tickets/unit-test/run @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8; py-indent-offset: 4 -*- +# +# Author: Linuxfabrik GmbH, Zurich, Switzerland +# Contact: info (at) linuxfabrik (dot) ch +# https://www.linuxfabrik.ch/ +# License: The Unlicense, see LICENSE file. + +# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.rst + +import sys +sys.path.append("..") # Adds higher directory to python modules path. + + + +import unittest + +from lib.globals import STATE_OK, STATE_UNKNOWN, STATE_WARN, STATE_CRIT +import lib.base +import lib.shell + + +class TestCheck(unittest.TestCase): + + check = '../avelon-tickets' + + def test_if_check_runs_tickets(self): + stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --test=stdout/tickets,,')) + self.assertIn('ReadModel: ', stdout) + self.assertEqual(stderr, '') + self.assertEqual(retc, STATE_OK) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/check-plugins/avelon-tickets/unit-test/stdout/tickets b/check-plugins/avelon-tickets/unit-test/stdout/tickets new file mode 100644 index 000000000..5cdf90249 --- /dev/null +++ b/check-plugins/avelon-tickets/unit-test/stdout/tickets @@ -0,0 +1,119 @@ +[ + { + "id": 13927572, + "type": "ALARM", + "message": "ALARM: Abschaltend: 6102/5/22: Durchfluss Notk\u00fchlung FQ201 St\u00f6rung", + "status": "OPEN", + "created": "2024-06-18T19:46:56.000+02:00", + "modified": "2024-06-18T19:47:33.000+02:00", + "resolved": null, + "closable": false, + "dataPointId": 1389273, + "deviceId": 10149, + "recurrences": 6 + }, + { + "id": 13927573, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/0: Anlage Zustand St\u00f6rung", + "status": "ACKNOWLEDGED", + "created": "2024-06-18T19:46:56.000+02:00", + "modified": "2024-06-19T14:43:35.000+02:00", + "resolved": null, + "closable": false, + "dataPointId": 1389326, + "deviceId": 10149, + "recurrences": 6 + }, + { + "id": 13915922, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notk\u00fchlung", + "status": "CLOSED", + "created": "2024-06-14T23:58:36.000+02:00", + "modified": "2024-06-17T08:04:46.000+02:00", + "resolved": "2024-06-17T08:04:46.000+02:00", + "closable": false, + "dataPointId": 1389359, + "deviceId": 10149, + "recurrences": 55 + }, + { + "id": 13915923, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/0: Anlage Zustand St\u00f6rung", + "status": "CLOSED", + "created": "2024-06-14T23:58:36.000+02:00", + "modified": "2024-06-17T08:04:34.000+02:00", + "resolved": "2024-06-17T08:04:35.000+02:00", + "closable": false, + "dataPointId": 1389326, + "deviceId": 10149, + "recurrences": 27 + }, + { + "id": 13916766, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/0/6: Vorlauftemperatur TT201", + "status": "CLOSED", + "created": "2024-06-15T07:19:26.000+02:00", + "modified": "2024-06-17T08:04:57.000+02:00", + "resolved": "2024-06-17T08:04:58.000+02:00", + "closable": false, + "dataPointId": 1389296, + "deviceId": 10149, + "recurrences": 20 + }, + { + "id": 13911337, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notk\u00fchlung", + "status": "CLOSED", + "created": "2024-06-13T13:40:39.000+02:00", + "modified": "2024-06-14T14:20:01.000+02:00", + "resolved": "2024-06-14T14:20:01.000+02:00", + "closable": false, + "dataPointId": 1389359, + "deviceId": 10149, + "recurrences": 13 + }, + { + "id": 13910313, + "type": "ALARM", + "message": "ALARM: Abschaltend: 6102/5/33: Differenzdruck DP101 zu tief", + "status": "CLOSED", + "created": "2024-06-13T07:43:53.000+02:00", + "modified": "2024-06-13T13:50:39.000+02:00", + "resolved": "2024-06-13T13:50:39.000+02:00", + "closable": true, + "dataPointId": 1389288, + "deviceId": 10149, + "recurrences": 6 + }, + { + "id": 13912010, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/0/6: Vorlauftemperatur TT201", + "status": "CLOSED", + "created": "2024-06-13T17:37:13.000+02:00", + "modified": "2024-06-14T14:20:10.000+02:00", + "resolved": "2024-06-14T14:20:10.000+02:00", + "closable": false, + "dataPointId": 1389296, + "deviceId": 10149, + "recurrences": 6 + }, + { + "id": 13910314, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/0: Anlage Zustand St\u00f6rung", + "status": "CLOSED", + "created": "2024-06-13T07:43:54.000+02:00", + "modified": "2024-06-14T14:19:50.000+02:00", + "resolved": "2024-06-14T14:19:51.000+02:00", + "closable": false, + "dataPointId": 1389326, + "deviceId": 10149, + "recurrences": 6 + } +] \ No newline at end of file From 1c5f75375d4f92b05e4471b17bc67af5df74f080 Mon Sep 17 00:00:00 2001 From: baechir Date: Thu, 20 Jun 2024 09:57:42 +0200 Subject: [PATCH 02/13] avelon-tickets: change doc --- check-plugins/avelon-tickets/README.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/check-plugins/avelon-tickets/README.rst b/check-plugins/avelon-tickets/README.rst index b0160d275..ce8af0418 100644 --- a/check-plugins/avelon-tickets/README.rst +++ b/check-plugins/avelon-tickets/README.rst @@ -16,11 +16,10 @@ If you already have a license, log in to Avelon and click on Settings in the use Links: -- [Avelon](https://avelon.com/) -- [Avelon Cloud Platform](https://avelon.cloud/) -- [Avelon Documentation](https://avelon.cloud/docs/) -- [API Documentation](https://avelon.cloud/swagger/swagger-ui/index.html?urls.primaryName=Public%20API#/) - +* Avelon: https://avelon.com +* Avelon Cloud Platform: https://avelon.cloud +* Avelon Documentation: https://avelon.cloud/docs +* API Documentation: https://avelon.cloud/swagger/swagger-ui/index.html?urls.primaryName=Public%20API# Fact Sheet From b3a0ab4f54a6646f233dab5d93245cd4738646c4 Mon Sep 17 00:00:00 2001 From: baechir Date: Thu, 20 Jun 2024 10:00:51 +0200 Subject: [PATCH 03/13] avelon-tickets: change doc --- check-plugins/avelon-tickets/README.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/check-plugins/avelon-tickets/README.rst b/check-plugins/avelon-tickets/README.rst index ce8af0418..8b83490c7 100644 --- a/check-plugins/avelon-tickets/README.rst +++ b/check-plugins/avelon-tickets/README.rst @@ -16,10 +16,10 @@ If you already have a license, log in to Avelon and click on Settings in the use Links: -* Avelon: https://avelon.com -* Avelon Cloud Platform: https://avelon.cloud -* Avelon Documentation: https://avelon.cloud/docs -* API Documentation: https://avelon.cloud/swagger/swagger-ui/index.html?urls.primaryName=Public%20API# +* `Avelon `_ +* `Avelon Cloud Platform `_ +* `Avelon Documentation `_ +* `API Documentation `_ Fact Sheet From 18d28374ad2893113b69906b55886fac6960e7e1 Mon Sep 17 00:00:00 2001 From: baechir Date: Fri, 21 Jun 2024 15:30:29 +0200 Subject: [PATCH 04/13] avelon-tickets: tried to make the code a bit prettier --- check-plugins/avelon-tickets/README.rst | 91 ++++++----- check-plugins/avelon-tickets/avelon-tickets | 152 ++++++++++-------- .../avelon-tickets/unit-test/stdout/EXAMPLE01 | 41 +++++ .../avelon-tickets/unit-test/stdout/EXAMPLE02 | 28 ++++ .../avelon-tickets/unit-test/stdout/EXAMPLE03 | 15 ++ .../avelon-tickets/unit-test/stdout/EXAMPLE04 | 1 + .../avelon-tickets/unit-test/stdout/tickets | 119 -------------- 7 files changed, 224 insertions(+), 223 deletions(-) create mode 100644 check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE01 create mode 100644 check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE02 create mode 100644 check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE03 create mode 100644 check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE04 delete mode 100644 check-plugins/avelon-tickets/unit-test/stdout/tickets diff --git a/check-plugins/avelon-tickets/README.rst b/check-plugins/avelon-tickets/README.rst index 8b83490c7..817787957 100644 --- a/check-plugins/avelon-tickets/README.rst +++ b/check-plugins/avelon-tickets/README.rst @@ -31,7 +31,7 @@ Fact Sheet "Check Plugin Download", "https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/avelon-tickets" "Check Interval Recommendation", "Once a minute" "Can be called without parameters", "No" - "Compiled for", "Linux" + "Compiled for", "Linux, Windows" Help @@ -39,63 +39,82 @@ Help .. code-block:: text - usage: avelon-tickets [-h] [-V] [--always-ok] [--client-id] [--client-secret] - [--username] [--password] [--no-closed-ticket] - [--verify] [--proxies] [--timeout] [--test] - - The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts or warnings can be triggered. You - need a license to access the public API of the Avelon Cloud. - - options: - -h, --help show this help message and exit - -V, --version show program's version number and exit - --always-ok Always returns OK. - --client-id Avelon API client_id. - --client-secret Avelon API client_secret. - --username Avelon Cloud username. - --password Avelon Cloud password. - --no-closed-ticket The option allows viewing the closed alarms as well. Default: True - --verify This option explicitly allows to perform "insecure" SSL connections. Default: True - --proxies This option allows you to set specific proxies. For no proxy: {"http": None, "https": None}. Default: {} (System Proxy) - --timeout Network timeout in seconds. Default: 8 (seconds) - --test For unit tests. Needs "path-to-stdout-file,path-to-stderr-file,expected-retc". + usage: avelon-tickets [-h] [-V] [--always-ok] --client-id CLIENT_ID --client-secret CLIENT_SECRET [--closed-ticket] + [-c [{ACKNOWLEDGED,OPEN} ...]] [--insecure] [--no-proxy] --password PASSWORD --username USERNAME + [--test TEST] [--timeout TIMEOUT] [-w [{ACKNOWLEDGED,OPEN} ...]] + + The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts + or warnings can be triggered. You need a license to access the public API of the Avelon Cloud. + + options: + -h, --help show this help message and exit + -V, --version show program's version number and exit + --always-ok Always returns OK. + --client-id CLIENT_ID + Avelon API client_id. + --client-secret CLIENT_SECRET + Avelon API client_secret. + --closed-ticket The option allows viewing the closed alarms as well. Default: False + -c [{ACKNOWLEDGED,OPEN} ...], --critical [{ACKNOWLEDGED,OPEN} ...] + Set the CRIT threshold as a status of the ticket (alarm). Default: >= [] + --insecure This option explicitly allows to perform "insecure" SSL connections. Default: False + --no-proxy Do not use a proxy. Default: False + --password PASSWORD Avelon Cloud password. + --username USERNAME Avelon Cloud username. + --test TEST For unit tests. Needs "path-to-stdout-file,path-to-stderr-file,expected-retc". + --timeout TIMEOUT Network timeout in seconds. Default: 8 (seconds) + -w [{ACKNOWLEDGED,OPEN} ...], --warning [{ACKNOWLEDGED,OPEN} ...] + Set the WARN threshold as a status of the ticket (alarm). Default: >= ['ACKNOWLEDGED', 'OPEN'] Usage Examples -------------- .. code-block:: bash - ./avelon-tickets --client-id "CLIENT_ID" --client-secret "CLIENT_SECRET" --username "USER" --password "PASSWORD" --no-closed-ticket "False" + ./avelon-tickets --client-id CLIENT_ID --client-secret CLIENT_SECRET --username USER --password PASSWORD --critical ACKNOWLEDGED OPEN Output: .. code-block:: text - There are open alarm ticket(s). - ID ! Timestamp ! Type ! Message ! Status ! State - ---------+-------------------------------+-------+-------------------------------------------------------------------------+--------------+------------ - 13910313 ! 2024-06-13T07:43:53.000+02:00 ! ALARM ! ALARM: Abschaltend: 6102/5/33: Differenzdruck DP101 zu tief ! CLOSED ! - 13910314 ! 2024-06-13T07:43:54.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED ! - 13911337 ! 2024-06-13T13:40:39.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED ! - 13912010 ! 2024-06-13T17:37:13.000+02:00 ! ALARM ! ALARM: Störung: 6102/0/6: Vorlauftemperatur TT201 ! CLOSED ! - 13915922 ! 2024-06-14T23:58:36.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED ! - 13915923 ! 2024-06-14T23:58:36.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED ! - 13916766 ! 2024-06-15T07:19:26.000+02:00 ! ALARM ! ALARM: Störung: 6102/0/6: Vorlauftemperatur TT201 ! CLOSED ! - 13927572 ! 2024-06-18T19:46:56.000+02:00 ! ALARM ! ALARM: Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN ! [CRITICAL] - 13927573 ! 2024-06-18T19:46:56.000+02:00 ! ALARM ! ALARM: Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED ! [WARNING] + ID ! Timestamp ! Message ! State + ---------+----------------------------------+-------------------------------------------------------------+------------------------- + 13927572 ! 2024-06-18 19:46:56 (2D 13h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL] + 13927573 ! 2024-06-18 19:46:56 (2D 13h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [CRITICAL] + + + +.. code-block:: bash + ./avelon-tickets --client-id CLIENT_ID --client-secret CLIENT_SECRET --username USER --password PASSWORD --closed-ticket --warning ACKNOWLEDGED --critical OPEN + +Output: + +.. code-block:: text + There are open alarm ticket(s). + + ID ! Timestamp ! Message ! State + ---------+----------------------------------+------------------------------------------------------------------+------------------------ + 13910314 ! 2024-06-13 07:43:54 (1W 1D ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED + 13911337 ! 2024-06-13 13:40:39 (1W 19h ago) ! Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED + 13912010 ! 2024-06-13 17:37:13 (1W 15h ago) ! Störung: 6102/0/6: Vorlauftemperatur TT201 ! CLOSED + 13915922 ! 2024-06-14 23:58:36 (6D 9h ago) ! Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED + 13915923 ! 2024-06-14 23:58:36 (6D 9h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED + 13916766 ! 2024-06-15 07:19:26 (6D 1h ago) ! Störung: 6102/0/6: Vorlauftemperatur TT201 ! CLOSED + 13927572 ! 2024-06-18 19:46:56 (2D 13h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL] + 13927573 ! 2024-06-18 19:46:56 (2D 13h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [WARNING] States ------ -Needs to be added. +* WARN or CRIT if a ticket (alarm) status matches the defined values (ACKNOWLEDGED / OPEN). Perfdata / Metrics ------------------ -Needs to be added. +There is no perfdata. Credits, License diff --git a/check-plugins/avelon-tickets/avelon-tickets b/check-plugins/avelon-tickets/avelon-tickets index 0fea673f0..f59db8180 100755 --- a/check-plugins/avelon-tickets/avelon-tickets +++ b/check-plugins/avelon-tickets/avelon-tickets @@ -12,6 +12,7 @@ """ import argparse # pylint: disable=C0413 +import datetime # pylint: disable=C0413 import json # pylint: disable=C0413 import re # pylint: disable=C0413 import sys # pylint: disable=C0413 @@ -33,18 +34,19 @@ DESCRIPTION = """The current tickets (alerts) of your Avelon Cloud are being rev and depending on their status, critical alerts or warnings can be triggered. You need a license to access the public API of the Avelon Cloud.""" -DEFAULT_NO_CLOSED_TICKET = True -DEFAULT_VERIFY = True -DEFAULT_PROXIES = {} +DEFAULT_CLOSED_TICKET = False +DEFAULT_CRIT = [] +DEFAULT_INSECURE = False +DEFAULT_NO_PROXY = False DEFAULT_TIMEOUT = 8 - - +DEFAULT_WARN = ['ACKNOWLEDGED', 'OPEN'] def parse_args(): """Parse command line arguments using argparse. """ parser = argparse.ArgumentParser(description=DESCRIPTION) +# parameter alphabetisch parser.add_argument( '-V', '--version', action='version', @@ -72,46 +74,64 @@ def parse_args(): dest='CLIENT_SECRET', required=True, ) - + parser.add_argument( - '--username', - help='Avelon Cloud username. ', - dest='USERNAME', - required=True, + '--closed-ticket', + help='The option allows viewing the closed alarms as well. ' + 'Default: %(default)s', + dest='CLOSED_TICKET', + action='store_true', + default=DEFAULT_CLOSED_TICKET, ) parser.add_argument( - '--password', - help='Avelon Cloud password.', - dest='PASSWORD', - required=True, + '-c', '--critical', + help='Set the CRIT threshold as a status of the ticket (alarm). ' + 'Default: >= %(default)s', + nargs='*', + choices=['ACKNOWLEDGED', 'OPEN'], + dest='CRIT', + default=DEFAULT_CRIT, ) parser.add_argument( - '--no-closed-ticket', - help='The option allows viewing the closed alarms as well. ' + '--insecure', + help='This option explicitly allows to perform "insecure" SSL connections. ' 'Default: %(default)s', - dest='NO_CLOSED_TICKET', - default=DEFAULT_NO_CLOSED_TICKET, + dest='INSECURE', + action='store_true', + default=DEFAULT_INSECURE, ) parser.add_argument( - '--verify', - help='This option explicitly allows to perform "insecure" SSL ' - 'connections. ' + '--no-proxy', + help='Do not use a proxy. ' 'Default: %(default)s', - dest='VERIFY', - default=DEFAULT_VERIFY, + dest='NO_PROXY', + action='store_true', + default=DEFAULT_NO_PROXY, ) parser.add_argument( - '--proxies', - help='This option allows you to set specific proxies. ' - 'For no proxy: {"http": None, "https": None}. ' - 'Default: %(default)s (System Proxy)', - dest='PROXIES', - action='store_true', - default=DEFAULT_PROXIES, + '--password', + help='Avelon Cloud password.', + dest='PASSWORD', + required=True, + ) + + parser.add_argument( + '--username', + help='Avelon Cloud username. ', + dest='USERNAME', + required=True, + ) + + parser.add_argument( + '--test', + help='For unit tests. ' + 'Needs "path-to-stdout-file,path-to-stderr-file,expected-retc".', + dest='TEST', + type=lib.args.csv, ) parser.add_argument( @@ -124,11 +144,13 @@ def parse_args(): ) parser.add_argument( - '--test', - help='For unit tests. ' - 'Needs "path-to-stdout-file,path-to-stderr-file,expected-retc".', - dest='TEST', - type=lib.args.csv, + '-w', '--warning', + help='Set the WARN threshold as a status of the ticket (alarm). ' + 'Default: >= %(default)s', + nargs='*', + choices=['ACKNOWLEDGED', 'OPEN'], + dest='WARN', + default=DEFAULT_WARN, ) return parser.parse_args() @@ -137,7 +159,6 @@ def parse_args(): def main(): """The main function. """ - # parse the command line, exit with UNKNOWN if it fails try: args = parse_args() @@ -156,16 +177,16 @@ def main(): client_secret=args.CLIENT_SECRET, username=args.USERNAME, password=args.PASSWORD, - verify=args.VERIFY, - proxies=args.PROXIES, + #insecure=args.INSECURE, + #no-proxy=args.NO_PROXY, timeout=args.TIMEOUT, ) # get tickets tickets = lib.avelon.get_tickets( access_token=token['access_token'], - verify=args.VERIFY, - proxies=args.PROXIES, + #insecure=args.INSECURE, + #no-proxy=args.NO_PROXY, timeout=args.TIMEOUT, ) else: @@ -174,28 +195,27 @@ def main(): tickets = json.loads(stdout) # analyze tickets - used_state = STATE_OK - locked_state = STATE_OK - - for ticket in tickets: - state = lib.base.get_worst(state, used_state) - - if ticket['type'] == 'ALARM' and ticket['status'] == 'CLOSED': + if ticket['type'] == 'ALARM': locked_state = STATE_OK - if ticket['type'] == 'ALARM' and ticket['status'] == 'ACKNOWLEDGED': - locked_state = STATE_WARN - elif ticket['type'] == 'ALARM' and ticket['status'] == 'OPEN': - locked_state = STATE_CRIT - - state = lib.base.get_worst(state, locked_state) - ticket['state'] = lib.base.state2str(locked_state, prefix='') + if ticket['status'] in args.CRIT: + locked_state = STATE_CRIT + elif ticket['status'] in args.WARN: + locked_state = STATE_WARN + state = lib.base.get_worst(state, locked_state) - # Ticket filter - if args.NO_CLOSED_TICKET == 'True' and ticket['status'] != 'CLOSED': - ticket_data.append(ticket) - elif args.NO_CLOSED_TICKET == 'False': - ticket_data.append(ticket) + # Format timestamp + timestamp = datetime.datetime.strptime(ticket['created'], "%Y-%m-%dT%H:%M:%S.%f%z").strftime("%Y-%m-%d %H:%M:%S") + + # Ticket filter for CLOSED tickets + if ticket['status'] != 'CLOSED' or args.CLOSED_TICKET: + # build ticket_data + ticket_data.append({ + 'id': ticket['id'], + 'timestamp': timestamp + ' (' + lib.human.seconds2human(lib.time.timestrdiff(lib.time.now(as_type='iso'), timestamp)) + ' ago)', + 'msg': re.sub(r'^ALARM: ', '', ticket['message']), + 'state': ticket['status'] + lib.base.state2str(locked_state, prefix=' '), + }) if state == STATE_CRIT: msg = 'There are open alarm ticket(s).\n\n' + msg @@ -204,35 +224,31 @@ def main(): else: msg = 'Everything is ok.\n\n' + msg - # build the message + # build the message if ticket_data: keys = [ 'id', - 'created', - 'type', - 'message', - 'status', + 'timestamp', + 'msg', 'state', ] headers = [ 'ID', 'Timestamp', - 'Type', 'Message', - 'Status', 'State', ] - if ticket_data: msg += lib.base.get_table( sorted(ticket_data, key=lambda d: d['id']), keys, header=headers, ) - + # over and out lib.base.oao(msg, state, always_ok=args.ALWAYS_OK) + if __name__ == '__main__': try: main() diff --git a/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE01 b/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE01 new file mode 100644 index 000000000..7da7c5343 --- /dev/null +++ b/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE01 @@ -0,0 +1,41 @@ +[ + { + "id": 13927572, + "type": "ALARM", + "message": "ALARM: Abschaltend: 6102/5/22: Durchfluss Notk\u00fchlung FQ201 St\u00f6rung", + "status": "OPEN", + "created": "2024-06-18T19:46:56.000+02:00", + "modified": "2024-06-18T19:47:33.000+02:00", + "resolved": null, + "closable": false, + "dataPointId": 1389273, + "deviceId": 10149, + "recurrences": 6 + }, + { + "id": 13927573, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/0: Anlage Zustand St\u00f6rung", + "status": "ACKNOWLEDGED", + "created": "2024-06-18T19:46:56.000+02:00", + "modified": "2024-06-19T14:43:35.000+02:00", + "resolved": null, + "closable": false, + "dataPointId": 1389326, + "deviceId": 10149, + "recurrences": 6 + }, + { + "id": 13915922, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notk\u00fchlung", + "status": "CLOSED", + "created": "2024-06-14T23:58:36.000+02:00", + "modified": "2024-06-17T08:04:46.000+02:00", + "resolved": "2024-06-17T08:04:46.000+02:00", + "closable": false, + "dataPointId": 1389359, + "deviceId": 10149, + "recurrences": 55 + } +] \ No newline at end of file diff --git a/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE02 b/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE02 new file mode 100644 index 000000000..b8d57bcd4 --- /dev/null +++ b/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE02 @@ -0,0 +1,28 @@ +[ + { + "id": 13927573, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/0: Anlage Zustand St\u00f6rung", + "status": "ACKNOWLEDGED", + "created": "2024-06-18T19:46:56.000+02:00", + "modified": "2024-06-19T14:43:35.000+02:00", + "resolved": null, + "closable": false, + "dataPointId": 1389326, + "deviceId": 10149, + "recurrences": 6 + }, + { + "id": 13915922, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notk\u00fchlung", + "status": "CLOSED", + "created": "2024-06-14T23:58:36.000+02:00", + "modified": "2024-06-17T08:04:46.000+02:00", + "resolved": "2024-06-17T08:04:46.000+02:00", + "closable": false, + "dataPointId": 1389359, + "deviceId": 10149, + "recurrences": 55 + } +] \ No newline at end of file diff --git a/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE03 b/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE03 new file mode 100644 index 000000000..4503818fa --- /dev/null +++ b/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE03 @@ -0,0 +1,15 @@ +[ + { + "id": 13915922, + "type": "ALARM", + "message": "ALARM: St\u00f6rung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notk\u00fchlung", + "status": "CLOSED", + "created": "2024-06-14T23:58:36.000+02:00", + "modified": "2024-06-17T08:04:46.000+02:00", + "resolved": "2024-06-17T08:04:46.000+02:00", + "closable": false, + "dataPointId": 1389359, + "deviceId": 10149, + "recurrences": 55 + } +] \ No newline at end of file diff --git a/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE04 b/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE04 new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/check-plugins/avelon-tickets/unit-test/stdout/EXAMPLE04 @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/check-plugins/avelon-tickets/unit-test/stdout/tickets b/check-plugins/avelon-tickets/unit-test/stdout/tickets deleted file mode 100644 index 5cdf90249..000000000 --- a/check-plugins/avelon-tickets/unit-test/stdout/tickets +++ /dev/null @@ -1,119 +0,0 @@ -[ - { - "id": 13927572, - "type": "ALARM", - "message": "ALARM: Abschaltend: 6102/5/22: Durchfluss Notk\u00fchlung FQ201 St\u00f6rung", - "status": "OPEN", - "created": "2024-06-18T19:46:56.000+02:00", - "modified": "2024-06-18T19:47:33.000+02:00", - "resolved": null, - "closable": false, - "dataPointId": 1389273, - "deviceId": 10149, - "recurrences": 6 - }, - { - "id": 13927573, - "type": "ALARM", - "message": "ALARM: St\u00f6rung: 6102/5/0: Anlage Zustand St\u00f6rung", - "status": "ACKNOWLEDGED", - "created": "2024-06-18T19:46:56.000+02:00", - "modified": "2024-06-19T14:43:35.000+02:00", - "resolved": null, - "closable": false, - "dataPointId": 1389326, - "deviceId": 10149, - "recurrences": 6 - }, - { - "id": 13915922, - "type": "ALARM", - "message": "ALARM: St\u00f6rung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notk\u00fchlung", - "status": "CLOSED", - "created": "2024-06-14T23:58:36.000+02:00", - "modified": "2024-06-17T08:04:46.000+02:00", - "resolved": "2024-06-17T08:04:46.000+02:00", - "closable": false, - "dataPointId": 1389359, - "deviceId": 10149, - "recurrences": 55 - }, - { - "id": 13915923, - "type": "ALARM", - "message": "ALARM: St\u00f6rung: 6102/5/0: Anlage Zustand St\u00f6rung", - "status": "CLOSED", - "created": "2024-06-14T23:58:36.000+02:00", - "modified": "2024-06-17T08:04:34.000+02:00", - "resolved": "2024-06-17T08:04:35.000+02:00", - "closable": false, - "dataPointId": 1389326, - "deviceId": 10149, - "recurrences": 27 - }, - { - "id": 13916766, - "type": "ALARM", - "message": "ALARM: St\u00f6rung: 6102/0/6: Vorlauftemperatur TT201", - "status": "CLOSED", - "created": "2024-06-15T07:19:26.000+02:00", - "modified": "2024-06-17T08:04:57.000+02:00", - "resolved": "2024-06-17T08:04:58.000+02:00", - "closable": false, - "dataPointId": 1389296, - "deviceId": 10149, - "recurrences": 20 - }, - { - "id": 13911337, - "type": "ALARM", - "message": "ALARM: St\u00f6rung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notk\u00fchlung", - "status": "CLOSED", - "created": "2024-06-13T13:40:39.000+02:00", - "modified": "2024-06-14T14:20:01.000+02:00", - "resolved": "2024-06-14T14:20:01.000+02:00", - "closable": false, - "dataPointId": 1389359, - "deviceId": 10149, - "recurrences": 13 - }, - { - "id": 13910313, - "type": "ALARM", - "message": "ALARM: Abschaltend: 6102/5/33: Differenzdruck DP101 zu tief", - "status": "CLOSED", - "created": "2024-06-13T07:43:53.000+02:00", - "modified": "2024-06-13T13:50:39.000+02:00", - "resolved": "2024-06-13T13:50:39.000+02:00", - "closable": true, - "dataPointId": 1389288, - "deviceId": 10149, - "recurrences": 6 - }, - { - "id": 13912010, - "type": "ALARM", - "message": "ALARM: St\u00f6rung: 6102/0/6: Vorlauftemperatur TT201", - "status": "CLOSED", - "created": "2024-06-13T17:37:13.000+02:00", - "modified": "2024-06-14T14:20:10.000+02:00", - "resolved": "2024-06-14T14:20:10.000+02:00", - "closable": false, - "dataPointId": 1389296, - "deviceId": 10149, - "recurrences": 6 - }, - { - "id": 13910314, - "type": "ALARM", - "message": "ALARM: St\u00f6rung: 6102/5/0: Anlage Zustand St\u00f6rung", - "status": "CLOSED", - "created": "2024-06-13T07:43:54.000+02:00", - "modified": "2024-06-14T14:19:50.000+02:00", - "resolved": "2024-06-14T14:19:51.000+02:00", - "closable": false, - "dataPointId": 1389326, - "deviceId": 10149, - "recurrences": 6 - } -] \ No newline at end of file From f9ca6984a6ca193cbcd2a5423043fb40be88cfdb Mon Sep 17 00:00:00 2001 From: baechir Date: Mon, 24 Jun 2024 09:53:02 +0200 Subject: [PATCH 05/13] avelon-tickets: Add unit-test --- check-plugins/avelon-tickets/avelon-tickets | 17 +++--- check-plugins/avelon-tickets/unit-test/run | 59 +++++++++++++++++++-- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/check-plugins/avelon-tickets/avelon-tickets b/check-plugins/avelon-tickets/avelon-tickets index f59db8180..767d62d8a 100755 --- a/check-plugins/avelon-tickets/avelon-tickets +++ b/check-plugins/avelon-tickets/avelon-tickets @@ -172,21 +172,20 @@ def main(): if args.TEST is None: # get token - token = lib.avelon.get_token( + success, token = lib.avelon.get_token( client_id=args.CLIENT_ID, client_secret=args.CLIENT_SECRET, username=args.USERNAME, password=args.PASSWORD, - #insecure=args.INSECURE, - #no-proxy=args.NO_PROXY, + insecure=args.INSECURE, + no_proxy=args.NO_PROXY, timeout=args.TIMEOUT, ) - # get tickets - tickets = lib.avelon.get_tickets( + success, tickets = lib.avelon.get_tickets( access_token=token['access_token'], - #insecure=args.INSECURE, - #no-proxy=args.NO_PROXY, + insecure=args.INSECURE, + no_proxy=args.NO_PROXY, timeout=args.TIMEOUT, ) else: @@ -218,9 +217,9 @@ def main(): }) if state == STATE_CRIT: - msg = 'There are open alarm ticket(s).\n\n' + msg + msg = 'There are CRITICAL alarm ticket(s).\n\n' + msg elif state == STATE_WARN: - msg = 'There are acknowledged alarm ticket(s).\n\n' + msg + msg = 'There are WARNING alarm ticket(s).\n\n' + msg else: msg = 'Everything is ok.\n\n' + msg diff --git a/check-plugins/avelon-tickets/unit-test/run b/check-plugins/avelon-tickets/unit-test/run index 72f139795..e4bd00feb 100755 --- a/check-plugins/avelon-tickets/unit-test/run +++ b/check-plugins/avelon-tickets/unit-test/run @@ -23,13 +23,66 @@ import lib.shell class TestCheck(unittest.TestCase): check = '../avelon-tickets' + def test_if_check_runs_tickets(self): + stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --client-id "CLIENTID" --client-secret "CLIENTSECRET" --username "USERNAME" --password "PASSWORD" --test=stdout/EXAMPLE01,,0')) + self.assertIn('There are WARNING alarm ticket(s).', stdout) + self.assertIn('', stdout) + self.assertIn('ID ! Timestamp ! Message ! State', stdout) + self.assertIn('---------+----------------------------------+-------------------------------------------------------------+------------------------', stdout) + self.assertIn('13927572 ! 2024-06-18 19:46:56 (5D 13h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [WARNING]', stdout) + self.assertIn('13927573 ! 2024-06-18 19:46:56 (5D 13h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [WARNING]', stdout) + self.assertEqual(stderr, '') + self.assertEqual(retc, STATE_WARN) + + def test_if_check_runs_tickets(self): + stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --client-id "CLIENTID" --client-secret "CLIENTSECRET" --username "USERNAME" --password "PASSWORD" --critical ACKNOWLEDGED OPEN --test=stdout/EXAMPLE01,,0')) + self.assertIn('There are CRITICAL alarm ticket(s).', stdout) + self.assertIn('', stdout) + self.assertIn('ID ! Timestamp ! Message ! State', stdout) + self.assertIn('---------+----------------------------------+-------------------------------------------------------------+-------------------------', stdout) + self.assertIn('13927572 ! 2024-06-18 19:46:56 (5D 13h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL]', stdout) + self.assertIn('13927573 ! 2024-06-18 19:46:56 (5D 13h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [CRITICAL]', stdout) + self.assertEqual(stderr, '') + self.assertEqual(retc, STATE_CRIT) + + def test_if_check_runs_tickets(self): + stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --client-id "CLIENTID" --client-secret "CLIENTSECRET" --username "USERNAME" --password "PASSWORD" --warning ACKNOWLEDGED --critical OPEN --test=stdout/EXAMPLE01,,0')) + self.assertIn('There are CRITICAL alarm ticket(s).', stdout) + self.assertIn('', stdout) + self.assertIn('ID ! Timestamp ! Message ! State', stdout) + self.assertIn('---------+----------------------------------+-------------------------------------------------------------+------------------------', stdout) + self.assertIn('13927572 ! 2024-06-18 19:46:56 (5D 13h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL]', stdout) + self.assertIn('13927573 ! 2024-06-18 19:46:56 (5D 13h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [WARNING]', stdout) + self.assertEqual(stderr, '') + self.assertEqual(retc, STATE_CRIT) def test_if_check_runs_tickets(self): - stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --test=stdout/tickets,,')) - self.assertIn('ReadModel: ', stdout) + stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --client-id "CLIENTID" --client-secret "CLIENTSECRET" --username "USERNAME" --password "PASSWORD" --test=stdout/EXAMPLE02,,0')) + self.assertIn('There are WARNING alarm ticket(s).', stdout) + self.assertIn('', stdout) + self.assertIn('ID ! Timestamp ! Message ! State', stdout) + self.assertIn('---------+----------------------------------+-------------------------------------------+------------------------', stdout) + self.assertIn('13927573 ! 2024-06-18 19:46:56 (5D 13h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [WARNING]', stdout) + self.assertEqual(stderr, '') + self.assertEqual(retc, STATE_WARN) + + def test_if_check_runs_tickets(self): + stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --client-id "CLIENTID" --client-secret "CLIENTSECRET" --username "USERNAME" --password "PASSWORD" --closed-ticket --test=stdout/EXAMPLE03,,0')) + self.assertIn('Everything is ok.', stdout) + self.assertIn('', stdout) + self.assertIn('ID ! Timestamp ! Message ! State', stdout) + self.assertIn('---------+---------------------------------+------------------------------------------------------------------+--------', stdout) + self.assertIn('13915922 ! 2024-06-14 23:58:36 (1W 2D ago) ! Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED', stdout) self.assertEqual(stderr, '') self.assertEqual(retc, STATE_OK) + def test_if_check_runs_tickets(self): + stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --client-id "CLIENTID" --client-secret "CLIENTSECRET" --username "USERNAME" --password "PASSWORD" --test=stdout/EXAMPLE04,,0')) + self.assertIn('Everything is ok.', stdout) + self.assertEqual(stderr, '') + self.assertEqual(retc, STATE_OK) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() + + From 68de5564121466df26e97ad5a70183051595ef0a Mon Sep 17 00:00:00 2001 From: baechir Date: Mon, 24 Jun 2024 13:12:52 +0200 Subject: [PATCH 06/13] avelon-tickets: add error handling --- check-plugins/avelon-tickets/README.rst | 24 ++++++++------------- check-plugins/avelon-tickets/avelon-tickets | 7 +++++- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/check-plugins/avelon-tickets/README.rst b/check-plugins/avelon-tickets/README.rst index 817787957..f9d6bffde 100644 --- a/check-plugins/avelon-tickets/README.rst +++ b/check-plugins/avelon-tickets/README.rst @@ -76,12 +76,12 @@ Usage Examples Output: .. code-block:: text - There are open alarm ticket(s). + There are CRITICAL alarm ticket(s). ID ! Timestamp ! Message ! State ---------+----------------------------------+-------------------------------------------------------------+------------------------- - 13927572 ! 2024-06-18 19:46:56 (2D 13h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL] - 13927573 ! 2024-06-18 19:46:56 (2D 13h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [CRITICAL] + 13927572 ! 2024-06-18 19:46:56 (5D 14h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL] + 13927573 ! 2024-06-18 19:46:56 (5D 14h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [CRITICAL] @@ -91,18 +91,12 @@ Output: Output: .. code-block:: text - There are open alarm ticket(s). - - ID ! Timestamp ! Message ! State - ---------+----------------------------------+------------------------------------------------------------------+------------------------ - 13910314 ! 2024-06-13 07:43:54 (1W 1D ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED - 13911337 ! 2024-06-13 13:40:39 (1W 19h ago) ! Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED - 13912010 ! 2024-06-13 17:37:13 (1W 15h ago) ! Störung: 6102/0/6: Vorlauftemperatur TT201 ! CLOSED - 13915922 ! 2024-06-14 23:58:36 (6D 9h ago) ! Störung: 6102/5/5: Vorlauftemperatur TT201 zu tief -> Notkühlung ! CLOSED - 13915923 ! 2024-06-14 23:58:36 (6D 9h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED - 13916766 ! 2024-06-15 07:19:26 (6D 1h ago) ! Störung: 6102/0/6: Vorlauftemperatur TT201 ! CLOSED - 13927572 ! 2024-06-18 19:46:56 (2D 13h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL] - 13927573 ! 2024-06-18 19:46:56 (2D 13h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [WARNING] + There are CRITICAL alarm ticket(s). + + ID ! Timestamp ! Message ! State + ---------+----------------------------------+-------------------------------------------------------------+----------------- + 13927572 ! 2024-06-18 19:46:56 (5D 14h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL] + 13927573 ! 2024-06-18 19:46:56 (5D 14h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED States diff --git a/check-plugins/avelon-tickets/avelon-tickets b/check-plugins/avelon-tickets/avelon-tickets index 767d62d8a..311cef7c6 100755 --- a/check-plugins/avelon-tickets/avelon-tickets +++ b/check-plugins/avelon-tickets/avelon-tickets @@ -28,7 +28,7 @@ from lib.globals import (STATE_OK, STATE_UNKNOWN, # pylint: disable=C0413 STATE_WARN, STATE_CRIT) __author__ = 'Linuxfabrik GmbH, Zurich/Switzerland' -__version__ = '2024033002' +__version__ = '2024062401' DESCRIPTION = """The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts or warnings can be triggered. @@ -181,6 +181,9 @@ def main(): no_proxy=args.NO_PROXY, timeout=args.TIMEOUT, ) + if not success: + lib.base.cu(token) + # get tickets success, tickets = lib.avelon.get_tickets( access_token=token['access_token'], @@ -188,6 +191,8 @@ def main(): no_proxy=args.NO_PROXY, timeout=args.TIMEOUT, ) + if not success: + lib.base.cu(tickets) else: # do not call the command, put in test data stdout, stderr, retc = lib.test.test(args.TEST) From 2349f5b89fcb503957892b9c3cf4a156bf6a08a7 Mon Sep 17 00:00:00 2001 From: baechir Date: Mon, 24 Jun 2024 13:47:06 +0200 Subject: [PATCH 07/13] avelon-tickets: add doc --- check-plugins/avelon-tickets/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check-plugins/avelon-tickets/README.rst b/check-plugins/avelon-tickets/README.rst index f9d6bffde..7f871609b 100644 --- a/check-plugins/avelon-tickets/README.rst +++ b/check-plugins/avelon-tickets/README.rst @@ -44,7 +44,7 @@ Help [--test TEST] [--timeout TIMEOUT] [-w [{ACKNOWLEDGED,OPEN} ...]] The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts - or warnings can be triggered. You need a license to access the public API of the Avelon Cloud. + or warnings can be triggered. You need a license to access the public API of the Avelon Cloud. options: -h, --help show this help message and exit From 6ba4727b6f57ae713da047e1629e65b757f18e23 Mon Sep 17 00:00:00 2001 From: baechir Date: Tue, 25 Jun 2024 11:54:28 +0200 Subject: [PATCH 08/13] avelon-tickets: Add icingaweb2-module-director --- .../avelon-tickets.json | 325 ++++++++++++++++++ .../avelon-tickets.yml | 6 + 2 files changed, 331 insertions(+) create mode 100644 check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json create mode 100644 check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.yml diff --git a/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json b/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json new file mode 100644 index 000000000..a233f7d53 --- /dev/null +++ b/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json @@ -0,0 +1,325 @@ +{ + "Command": { + "cmd-check-avelon-tickets": { + "arguments": { + "--always-ok": { + "set_if": "$avelon_tickets_always_ok$" + }, + "--client-id": { + "value": "$avelon_tickets_client_id$" + }, + "--client-secret": { + "value": "$avelon_tickets_client_secret$" + }, + "--closed-ticket": { + "set_if": "$avelon_tickets_closed_ticket$" + }, + "--critical": { + "value": "$avelon_tickets_critical$" + }, + "--insecure": { + "set_if": "$avelon_tickets_insecure$" + }, + "--no-proxy": { + "set_if": "$avelon_tickets_no_proxy$" + }, + "--password": { + "value": "$avelon_tickets_password$" + }, + "--username": { + "value": "$avelon_tickets_username$" + }, + "--timeout": { + "value": "$avelon_tickets_timeout$" + }, + "--warning": { + "value": "$avelon_tickets_warning$" + } + }, + "command": "/usr/lib64/nagios/plugins/avelon-tickets", + "disabled": false, + "fields": [ + { + "datafield_id": 1, + "is_required": "n", + "var_filter": null + }, + { + "datafield_id": 2, + "is_required": "y", + "var_filter": null + }, + { + "datafield_id": 3, + "is_required": "y", + "var_filter": null + }, + { + "datafield_id": 4, + "is_required": "n", + "var_filter": null + }, + { + "datafield_id": 5, + "is_required": "n", + "var_filter": null + }, + { + "datafield_id": 6, + "is_required": "n", + "var_filter": null + }, + { + "datafield_id": 7, + "is_required": "n", + "var_filter": null + }, + { + "datafield_id": 8, + "is_required": "y", + "var_filter": null + }, + { + "datafield_id": 9, + "is_required": "y", + "var_filter": null + }, + { + "datafield_id": 10, + "is_required": "n", + "var_filter": null + }, + { + "datafield_id": 11, + "is_required": "n", + "var_filter": null + } + ], + "imports": [], + "is_string": null, + "methods_execute": "PluginCheck", + "object_name": "cmd-check-avelon-tickets", + "object_type": "object", + "timeout": "10", + "vars": {}, + "zone": null, + "uuid": "27c38f6e-7794-4779-bb22-06427b81c69b" + } + }, + "ServiceTemplate": { + "tpl-service-avelon-tickets": { + "action_url": null, + "apply_for": null, + "assign_filter": null, + "check_command": "cmd-check-avelon-tickets", + "check_interval": 60, + "check_period": null, + "check_timeout": null, + "command_endpoint": null, + "disabled": false, + "display_name": null, + "enable_active_checks": null, + "enable_event_handler": null, + "enable_flapping": null, + "enable_notifications": true, + "enable_passive_checks": null, + "enable_perfdata": null, + "event_command": null, + "fields": [], + "flapping_threshold_high": null, + "flapping_threshold_low": null, + "groups": [], + "host": null, + "icon_image": "avelon-tickets.png", + "icon_image_alt": null, + "imports": [ + "tpl-service-generic" + ], + "max_check_attempts": 5, + "notes": "The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts or warnings can be triggered. You need a license to access the public API of the Avelon Cloud.", + "notes_url": "https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/avelon-tickets", + "object_name": "tpl-service-avelon-tickets", + "object_type": "template", + "retry_interval": 15, + "service_set": null, + "template_choice": null, + "use_agent": null, + "use_var_overrides": null, + "vars": { + "criticality": "C", + "avelon_tickets_always_ok": false, + "avelon_tickets_closed_ticket": false, + "avelon_tickets_critical": [], + "avelon_tickets_insecure": false, + "avelon_tickets_no_proxy": false, + "avelon_tickets_timeout": 8, + "avelon_tickets_warning": [ + "ACKNOWLEDGED", + "OPEN" + ] + }, + "volatile": null, + "zone": null, + "uuid": "72ebd251-a7e1-46c9-96ec-e2e9171a1c95" + } + }, + "DataList": { + "avelon_tickets_critical_list": { + "list_name": "avelon_tickets_critical_list", + "owner": "icinga-admin", + "entries": [ + { + "entry_name": "ACKNOWLEDGED", + "entry_value": "Acknowledged", + "format": "string", + "allowed_roles": null + }, + { + "entry_name": "OPEN", + "entry_value": "Open", + "format": "string", + "allowed_roles": null + } + ], + "uuid": "114fcb86-4900-453b-9e64-303fa2f638f6" + }, + "avelon_tickets_warning_list": { + "list_name": "avelon_tickets_warning_list", + "owner": "icinga-admin", + "entries": [ + { + "entry_name": "ACKNOWLEDGED", + "entry_value": "Acknowledged", + "format": "string", + "allowed_roles": null + }, + { + "entry_name": "OPEN", + "entry_value": "Open", + "format": "string", + "allowed_roles": null + } + ], + "uuid": "64821afe-7c6c-4e23-8873-1aa50f3f7f69" + } + }, + "Datafield": { + "1": { + "varname": "avelon_tickets_always_ok", + "caption": "Avelon Tickets: Always OK?", + "description": "Always returns OK.", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", + "format": null, + "settings": {}, + "uuid": "bde331e1-c00f-43f5-b5b7-f25a7e72afc4" + }, + "2": { + "varname": "avelon_tickets_client_id", + "caption": "Avelon Tickets: Client ID", + "description": "Avelon API client_id. ", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString", + "format": null, + "settings": { + "visibility": "visible" + }, + "uuid": "2fd5a224-5502-4a9d-8b84-bb5db08f456f" + }, + "3": { + "varname": "avelon_tickets_client_secret", + "caption": "Avelon Tickets: Client Secret", + "description": "Avelon API client_secret. ", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString", + "format": null, + "settings": { + "visibility": "visible" + }, + "uuid": "fdfba414-1eb5-4af5-a3ef-297d7fd4d9fb" + }, + "4": { + "varname": "avelon_tickets_closed_ticket", + "caption": "Avelon Tickets: Closed Ticket?", + "description": "The option allows viewing the closed alarms as well.", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", + "format": null, + "settings": {}, + "uuid": "e17071ed-4cbf-4ae0-9ff5-4ce3600fb16c" + }, + "5": { + "varname": "avelon_tickets_critical", + "caption": "Avelon Tickets: Critical", + "description": "Set the CRIT threshold as a status of the ticket (alarm).", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeDatalist", + "format": null, + "settings": { + "behavior": "strict", + "data_type": "string", + "datalist": "avelon_tickets_critical_list" + }, + "uuid": "4463b65e-4f30-4cfe-bd60-9bc5e313adfb" + }, + "6": { + "varname": "avelon_tickets_insecure", + "caption": "Avelon Tickets: Insecure?", + "description": "This option explicitly allows to perform \"insecure\" SSL connections.", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", + "format": null, + "settings": {}, + "uuid": "a9bc9f1a-fa18-4f01-b985-b59b675ae886" + }, + "7": { + "varname": "avelon_tickets_no_proxy", + "caption": "Avelon Tickets: No Proxy?", + "description": "Do not use a proxy.", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", + "format": null, + "settings": {}, + "uuid": "7d0508e4-5254-4deb-b7c9-7b24779c55b6" + }, + "8": { + "varname": "avelon_tickets_password", + "caption": "Avelon Tickets: Password", + "description": "Avelon Cloud password.", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString", + "format": null, + "settings": { + "visibility": "hidden" + }, + "uuid": "da50db44-2085-4294-93a2-443718777168" + }, + "9": { + "varname": "avelon_tickets_username", + "caption": "Avelon Tickets: Username", + "description": "Avelon Cloud username. ", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString", + "format": null, + "settings": { + "visibility": "visible" + }, + "uuid": "fececbee-e624-400f-bb61-98782f2d5154" + }, + "10": { + "varname": "avelon_tickets_timeout", + "caption": "Avelon Tickets: Timeout", + "description": "Network timeout in seconds.", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString", + "format": null, + "settings": { + "visibility": "visible" + }, + "uuid": "9915e597-72c0-4bc4-9256-05a42dd9a503" + }, + "11": { + "varname": "avelon_tickets_warning", + "caption": "Avelon Tickets: Warning", + "description": "Set the WARN threshold as a status of the ticket (alarm).", + "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeDatalist", + "format": null, + "settings": { + "behavior": "strict", + "data_type": "string", + "datalist": "avelon_tickets_warning_list" + }, + "uuid": "ea3a37f0-5ecc-4731-9d6d-aa40df8ce441" + } + } +} diff --git a/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.yml b/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.yml new file mode 100644 index 000000000..33bde1bb6 --- /dev/null +++ b/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.yml @@ -0,0 +1,6 @@ +--- +overwrites: + '["Command"]["cmd-check-avelon-tickets"]["timeout"]': 30 + '["Command"]["cmd-check-avelon-tickets"]["command"]': '/usr/bin/sudo /usr/lib64/nagios/plugins/avelon-tickets' + '["ServiceTemplate"]["tpl-service-avelon-tickets"]["enable_perfdata"]': false + '["ServiceTemplate"]["tpl-service-avelon-tickets"]["max_check_attempts"]': 4 From ec0eb5069ba55f8442107414ed88f12468345ff2 Mon Sep 17 00:00:00 2001 From: TheRapac <55585899+therapac@users.noreply.github.com> Date: Tue, 25 Jun 2024 12:07:43 +0200 Subject: [PATCH 09/13] avelon-tickets: Change doc --- check-plugins/avelon-tickets/README.rst | 61 ++++++++++--------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/check-plugins/avelon-tickets/README.rst b/check-plugins/avelon-tickets/README.rst index 7f871609b..5a341ec5e 100644 --- a/check-plugins/avelon-tickets/README.rst +++ b/check-plugins/avelon-tickets/README.rst @@ -10,8 +10,8 @@ What is the Avelon Cloud? Avelon's products and services have been used in professional building operations for over 20 years. From commercial and industrial buildings to office buildings, airports, and railway facilities. The Avelon Cloud propels buildings into a professional era. Avelon takes care of security and maintenance throughout the entire usage period. With Avelon Cloud, operations become cheaper and more professional. Notes: -To use this monitoring plugin, you need to have a REST API license from Avelon. +To use this monitoring plugin, you need to have a REST API license from Avelon. If you already have a license, log in to Avelon and click on Settings in the user menu at the top right. On the General tab, you will see a section called Public OAuth API Key. The Client ID and Client Secret displayed there are required to authenticate with our API (Monitoring-Plugin). Links: @@ -43,39 +43,41 @@ Help [-c [{ACKNOWLEDGED,OPEN} ...]] [--insecure] [--no-proxy] --password PASSWORD --username USERNAME [--test TEST] [--timeout TIMEOUT] [-w [{ACKNOWLEDGED,OPEN} ...]] - The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts + The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts or warnings can be triggered. You need a license to access the public API of the Avelon Cloud. - options: - -h, --help show this help message and exit - -V, --version show program's version number and exit - --always-ok Always returns OK. - --client-id CLIENT_ID - Avelon API client_id. - --client-secret CLIENT_SECRET - Avelon API client_secret. - --closed-ticket The option allows viewing the closed alarms as well. Default: False - -c [{ACKNOWLEDGED,OPEN} ...], --critical [{ACKNOWLEDGED,OPEN} ...] - Set the CRIT threshold as a status of the ticket (alarm). Default: >= [] - --insecure This option explicitly allows to perform "insecure" SSL connections. Default: False - --no-proxy Do not use a proxy. Default: False - --password PASSWORD Avelon Cloud password. - --username USERNAME Avelon Cloud username. - --test TEST For unit tests. Needs "path-to-stdout-file,path-to-stderr-file,expected-retc". - --timeout TIMEOUT Network timeout in seconds. Default: 8 (seconds) - -w [{ACKNOWLEDGED,OPEN} ...], --warning [{ACKNOWLEDGED,OPEN} ...] - Set the WARN threshold as a status of the ticket (alarm). Default: >= ['ACKNOWLEDGED', 'OPEN'] + options: + -h, --help show this help message and exit + -V, --version show program's version number and exit + --always-ok Always returns OK. + --client-id CLIENT_ID + Avelon API client_id. + --client-secret CLIENT_SECRET + Avelon API client_secret. + --closed-ticket The option allows viewing the closed alarms as well. Default: False + -c [{ACKNOWLEDGED,OPEN} ...], --critical [{ACKNOWLEDGED,OPEN} ...] + Set the CRIT threshold as a status of the ticket (alarm). Default: >= [] + --insecure This option explicitly allows to perform "insecure" SSL connections. Default: False + --no-proxy Do not use a proxy. Default: False + --password PASSWORD Avelon Cloud password. + --username USERNAME Avelon Cloud username. + --test TEST For unit tests. Needs "path-to-stdout-file,path-to-stderr-file,expected-retc". + --timeout TIMEOUT Network timeout in seconds. Default: 8 (seconds) + -w [{ACKNOWLEDGED,OPEN} ...], --warning [{ACKNOWLEDGED,OPEN} ...] + Set the WARN threshold as a status of the ticket (alarm). Default: >= ['ACKNOWLEDGED', 'OPEN'] Usage Examples -------------- .. code-block:: bash - ./avelon-tickets --client-id CLIENT_ID --client-secret CLIENT_SECRET --username USER --password PASSWORD --critical ACKNOWLEDGED OPEN + + ./avelon-tickets --client-id CLIENT_ID --client-secret CLIENT_SECRET --username USER --password PASSWORD --critical ACKNOWLEDGED OPEN Output: .. code-block:: text + There are CRITICAL alarm ticket(s). ID ! Timestamp ! Message ! State @@ -84,21 +86,6 @@ Output: 13927573 ! 2024-06-18 19:46:56 (5D 14h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! ACKNOWLEDGED [CRITICAL] - -.. code-block:: bash - ./avelon-tickets --client-id CLIENT_ID --client-secret CLIENT_SECRET --username USER --password PASSWORD --closed-ticket --warning ACKNOWLEDGED --critical OPEN - -Output: - -.. code-block:: text - There are CRITICAL alarm ticket(s). - - ID ! Timestamp ! Message ! State - ---------+----------------------------------+-------------------------------------------------------------+----------------- - 13927572 ! 2024-06-18 19:46:56 (5D 14h ago) ! Abschaltend: 6102/5/22: Durchfluss Notkühlung FQ201 Störung ! OPEN [CRITICAL] - 13927573 ! 2024-06-18 19:46:56 (5D 14h ago) ! Störung: 6102/5/0: Anlage Zustand Störung ! CLOSED - - States ------ From f62b9a5e7761dec7eea51a9464b11b82e2e46f38 Mon Sep 17 00:00:00 2001 From: baechir Date: Tue, 25 Jun 2024 14:12:48 +0200 Subject: [PATCH 10/13] avelon-tickets: Format code --- check-plugins/avelon-tickets/avelon-tickets | 8 ++-- .../avelon-tickets.json | 46 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/check-plugins/avelon-tickets/avelon-tickets b/check-plugins/avelon-tickets/avelon-tickets index 311cef7c6..1e1dbdca1 100755 --- a/check-plugins/avelon-tickets/avelon-tickets +++ b/check-plugins/avelon-tickets/avelon-tickets @@ -63,14 +63,14 @@ def parse_args(): parser.add_argument( '--client-id', - help='Avelon API client_id. ', + help='Avelon API client_id.', dest='CLIENT_ID', required=True, ) parser.add_argument( '--client-secret', - help='Avelon API client_secret. ', + help='Avelon API client_secret.', dest='CLIENT_SECRET', required=True, ) @@ -105,7 +105,7 @@ def parse_args(): parser.add_argument( '--no-proxy', - help='Do not use a proxy. ' + help='Do not use a proxy.' 'Default: %(default)s', dest='NO_PROXY', action='store_true', @@ -121,7 +121,7 @@ def parse_args(): parser.add_argument( '--username', - help='Avelon Cloud username. ', + help='Avelon Cloud username.', dest='USERNAME', required=True, ) diff --git a/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json b/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json index a233f7d53..1f31d8908 100644 --- a/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json +++ b/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json @@ -36,7 +36,7 @@ "value": "$avelon_tickets_warning$" } }, - "command": "/usr/lib64/nagios/plugins/avelon-tickets", + "command": "/usr/bin/sudo /usr/lib64/nagios/plugins/avelon-tickets", "disabled": false, "fields": [ { @@ -100,10 +100,10 @@ "methods_execute": "PluginCheck", "object_name": "cmd-check-avelon-tickets", "object_type": "object", - "timeout": "10", + "timeout": 30, "vars": {}, "zone": null, - "uuid": "27c38f6e-7794-4779-bb22-06427b81c69b" + "uuid": "f7d99c91-6923-4361-b5c7-ffd10a25bef0" } }, "ServiceTemplate": { @@ -123,7 +123,7 @@ "enable_flapping": null, "enable_notifications": true, "enable_passive_checks": null, - "enable_perfdata": null, + "enable_perfdata": false, "event_command": null, "fields": [], "flapping_threshold_high": null, @@ -135,7 +135,7 @@ "imports": [ "tpl-service-generic" ], - "max_check_attempts": 5, + "max_check_attempts": 4, "notes": "The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts or warnings can be triggered. You need a license to access the public API of the Avelon Cloud.", "notes_url": "https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/avelon-tickets", "object_name": "tpl-service-avelon-tickets", @@ -160,7 +160,7 @@ }, "volatile": null, "zone": null, - "uuid": "72ebd251-a7e1-46c9-96ec-e2e9171a1c95" + "uuid": "f4647c7f-2c0c-468f-a377-3ff12ce7d767" } }, "DataList": { @@ -181,7 +181,7 @@ "allowed_roles": null } ], - "uuid": "114fcb86-4900-453b-9e64-303fa2f638f6" + "uuid": "5ae39edc-f13f-4506-b262-a560ed8e14ab" }, "avelon_tickets_warning_list": { "list_name": "avelon_tickets_warning_list", @@ -200,7 +200,7 @@ "allowed_roles": null } ], - "uuid": "64821afe-7c6c-4e23-8873-1aa50f3f7f69" + "uuid": "718d6db3-506b-4fcd-82e8-e81627a2d7fa" } }, "Datafield": { @@ -211,29 +211,29 @@ "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", "format": null, "settings": {}, - "uuid": "bde331e1-c00f-43f5-b5b7-f25a7e72afc4" + "uuid": "e88f77d4-7b9e-4b67-a9af-0d33b0ffdff4" }, "2": { "varname": "avelon_tickets_client_id", "caption": "Avelon Tickets: Client ID", - "description": "Avelon API client_id. ", + "description": "Avelon API client_id.", "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString", "format": null, "settings": { "visibility": "visible" }, - "uuid": "2fd5a224-5502-4a9d-8b84-bb5db08f456f" + "uuid": "45134e33-0512-4ccb-847e-de0680b11329" }, "3": { "varname": "avelon_tickets_client_secret", "caption": "Avelon Tickets: Client Secret", - "description": "Avelon API client_secret. ", + "description": "Avelon API client_secret.", "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString", "format": null, "settings": { "visibility": "visible" }, - "uuid": "fdfba414-1eb5-4af5-a3ef-297d7fd4d9fb" + "uuid": "99b06461-8a91-4758-bad3-be14260bb266" }, "4": { "varname": "avelon_tickets_closed_ticket", @@ -242,7 +242,7 @@ "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", "format": null, "settings": {}, - "uuid": "e17071ed-4cbf-4ae0-9ff5-4ce3600fb16c" + "uuid": "4c442f02-d8fd-4974-becb-a70df0a3fc91" }, "5": { "varname": "avelon_tickets_critical", @@ -255,7 +255,7 @@ "data_type": "string", "datalist": "avelon_tickets_critical_list" }, - "uuid": "4463b65e-4f30-4cfe-bd60-9bc5e313adfb" + "uuid": "4c74e768-a59a-4528-8dde-51dca4e35179" }, "6": { "varname": "avelon_tickets_insecure", @@ -264,16 +264,16 @@ "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", "format": null, "settings": {}, - "uuid": "a9bc9f1a-fa18-4f01-b985-b59b675ae886" + "uuid": "15de73ca-d519-4405-8668-b71c53ed7261" }, "7": { "varname": "avelon_tickets_no_proxy", "caption": "Avelon Tickets: No Proxy?", - "description": "Do not use a proxy.", + "description": "Do not use a proxy.Default: %(default)s", "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", "format": null, "settings": {}, - "uuid": "7d0508e4-5254-4deb-b7c9-7b24779c55b6" + "uuid": "91657baf-a22d-451d-80ff-ff64b1534946" }, "8": { "varname": "avelon_tickets_password", @@ -284,18 +284,18 @@ "settings": { "visibility": "hidden" }, - "uuid": "da50db44-2085-4294-93a2-443718777168" + "uuid": "4bf89922-97e9-475a-8bf4-a05ff731a982" }, "9": { "varname": "avelon_tickets_username", "caption": "Avelon Tickets: Username", - "description": "Avelon Cloud username. ", + "description": "Avelon Cloud username.", "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString", "format": null, "settings": { "visibility": "visible" }, - "uuid": "fececbee-e624-400f-bb61-98782f2d5154" + "uuid": "e72417d9-80b1-4321-ae82-658baf79f1a7" }, "10": { "varname": "avelon_tickets_timeout", @@ -306,7 +306,7 @@ "settings": { "visibility": "visible" }, - "uuid": "9915e597-72c0-4bc4-9256-05a42dd9a503" + "uuid": "03fcd395-5940-41fc-8702-0f82537c5601" }, "11": { "varname": "avelon_tickets_warning", @@ -319,7 +319,7 @@ "data_type": "string", "datalist": "avelon_tickets_warning_list" }, - "uuid": "ea3a37f0-5ecc-4731-9d6d-aa40df8ce441" + "uuid": "51378d3f-b08e-4371-90cf-7d2f9a70b13b" } } } From c49227992d265d3f4a7322c163c95fd9d51f13ef Mon Sep 17 00:00:00 2001 From: baechir Date: Wed, 26 Jun 2024 15:56:35 +0200 Subject: [PATCH 11/13] avelon-tickets: Fix: Yesterday evening, on 25.06.2024, Avelon added two additional statuses (ACKNOWLEDGED_AND_GONE, GONE). These have now been included in the plugin. --- check-plugins/avelon-tickets/README.rst | 19 ++++--- check-plugins/avelon-tickets/avelon-tickets | 6 +- .../avelon-tickets.json | 56 ++++++++++++++----- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/check-plugins/avelon-tickets/README.rst b/check-plugins/avelon-tickets/README.rst index 5a341ec5e..a8c9e9828 100644 --- a/check-plugins/avelon-tickets/README.rst +++ b/check-plugins/avelon-tickets/README.rst @@ -40,11 +40,11 @@ Help .. code-block:: text usage: avelon-tickets [-h] [-V] [--always-ok] --client-id CLIENT_ID --client-secret CLIENT_SECRET [--closed-ticket] - [-c [{ACKNOWLEDGED,OPEN} ...]] [--insecure] [--no-proxy] --password PASSWORD --username USERNAME - [--test TEST] [--timeout TIMEOUT] [-w [{ACKNOWLEDGED,OPEN} ...]] + [-c [{ACKNOWLEDGED,ACKNOWLEDGED_AND_GONE,GONE,OPEN} ...]] [--insecure] [--no-proxy] --password PASSWORD --username + USERNAME [--test TEST] [--timeout TIMEOUT] [-w [{ACKNOWLEDGED,ACKNOWLEDGED_AND_GONE,GONE,OPEN} ...]] - The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts - or warnings can be triggered. You need a license to access the public API of the Avelon Cloud. + The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts or warnings can be + triggered. You need a license to access the public API of the Avelon Cloud. options: -h, --help show this help message and exit @@ -55,16 +55,17 @@ Help --client-secret CLIENT_SECRET Avelon API client_secret. --closed-ticket The option allows viewing the closed alarms as well. Default: False - -c [{ACKNOWLEDGED,OPEN} ...], --critical [{ACKNOWLEDGED,OPEN} ...] + -c [{ACKNOWLEDGED,ACKNOWLEDGED_AND_GONE,GONE,OPEN} ...], --critical [{ACKNOWLEDGED,ACKNOWLEDGED_AND_GONE,GONE,OPEN} ...] Set the CRIT threshold as a status of the ticket (alarm). Default: >= [] --insecure This option explicitly allows to perform "insecure" SSL connections. Default: False - --no-proxy Do not use a proxy. Default: False + --no-proxy Do not use a proxy.Default: False --password PASSWORD Avelon Cloud password. --username USERNAME Avelon Cloud username. --test TEST For unit tests. Needs "path-to-stdout-file,path-to-stderr-file,expected-retc". --timeout TIMEOUT Network timeout in seconds. Default: 8 (seconds) - -w [{ACKNOWLEDGED,OPEN} ...], --warning [{ACKNOWLEDGED,OPEN} ...] - Set the WARN threshold as a status of the ticket (alarm). Default: >= ['ACKNOWLEDGED', 'OPEN'] + -w [{ACKNOWLEDGED,ACKNOWLEDGED_AND_GONE,GONE,OPEN} ...], --warning [{ACKNOWLEDGED,ACKNOWLEDGED_AND_GONE,GONE,OPEN} ...] + Set the WARN threshold as a status of the ticket (alarm). Default: >= ['ACKNOWLEDGED', 'ACKNOWLEDGED_AND_GONE', + 'GONE', 'OPEN'] Usage Examples @@ -89,7 +90,7 @@ Output: States ------ -* WARN or CRIT if a ticket (alarm) status matches the defined values (ACKNOWLEDGED / OPEN). +* WARN or CRIT if a ticket (alarm) status matches the defined values (ACKNOWLEDGED, ACKNOWLEDGED_AND_GONE, GONE and OPEN). Perfdata / Metrics diff --git a/check-plugins/avelon-tickets/avelon-tickets b/check-plugins/avelon-tickets/avelon-tickets index 1e1dbdca1..e30673885 100755 --- a/check-plugins/avelon-tickets/avelon-tickets +++ b/check-plugins/avelon-tickets/avelon-tickets @@ -39,7 +39,7 @@ DEFAULT_CRIT = [] DEFAULT_INSECURE = False DEFAULT_NO_PROXY = False DEFAULT_TIMEOUT = 8 -DEFAULT_WARN = ['ACKNOWLEDGED', 'OPEN'] +DEFAULT_WARN = ['ACKNOWLEDGED', 'ACKNOWLEDGED_AND_GONE', 'GONE', 'OPEN'] def parse_args(): """Parse command line arguments using argparse. @@ -89,7 +89,7 @@ def parse_args(): help='Set the CRIT threshold as a status of the ticket (alarm). ' 'Default: >= %(default)s', nargs='*', - choices=['ACKNOWLEDGED', 'OPEN'], + choices=['ACKNOWLEDGED', 'ACKNOWLEDGED_AND_GONE', 'GONE', 'OPEN'], dest='CRIT', default=DEFAULT_CRIT, ) @@ -148,7 +148,7 @@ def parse_args(): help='Set the WARN threshold as a status of the ticket (alarm). ' 'Default: >= %(default)s', nargs='*', - choices=['ACKNOWLEDGED', 'OPEN'], + choices=['ACKNOWLEDGED', 'ACKNOWLEDGED_AND_GONE', 'GONE', 'OPEN'], dest='WARN', default=DEFAULT_WARN, ) diff --git a/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json b/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json index 1f31d8908..d7bdfd4a8 100644 --- a/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json +++ b/check-plugins/avelon-tickets/icingaweb2-module-director/avelon-tickets.json @@ -103,7 +103,7 @@ "timeout": 30, "vars": {}, "zone": null, - "uuid": "f7d99c91-6923-4361-b5c7-ffd10a25bef0" + "uuid": "4984cd39-46c3-456d-beb6-57126bae63bb" } }, "ServiceTemplate": { @@ -155,12 +155,14 @@ "avelon_tickets_timeout": 8, "avelon_tickets_warning": [ "ACKNOWLEDGED", + "ACKNOWLEDGED_AND_GONE", + "GONE", "OPEN" ] }, "volatile": null, "zone": null, - "uuid": "f4647c7f-2c0c-468f-a377-3ff12ce7d767" + "uuid": "7a88cf8d-c01a-42f7-a8fc-66d95fde9a5d" } }, "DataList": { @@ -174,6 +176,18 @@ "format": "string", "allowed_roles": null }, + { + "entry_name": "ACKNOWLEDGED_AND_GONE", + "entry_value": "Acknowledged And Gone", + "format": "string", + "allowed_roles": null + }, + { + "entry_name": "GONE", + "entry_value": "Gone", + "format": "string", + "allowed_roles": null + }, { "entry_name": "OPEN", "entry_value": "Open", @@ -181,7 +195,7 @@ "allowed_roles": null } ], - "uuid": "5ae39edc-f13f-4506-b262-a560ed8e14ab" + "uuid": "fe70f681-28ef-4d1f-95ee-ce99ee983232" }, "avelon_tickets_warning_list": { "list_name": "avelon_tickets_warning_list", @@ -193,6 +207,18 @@ "format": "string", "allowed_roles": null }, + { + "entry_name": "ACKNOWLEDGED_AND_GONE", + "entry_value": "Acknowledged And Gone", + "format": "string", + "allowed_roles": null + }, + { + "entry_name": "GONE", + "entry_value": "Gone", + "format": "string", + "allowed_roles": null + }, { "entry_name": "OPEN", "entry_value": "Open", @@ -200,7 +226,7 @@ "allowed_roles": null } ], - "uuid": "718d6db3-506b-4fcd-82e8-e81627a2d7fa" + "uuid": "1c4e131f-22c0-4238-b2a6-7bb50198090b" } }, "Datafield": { @@ -211,7 +237,7 @@ "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", "format": null, "settings": {}, - "uuid": "e88f77d4-7b9e-4b67-a9af-0d33b0ffdff4" + "uuid": "c4d5d2a6-028c-46a2-9fa4-82dfe45cd187" }, "2": { "varname": "avelon_tickets_client_id", @@ -222,7 +248,7 @@ "settings": { "visibility": "visible" }, - "uuid": "45134e33-0512-4ccb-847e-de0680b11329" + "uuid": "26f07670-49d1-4102-98c6-1f80293c34b4" }, "3": { "varname": "avelon_tickets_client_secret", @@ -233,7 +259,7 @@ "settings": { "visibility": "visible" }, - "uuid": "99b06461-8a91-4758-bad3-be14260bb266" + "uuid": "84dc37e3-b0f6-4879-8005-4efa34713c75" }, "4": { "varname": "avelon_tickets_closed_ticket", @@ -242,7 +268,7 @@ "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", "format": null, "settings": {}, - "uuid": "4c442f02-d8fd-4974-becb-a70df0a3fc91" + "uuid": "0c8e75bd-35ec-490c-823b-6313c6004407" }, "5": { "varname": "avelon_tickets_critical", @@ -255,7 +281,7 @@ "data_type": "string", "datalist": "avelon_tickets_critical_list" }, - "uuid": "4c74e768-a59a-4528-8dde-51dca4e35179" + "uuid": "d2a6d1af-c584-4a00-8405-4029ca00ad14" }, "6": { "varname": "avelon_tickets_insecure", @@ -264,7 +290,7 @@ "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", "format": null, "settings": {}, - "uuid": "15de73ca-d519-4405-8668-b71c53ed7261" + "uuid": "54c366c2-9775-4a00-9314-11b725c6496b" }, "7": { "varname": "avelon_tickets_no_proxy", @@ -273,7 +299,7 @@ "datatype": "Icinga\\Module\\Director\\DataType\\DataTypeBoolean", "format": null, "settings": {}, - "uuid": "91657baf-a22d-451d-80ff-ff64b1534946" + "uuid": "289c407d-af81-4ddd-92c1-fe529dcb33b7" }, "8": { "varname": "avelon_tickets_password", @@ -284,7 +310,7 @@ "settings": { "visibility": "hidden" }, - "uuid": "4bf89922-97e9-475a-8bf4-a05ff731a982" + "uuid": "e8ac942f-2f09-44ec-a490-b86347fe8660" }, "9": { "varname": "avelon_tickets_username", @@ -295,7 +321,7 @@ "settings": { "visibility": "visible" }, - "uuid": "e72417d9-80b1-4321-ae82-658baf79f1a7" + "uuid": "524dd1e9-b762-40fb-861f-7497ffcb2e5a" }, "10": { "varname": "avelon_tickets_timeout", @@ -306,7 +332,7 @@ "settings": { "visibility": "visible" }, - "uuid": "03fcd395-5940-41fc-8702-0f82537c5601" + "uuid": "582299ec-1093-46f7-bfd1-ee3e504f3627" }, "11": { "varname": "avelon_tickets_warning", @@ -319,7 +345,7 @@ "data_type": "string", "datalist": "avelon_tickets_warning_list" }, - "uuid": "51378d3f-b08e-4371-90cf-7d2f9a70b13b" + "uuid": "bb372f8f-ba91-4d3c-8740-f7901881f380" } } } From ce0bf8750e6ef7dbe83f031d96ea2b833135554a Mon Sep 17 00:00:00 2001 From: TheRapac <55585899+therapac@users.noreply.github.com> Date: Wed, 24 Jul 2024 09:51:54 +0200 Subject: [PATCH 12/13] avelon-tickets: code structure --- check-plugins/avelon-tickets/avelon-tickets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check-plugins/avelon-tickets/avelon-tickets b/check-plugins/avelon-tickets/avelon-tickets index e30673885..6fb59ef42 100755 --- a/check-plugins/avelon-tickets/avelon-tickets +++ b/check-plugins/avelon-tickets/avelon-tickets @@ -242,7 +242,7 @@ def main(): 'Message', 'State', ] - if ticket_data: + msg += lib.base.get_table( sorted(ticket_data, key=lambda d: d['id']), keys, From d47757151c3347e34379921cc7505fb65722939c Mon Sep 17 00:00:00 2001 From: baechir Date: Wed, 24 Jul 2024 14:20:04 +0200 Subject: [PATCH 13/13] avelon-tickets: Code structure and version --- check-plugins/avelon-tickets/avelon-tickets | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/check-plugins/avelon-tickets/avelon-tickets b/check-plugins/avelon-tickets/avelon-tickets index 6fb59ef42..d8f5ce921 100755 --- a/check-plugins/avelon-tickets/avelon-tickets +++ b/check-plugins/avelon-tickets/avelon-tickets @@ -28,7 +28,7 @@ from lib.globals import (STATE_OK, STATE_UNKNOWN, # pylint: disable=C0413 STATE_WARN, STATE_CRIT) __author__ = 'Linuxfabrik GmbH, Zurich/Switzerland' -__version__ = '2024062401' +__version__ = '2024072401' DESCRIPTION = """The current tickets (alerts) of your Avelon Cloud are being reviewed, and depending on their status, critical alerts or warnings can be triggered. @@ -168,7 +168,7 @@ def main(): # init some vars msg = '' state = STATE_OK - ticket_data = [] + ticket_table = [] if args.TEST is None: # get token @@ -213,8 +213,8 @@ def main(): # Ticket filter for CLOSED tickets if ticket['status'] != 'CLOSED' or args.CLOSED_TICKET: - # build ticket_data - ticket_data.append({ + # build ticket_table + ticket_table.append({ 'id': ticket['id'], 'timestamp': timestamp + ' (' + lib.human.seconds2human(lib.time.timestrdiff(lib.time.now(as_type='iso'), timestamp)) + ' ago)', 'msg': re.sub(r'^ALARM: ', '', ticket['message']), @@ -229,7 +229,7 @@ def main(): msg = 'Everything is ok.\n\n' + msg # build the message - if ticket_data: + if ticket_table: keys = [ 'id', 'timestamp', @@ -244,7 +244,7 @@ def main(): ] msg += lib.base.get_table( - sorted(ticket_data, key=lambda d: d['id']), + sorted(ticket_table, key=lambda d: d['id']), keys, header=headers, )