diff --git a/check_bareos.py b/check_bareos.py index 303da50..0ecad8a 100755 --- a/check_bareos.py +++ b/check_bareos.py @@ -16,20 +16,19 @@ # - 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 # ---------------------------------------------------- # import argparse -import psycopg2 -import psycopg2.extras import sys import subprocess -import MySQLdb # Constants -VERSION = '1.0.3' +VERSION = '1.1.0' # Variables databaseName = 'bareos' @@ -473,6 +472,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 +491,9 @@ 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) + return conn.cursor() 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