Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions check_bareos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements-mysql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mysqlclient==2.1.1
1 change: 0 additions & 1 deletion requirements.txt → requirements-postgres.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
mysqlclient==2.1.1
psycopg2-binary==2.9.3