From cc063da7ff645150c13b2e9942a471e731267d9a Mon Sep 17 00:00:00 2001 From: Adrien Robert Date: Tue, 8 Nov 2022 08:42:44 +0100 Subject: [PATCH 1/3] Add possibility to install only required dependencies --- check_bareos.py | 9 ++++----- requirements-mysql.txt | 1 + requirements.txt => requirements-postgres.txt | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 requirements-mysql.txt rename requirements.txt => requirements-postgres.txt (54%) diff --git a/check_bareos.py b/check_bareos.py index 303da50..8c1bce7 100755 --- a/check_bareos.py +++ b/check_bareos.py @@ -17,15 +17,11 @@ # - 1.0.2 start to rework for chosing correct query for the database type (MySQL -vs - PostgreSQL) # - 1.0.3 add port parameter for MySQL and PostgreSQL databases # -# # Plugin check for icinga # ---------------------------------------------------- # import argparse -import psycopg2 -import psycopg2.extras import sys import subprocess -import MySQLdb # Constants @@ -473,6 +469,8 @@ def connectDB(userName, pw, hostName, database, port): global databaseType databaseType = 'psql' try: + import psycopg2 + import psycopg2.extras # Define our connection string connString = "host='" + hostName + "' port=" + str(port) + " dbname='" + databaseName + "' user='" + userName + "' password='" + pw + "'" # get a connection, if a connect cannot be made an exception will be raised here @@ -490,7 +488,8 @@ def connectDB(userName, pw, hostName, database, port): if(database == "mysql" or database == "m"): try: - conn = MySQLdb.connect(host=hostName, user=userName, passwd=pw, db=databaseName, port=port) + import MySQLdb + conn = MySQLdb.connect(host=hostName, user=userName, password=pw, database=databaseName, port=port) except MySQLdb.Error as e: checkState = {} checkState["returnCode"] = 3 diff --git a/requirements-mysql.txt b/requirements-mysql.txt new file mode 100644 index 0000000..485d75f --- /dev/null +++ b/requirements-mysql.txt @@ -0,0 +1 @@ +mysqlclient==2.1.1 diff --git a/requirements.txt b/requirements-postgres.txt similarity index 54% rename from requirements.txt rename to requirements-postgres.txt index ea412ef..4881093 100644 --- a/requirements.txt +++ b/requirements-postgres.txt @@ -1,2 +1 @@ -mysqlclient==2.1.1 psycopg2-binary==2.9.3 From 497ce206a7d6f221c1651e24409cf35452d3e872 Mon Sep 17 00:00:00 2001 From: Adrien Robert Date: Tue, 8 Nov 2022 08:49:37 +0100 Subject: [PATCH 2/3] Fix: MySQL connection was't returning a cursor So the requesting of the DB was impossible Maybe it fixes : NETWAYS/check_bareos#8 --- check_bareos.py | 1 + 1 file changed, 1 insertion(+) diff --git a/check_bareos.py b/check_bareos.py index 8c1bce7..dd6daed 100755 --- a/check_bareos.py +++ b/check_bareos.py @@ -490,6 +490,7 @@ def connectDB(userName, pw, hostName, database, port): try: import MySQLdb conn = MySQLdb.connect(host=hostName, user=userName, password=pw, database=databaseName, port=port) + return conn.cursor() except MySQLdb.Error as e: checkState = {} checkState["returnCode"] = 3 From 68e2879df655eea92b55cfc9386e8b1949a67dca Mon Sep 17 00:00:00 2001 From: Adrien Robert Date: Tue, 8 Nov 2022 08:32:42 +0100 Subject: [PATCH 3/3] Bump version to 1.1.0 --- check_bareos.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/check_bareos.py b/check_bareos.py index dd6daed..0ecad8a 100755 --- a/check_bareos.py +++ b/check_bareos.py @@ -16,6 +16,9 @@ # - 1.0.1 remove 'error' tapes from expire check and correct the help description # - 1.0.2 start to rework for chosing correct query for the database type (MySQL -vs - PostgreSQL) # - 1.0.3 add port parameter for MySQL and PostgreSQL databases +# - 1.1.0 add python3 compatibility +# split import to be able to not install unnecessary dependencies +# Fixes issues with mysql connection # # Plugin check for icinga # ---------------------------------------------------- # @@ -25,7 +28,7 @@ # Constants -VERSION = '1.0.3' +VERSION = '1.1.0' # Variables databaseName = 'bareos'