diff --git a/.gitignore b/.gitignore index ba74660..580c0c8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ __pycache__/ # Distribution / packaging .Python env/ +venv/ +.venv/ build/ develop-eggs/ dist/ diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..ea1844b --- /dev/null +++ b/.pylintrc @@ -0,0 +1,18 @@ +# pylint config +[FORMAT] +good-names=m,p,ok +[MESSAGES CONTROL] +disable=fixme, + consider-using-f-string, + import-outside-toplevel, + inconsistent-return-statements, + invalid-name, + line-too-long, + missing-class-docstring, + missing-function-docstring, + missing-module-docstring, + redefined-outer-name, + too-many-arguments, + too-many-branches, + too-many-locals, + too-many-statements diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..720ef9a --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +.PHONY: lint test + +lint: + python -m pylint check_bareos +test: + python -m unittest -v -b diff --git a/README.md b/README.md index 1abfc09..36ca295 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,22 @@ # check_bareos -Icinga Monitoring Plugin to check Bareos Backup Director databases -Main Git Repository: https://github.com/widhalmt/check_bareos -At the moment this is a fork repository to make it to a synchronized project with thise site. +Icinga Monitoring Plugin to check Bareos Backup Director databases -This project is mainly aimed at fixing some bugs. +## Setup -If you want to add features contribute in the git project or sent an email to the author or git repository owner. +Requires Python 3 to be installed. +Depending on your database setup either `requirements-mysql.txt` or `requirements-postgres.txt` needs to be installed. -## Check Examples: +# Examples Note: use the postgresql database bareos and login without password - -#### Check if a full backup has 0 Bytes(is Empty) and trigger warning it is at least 1 and trigger ciritcal if more than 5 are empty +#### Check if a full backup has 0 Bytes(is Empty) and trigger warning it is at least 1 and trigger ciritcal if more than 5 are empty ```check_bareos.py -u bareos -d p status -e -f -w 1 -c 5``` -##### Check if a diff/inc backup is larger than 2 TB (default value) and trigger warning it is at least 1 and trigger ciritcal if more than 5 are empty +#### Check if a diff/inc backup is larger than 2 TB (default value) and trigger warning it is at least 1 and trigger ciritcal if more than 5 are empty ```check_bareos.py -u bareos -d p status -o -d -i -w 1 -c 5``` @@ -56,6 +54,3 @@ Note: use the postgresql database bareos and login without password #### Check how much tapes will expire in the next 14 days ```check_bareos.py -u bareos -d p tape -wex -t 14 -w 10 -c 5``` - - - diff --git a/check_bareos.py b/check_bareos.py index 146c8e2..7291c29 100755 --- a/check_bareos.py +++ b/check_bareos.py @@ -1,41 +1,42 @@ -#!/usr/bin/python +#!/usr/bin/python3 # ---------------------------------------------------- # # File : check_bareos # Author : Philipp Posovszky, DLR # E-Mail: Philipp.Posovszky@dlr.de # Date : 22/04/2015 -# +# # Modifications : Thomas Widhalm, NETways GmbH # E-Mail: widhalmt@widhalm.or.at # -# Version: 1.0.3 -# # This program is free software; you can redistribute it or modify # it under the terms of the GNU General Public License version 3.0 # # Changelog: -# - 1.0.1 remove 'error' tapes from expire check and correct the help description +# - 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.1.0' # Variables databaseName = 'bareos' # Used to differentiate between database specific queries databaseType = 'mysql' + def createBackupKindString(full, inc, diff): - if full == False and inc == False and diff == False: + if full is False and inc is False and diff is False: return "'F','D','I'" kind = [] if full: @@ -43,7 +44,7 @@ def createBackupKindString(full, inc, diff): if inc: kind.append("'I'") if diff: - kind.append("'D'") + kind.append("'D'") return ",".join(kind) @@ -66,10 +67,10 @@ def getState(state): def checkFailedBackups(courser, time, warning, critical): checkState = {} - if time == None: + if time is None: time = 7 # MySQL needs other Queries than PostgreSQL - if(databaseType == "psql"): + if databaseType == "psql": query = """ SELECT Job.Name,Level,starttime, JobStatus FROM Job @@ -87,151 +88,156 @@ def checkFailedBackups(courser, time, warning, critical): result = len(results) if result >= int(critical): - checkState["returnCode"] = 2 - checkState["returnMessage"] = "CRITICAL - " + str(result) + " Backups failed/canceled last " + str(time) + " days" + checkState["returnCode"] = 2 + checkState["returnMessage"] = "CRITICAL - " + str(result) + " Backups failed/canceled last " + str(time) + " days" elif result >= int(warning): - checkState["returnCode"] = 1 - checkState["returnMessage"] = "WARNING - " + str(result) + " Backups failed/canceled last " + str(time) + " days" + checkState["returnCode"] = 1 + checkState["returnMessage"] = "WARNING - " + str(result) + " Backups failed/canceled last " + str(time) + " days" else: - checkState["returnCode"] = 0 - checkState["returnMessage"] = "OK - Only " + str(result) + " Backups failed in the last " + str(time) + " days" + checkState["returnCode"] = 0 + checkState["returnMessage"] = "OK - Only " + str(result) + " Backups failed in the last " + str(time) + " days" + checkState["performanceData"] = "Failed=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" - - return checkState - - + return checkState - + def checkBackupSize(courser, time, kind, factor): - if time != None: - # MySQL needs other Queries than PostgreSQL - if(databaseType == "psql"): - query = """ - SELECT ROUND(SUM(JobBytes/""" + str(float(factor)) + """),3) - FROM Job - Where Level in (""" + kind + """) and starttime > (now()-""" + str(time) + """ * '1 day'::INTERVAL) ; - """ - # According to --help output MySQL is the default - else: - query = """ - SELECT ROUND(SUM(JobBytes/""" + str(float(factor)) + """),3) - FROM Job - Where Level in (""" + kind + """) and starttime > DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY); - """ - courser.execute(query) - results = courser.fetchone() # Returns a value - return results[0] - else: - query = """ - SELECT ROUND(SUM(JobBytes/""" + str(float(factor)) + """),3) - FROM Job - Where Level in (""" + kind + """); - """ - courser.execute(query) - results = courser.fetchone() # Returns a value - return results[0] - + if time is not None: + # MySQL needs other Queries than PostgreSQL + if databaseType == "psql": + query = """ + SELECT ROUND(SUM(JobBytes/""" + str(float(factor)) + """),3) + FROM Job + Where Level in (""" + kind + """) and starttime > (now()-""" + str(time) + """ * '1 day'::INTERVAL) ; + """ + # According to --help output MySQL is the default + else: + query = """ + SELECT ROUND(SUM(JobBytes/""" + str(float(factor)) + """),3) + FROM Job + Where Level in (""" + kind + """) and starttime > DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY); + """ + courser.execute(query) + results = courser.fetchone() # Returns a value + return results[0] + + query = """ + SELECT ROUND(SUM(JobBytes/""" + str(float(factor)) + """),3) + FROM Job + Where Level in (""" + kind + """); + """ + courser.execute(query) + results = courser.fetchone() # Returns a value + + return results[0] + def checkTotalBackupSize(cursor, time, kind, unit, warning, critical): - checkState = {} - result = checkBackupSize(cursor, time, kind, createFactor(unit)) - if result >= int(critical): - checkState["returnCode"] = 2 - if args.time: - checkState["returnMessage"] = "CRITICAL - " + str(result) + " " + unit + " Kind:" + kind + " Days: " + str(time) - else: - checkState["returnMessage"] = "CRITICAL - " + str(result) + " " + unit + " Kind:" + kind - elif result >= int(warning): - checkState["returnCode"] = 1 - if args.time: - checkState["returnMessage"] = "WARNING - " + str(result) + " " + unit + " Kind:" + kind + " Days: " + str(time) - else: - checkState["returnMessage"] = "WARNING - " + str(result) + " " + unit + " Kind:" + kind - else: - checkState["returnCode"] = 0 - if args.time: - checkState["returnMessage"] = "OK - " + str(result) + " " + unit + " Kind:" + kind + " Days: " + str(time) - else: - checkState["returnMessage"] = "OK - " + str(result) + " " + unit + " Kind:" + kind - checkState["performanceData"] = "Size=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" - return checkState - + checkState = {} + result = checkBackupSize(cursor, time, kind, createFactor(unit)) + if result >= int(critical): + checkState["returnCode"] = 2 + if args.time: + checkState["returnMessage"] = "CRITICAL - " + str(result) + " " + unit + " Kind:" + kind + " Days: " + str(time) + else: + checkState["returnMessage"] = "CRITICAL - " + str(result) + " " + unit + " Kind:" + kind + elif result >= int(warning): + checkState["returnCode"] = 1 + if args.time: + checkState["returnMessage"] = "WARNING - " + str(result) + " " + unit + " Kind:" + kind + " Days: " + str(time) + else: + checkState["returnMessage"] = "WARNING - " + str(result) + " " + unit + " Kind:" + kind + else: + checkState["returnCode"] = 0 + if args.time: + checkState["returnMessage"] = "OK - " + str(result) + " " + unit + " Kind:" + kind + " Days: " + str(time) + else: + checkState["returnMessage"] = "OK - " + str(result) + " " + unit + " Kind:" + kind + + checkState["performanceData"] = "Size=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" + + return checkState + def checkOversizedBackups(courser, time, size, kind, unit, warning, critical): - checkState = {} - if time == None: - time = 7 - factor = createFactor(unit) - # MySQL needs other Queries than PostgreSQL - if(databaseType == "psql"): - query = """ - SELECT Job.Name,Level,starttime, JobBytes/""" + str(float(factor)) + """ - FROM Job - Where Level in (""" + kind + """) and starttime > (now()::date-""" + str(time) + """ * '1 day'::INTERVAL) and JobBytes/""" + str(float(factor)) + """>""" + str(size) + """; - """ - # MySQL is the default - else: - query = """ - SELECT Job.Name,Level,starttime, JobBytes/""" + str(float(factor)) + """ - FROM Job - Where Level in (""" + kind + """) and starttime > DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY) and JobBytes/""" + str(float(factor)) + """>""" + str(size) + """; - """ - courser.execute(query) - results = courser.fetchall() # Returns a value - result = len(results) - - if result >= int(critical): - checkState["returnCode"] = 2 - checkState["returnMessage"] = "CRITICAL - " + str(result) + " " + kind + " Backups larger than " + str(size) + " " + unit + " in the last " + str(time) + " days" - elif result >= int(warning): - checkState["returnCode"] = 1 - checkState["returnMessage"] = "WARNING - " + str(result) + " " + kind + " Backups larger than " + str(size) + " " + unit + " in the last " + str(time) + " days" - else: - checkState["returnCode"] = 0 - checkState["returnMessage"] = "OK - No " + kind + " Backup larger than " + str(size) + " " + unit + " in the last " + str(time) + " days" - checkState["performanceData"] = "OverSized=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" - return checkState + checkState = {} + if time is None: + time = 7 + factor = createFactor(unit) + # MySQL needs other Queries than PostgreSQL + if databaseType == "psql": + query = """ + SELECT Job.Name,Level,starttime, JobBytes/""" + str(float(factor)) + """ + FROM Job + Where Level in (""" + kind + """) and starttime > (now()::date-""" + str(time) + """ * '1 day'::INTERVAL) and JobBytes/""" + str(float(factor)) + """>""" + str(size) + """; + """ + # MySQL is the default + else: + query = """ + SELECT Job.Name,Level,starttime, JobBytes/""" + str(float(factor)) + """ + FROM Job + Where Level in (""" + kind + """) and starttime > DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY) and JobBytes/""" + str(float(factor)) + """>""" + str(size) + """; + """ + courser.execute(query) + results = courser.fetchall() # Returns a value + result = len(results) + + if result >= int(critical): + checkState["returnCode"] = 2 + checkState["returnMessage"] = "CRITICAL - " + str(result) + " " + kind + " Backups larger than " + str(size) + " " + unit + " in the last " + str(time) + " days" + elif result >= int(warning): + checkState["returnCode"] = 1 + checkState["returnMessage"] = "WARNING - " + str(result) + " " + kind + " Backups larger than " + str(size) + " " + unit + " in the last " + str(time) + " days" + else: + checkState["returnCode"] = 0 + checkState["returnMessage"] = "OK - No " + kind + " Backup larger than " + str(size) + " " + unit + " in the last " + str(time) + " days" + + checkState["performanceData"] = "OverSized=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" + + return checkState def checkEmptyBackups(cursor, time, kind, warning, critical): - checkState = {} - if time == None: - time = 7 - # MySQL needs other Queries than PostgreSQL - if(databaseType == "psql"): - query = """ - SELECT Job.Name,Level,starttime - FROM Job - Where Level in (""" + str(kind) + """) and JobBytes=0 and starttime > (now()::date-""" + str(time) + """ * '1 day'::INTERVAL) and JobStatus in ('T'); - """ - # MySQL is the default - else: - query = """ - SELECT Job.Name,Level,starttime - FROM Job - Where Level in (""" + str(kind) + """) and JobBytes=0 and starttime > DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY) and JobStatus in ('T'); - """ - cursor.execute(query) - results = cursor.fetchall() # Returns a value - result = len(results) - - if result >= int(critical): - checkState["returnCode"] = 2 - checkState["returnMessage"] = "CRITICAL - " + str(result) + " successful " + str(kind) + " backups are empty" - elif result >= int(warning): - checkState["returnCode"] = 1 - checkState["returnMessage"] = "WARNING - " + str(result) + " successful " + str(kind) + " backups are empty!" - else: - checkState["returnCode"] = 0 - checkState["returnMessage"] = "OK - All " + str(kind) + " backups are fine" - checkState["performanceData"] = "EmptyBackups=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" - return checkState - + checkState = {} + if time is None: + time = 7 + # MySQL needs other Queries than PostgreSQL + if databaseType == "psql": + query = """ + SELECT Job.Name,Level,starttime + FROM Job + Where Level in (""" + str(kind) + """) and JobBytes=0 and starttime > (now()::date-""" + str(time) + """ * '1 day'::INTERVAL) and JobStatus in ('T'); + """ + # MySQL is the default + else: + query = """ + SELECT Job.Name,Level,starttime + FROM Job + Where Level in (""" + str(kind) + """) and JobBytes=0 and starttime > DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY) and JobStatus in ('T'); + """ + cursor.execute(query) + results = cursor.fetchall() # Returns a value + result = len(results) + + if result >= int(critical): + checkState["returnCode"] = 2 + checkState["returnMessage"] = "CRITICAL - " + str(result) + " successful " + str(kind) + " backups are empty" + elif result >= int(warning): + checkState["returnCode"] = 1 + checkState["returnMessage"] = "WARNING - " + str(result) + " successful " + str(kind) + " backups are empty!" + else: + checkState["returnCode"] = 0 + checkState["returnMessage"] = "OK - All " + str(kind) + " backups are fine" + + checkState["performanceData"] = "EmptyBackups=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" + + return checkState + # Checks on Jobs def checkJobs(cursor, state, kind, time, warning, critical): checkState = {} - if time == None: + if time is None: time = 7 # MySQL needs other Queries than PostgreSQL - if(databaseType == "psql"): + if databaseType == "psql": query = """ Select count(Job.Name) From Job @@ -245,28 +251,29 @@ def checkJobs(cursor, state, kind, time, warning, critical): Where Job.JobStatus like '"""+str(state)+"""' and (starttime > DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY) or starttime IS NULL) and Job.Level in ("""+kind+"""); """ cursor.execute(query) - results = cursor.fetchone() # Returns a value + results = cursor.fetchone() # Returns a value result = float(results[0]) if result >= int(critical): - checkState["returnCode"] = 2 - checkState["returnMessage"] = "CRITICAL - " + str(result) + " Jobs are in the state: "+str(getState(state)) + checkState["returnCode"] = 2 + checkState["returnMessage"] = "CRITICAL - " + str(result) + " Jobs are in the state: "+str(getState(state)) elif result >= int(warning): - checkState["returnCode"] = 1 - checkState["returnMessage"] = "WARNING - " + str(result) + " Jobs are in the state: "+str(getState(state)) + checkState["returnCode"] = 1 + checkState["returnMessage"] = "WARNING - " + str(result) + " Jobs are in the state: "+str(getState(state)) else: - checkState["returnCode"] = 0 - checkState["returnMessage"] = "OK - " + str(result) + " Jobs are in the state: "+str(getState(state)) + checkState["returnCode"] = 0 + checkState["returnMessage"] = "OK - " + str(result) + " Jobs are in the state: "+str(getState(state)) + checkState["performanceData"] = str(getState(state))+"=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" return checkState def checkSingleJob(cursor, name, state, kind, time, warning, critical): checkState = {} - if time == None: + if time is None: time = 7 # MySQL needs other Queries than PostgreSQL - if(databaseType == "psql"): + if databaseType == "psql": query = """ Select Job.Name,Job.JobStatus, Job.Starttime FROm Job @@ -280,28 +287,29 @@ def checkSingleJob(cursor, name, state, kind, time, warning, critical): Where Job.Name like '%"""+name+"""%' and Job.JobStatus like '"""+state+"""' and (starttime > DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY) or starttime IS NULL) and Job.Level in ("""+kind+"""); """ cursor.execute(query) - results = cursor.fetchall() # Returns a value + results = cursor.fetchall() # Returns a value result = len(results) if result >= int(critical): - checkState["returnCode"] = 2 - checkState["returnMessage"] = "CRITICAL - " + str(result) + " Jobs are in the state: "+str(getState(state)) + checkState["returnCode"] = 2 + checkState["returnMessage"] = "CRITICAL - " + str(result) + " Jobs are in the state: "+str(getState(state)) elif result >= int(warning): - checkState["returnCode"] = 1 - checkState["returnMessage"] = "WARNING - " + str(result) + " Jobs are in the state: "+str(getState(state)) + checkState["returnCode"] = 1 + checkState["returnMessage"] = "WARNING - " + str(result) + " Jobs are in the state: "+str(getState(state)) else: - checkState["returnCode"] = 0 - checkState["returnMessage"] = "OK - " + str(result) + " Jobs are in the state: "+str(getState(state)) + checkState["returnCode"] = 0 + checkState["returnMessage"] = "OK - " + str(result) + " Jobs are in the state: "+str(getState(state)) + checkState["performanceData"] = str(getState(state))+"=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" return checkState -def checkRunTimeJobs(cursor,name,state,time,warning,critical): +def checkRunTimeJobs(cursor,state,time,warning,critical): checkState = {} - if time == None: + if time is None: time = 7 # MySQL needs other Queries than PostgreSQL - if(databaseType == "psql"): + if databaseType == "psql": query = """ Select Count(Job.Name) FROm Job @@ -315,23 +323,24 @@ def checkRunTimeJobs(cursor,name,state,time,warning,critical): Where starttime < DATE_SUB(now(), INTERVAL """ + str(time) + """ DAY) and Job.JobStatus like '"""+state+"""'; """ cursor.execute(query) - results = cursor.fetchone() # Returns a value + results = cursor.fetchone() # Returns a value result = float(results[0]) if result >= int(critical): - checkState["returnCode"] = 2 - checkState["returnMessage"] = "CRITICAL - " + str(result) + " Jobs are running longer than "+str(time)+" days" + checkState["returnCode"] = 2 + checkState["returnMessage"] = "CRITICAL - " + str(result) + " Jobs are running longer than "+str(time)+" days" elif result >= int(warning): - checkState["returnCode"] = 1 - checkState["returnMessage"] = "WARNING - " + str(result) + " Jobs are running longer than "+str(time)+" days" + checkState["returnCode"] = 1 + checkState["returnMessage"] = "WARNING - " + str(result) + " Jobs are running longer than "+str(time)+" days" else: - checkState["returnCode"] = 0 - checkState["returnMessage"] = "OK - " + str(result) + " Jobs are running longer than "+str(time)+" days" + checkState["returnCode"] = 0 + checkState["returnMessage"] = "OK - " + str(result) + " Jobs are running longer than "+str(time)+" days" + checkState["performanceData"] = "Count=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" return checkState - + # Checks on Tapes def checkTapesInStorage(cursor, warning, critical): checkState = {} @@ -344,9 +353,9 @@ def checkTapesInStorage(cursor, warning, critical): AND Media.StorageId=Storage.StorageId; """ cursor.execute(query) - results = cursor.fetchone() # Returns a value + results = cursor.fetchone() # Returns a value result = float(results[0]) - + if result <= int(critical): checkState["returnCode"] = 2 checkState["returnMessage"] = "CRITICAL - Only " + str(result) + " Tapes are in the Storage" @@ -367,20 +376,21 @@ def checkExpiredTapes(cursor, warning, critical): WHERE lastwritten+(media.volretention * '1 second'::INTERVAL)now() and volstatus not like 'Error';; """ cursor.execute(query) - results = cursor.fetchone() # Returns a value + results = cursor.fetchone() # Returns a value result = float(results[0]) - + if result <= int(critical): - checkState["returnCode"] = 2 - checkState["returnMessage"] = "CRITICAL - Only " + str(result) + " will expire in next " + str(time) + " days" + checkState["returnCode"] = 2 + checkState["returnMessage"] = "CRITICAL - Only " + str(result) + " will expire in next " + str(time) + " days" elif result <= int(warning): - checkState["returnCode"] = 1 - checkState["returnMessage"] = "WARNING - Only " + str(result) + " will expire in next " + str(time) + " days" + checkState["returnCode"] = 1 + checkState["returnMessage"] = "WARNING - Only " + str(result) + " will expire in next " + str(time) + " days" else: - checkState["returnCode"] = 0 - checkState["returnMessage"] = "OK - Tapes " + str(result) + " will expire in next " + str(time) + " days" + checkState["returnCode"] = 0 + checkState["returnMessage"] = "OK - Tapes " + str(result) + " will expire in next " + str(time) + " days" + checkState["performanceData"] = "Expire=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" - + return checkState def checkReplaceTapes(cursor, mounts, warning, critical): @@ -417,111 +428,115 @@ def checkReplaceTapes(cursor, mounts, warning, critical): (VolStatus='Disabled'); """ cursor.execute(query) - results = cursor.fetchone() # Returns a value + results = cursor.fetchone() # Returns a value result = float(results[0]) if result >= int(critical): - checkState["returnCode"] = 2 - checkState["returnMessage"] = "CRITICAL - " + str(result) + " Tapes have to be replaced in the near future" + checkState["returnCode"] = 2 + checkState["returnMessage"] = "CRITICAL - " + str(result) + " Tapes have to be replaced in the near future" elif result >= int(warning): - checkState["returnCode"] = 1 - checkState["returnMessage"] = "WARNING - Only " + str(result) + " Tapes have to be replaced in the near future" + checkState["returnCode"] = 1 + checkState["returnMessage"] = "WARNING - Only " + str(result) + " Tapes have to be replaced in the near future" else: - checkState["returnCode"] = 0 - checkState["returnMessage"] = "OK - Tapes " + str(result) + " have to be replaced in the near future" + checkState["returnCode"] = 0 + checkState["returnMessage"] = "OK - Tapes " + str(result) + " have to be replaced in the near future" + checkState["performanceData"] = "Replace=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;" - return checkState + return checkState + + - - def checkEmptyTapes(courser, warning, critical): - checkState = {} - query = """ - SELECT Count(MediaId) - FROM Media,Pool,Storage - WHERE Media.PoolId=Pool.PoolId - AND Slot>0 AND InChanger=1 - AND Media.StorageId=Storage.StorageId - AND (VolStatus like 'Purged' or VolStatus like 'Recycle' or lastwritten+(media.volretention * '1 second'::INTERVAL)0 AND InChanger=1 + AND Media.StorageId=Storage.StorageId + AND (VolStatus like 'Purged' or VolStatus like 'Recycle' or lastwritten+(media.volretention * '1 second'::INTERVAL)