From f911448a908830eca409976c6f3e852554d93292 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Fri, 5 Apr 2024 23:51:42 -0600 Subject: [PATCH] update check_mysql_slave --- README.md | 10 +++++++--- check_mysql_slave.py | 16 +++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 607ed6b..ccd89ad 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,17 @@ # icinga2-checks -My custom Icinga2 checks. +_My custom Icinga2 checks._ Useful: https://nagios-plugins.org/doc/guidelines.html#AEN200 https://icinga.com/docs/icinga-2/latest/doc/05-service-monitoring/#performance-data-metrics -`requirements-everybody.txt`: pip requirements for all Python 3 versions and Linux and BSD hosts. Should be easy to install on all hosts. +`requirements-everybody.txt`: pip requirements for all Python 3 versions and Linux and BSD hosts. Should be easy to +install on all hosts. -`requirements-difficult.txt`: pip requirements that are easy to install on normal Debian hosts but complicated when there are wheels available. +`requirements-difficult.txt`: pip requirements that are easy to install on normal Debian hosts but complicated when +there are wheels available. + +These scripts have varying levels of code quality. ## Fix `dbus` Issues diff --git a/check_mysql_slave.py b/check_mysql_slave.py index cd86507..d04f165 100755 --- a/check_mysql_slave.py +++ b/check_mysql_slave.py @@ -5,7 +5,8 @@ import traceback import mysql.connector -from checker import nagios, print_icinga2_check_status +from checker import nagios +from checker.result import quit_check from checker.types import try_int """ @@ -107,19 +108,12 @@ def main(args): }, } - text_result = ' '.join(exit_msg) - print_icinga2_check_status(text_result, exit_code, perfdata) - sys.exit(exit_code) + quit_check(' '.join(exit_msg), exit_code, perfdata) except mysql.connector.Error as e: - print("UNKNOWN - Could not connect to database!") - print(e) - sys.exit(nagios.STATE_UNKNOWN) + quit_check(f'Could not connect to database: {e}', nagios.STATE_CRIT) except Exception as e: - print(f"UNKNOWN - {e}") - traceback.print_exc() - sys.exit(nagios.STATE_UNKNOWN) - + quit_check(f'Unknown error: {e}\n{traceback.format_exc()}', nagios.STATE_UNKNOWN) finally: if cursor: cursor.close()