Skip to content

Commit

Permalink
Fix wrong query in checkruntimejobs
Browse files Browse the repository at this point in the history
 - The query assumed a string and used LIKE, probably from an older
 iteration of the plugin. Now uses IN syntax to support multiple states
  • Loading branch information
martialblog committed Sep 23, 2024
1 parent bd40556 commit 274a299
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions check_bareos.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def checkRunTimeJobs(cursor, state, time, warning, critical):
query = """
SELECT Count(Job.Name)
FROM Job
WHERE starttime < (now()::date-""" + str(time) + """ * '1 day'::INTERVAL) AND Job.JobStatus like '""" + state + """';
WHERE starttime < (now()::date-""" + str(time) + """ * '1 day'::INTERVAL) AND Job.JobStatus in (""" + state + """);
"""

cursor.execute(query)
Expand All @@ -405,7 +405,7 @@ def checkRunTimeJobs(cursor, state, time, warning, critical):
checkState["returnCode"] = OK
checkState["returnMessage"] = "[OK]"

checkState["returnMessage"] += " - " + str(result) + " Jobs are running longer than " + str(time) + " days"
checkState["returnMessage"] += " - " + str(result) + " Jobs in state " + state.replace("'", "") + " are running longer than " + str(time) + " days"

checkState["performanceData"] = "bareos.job.count=" + str(result) + ";" + str(warning) + ";" + str(critical) + ";;"

Expand Down
7 changes: 4 additions & 3 deletions test_check_bareos.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,16 @@ def test_checkRunTimeJobs(self):

c.fetchone.return_value = [2]
actual = checkRunTimeJobs(c, "'F','I','D'", 1, Threshold(3), Threshold(5))
expected = {'returnCode': 0, 'returnMessage': '[OK] - 2.0 Jobs are running longer than 1 days', 'performanceData': 'bareos.job.count=2.0;3;5;;'}
c.execute.assert_called_with("\n SELECT Count(Job.Name)\n FROM Job\n WHERE starttime < (now()::date-1 * '1 day'::INTERVAL) AND Job.JobStatus in ('F','I','D');\n ")

expected = {'returnCode': 0, 'returnMessage': '[OK] - 2.0 Jobs in state F,I,D are running longer than 1 days', 'performanceData': 'bareos.job.count=2.0;3;5;;'}
self.assertEqual(actual, expected)

c.fetchone.return_value = [10]
actual = checkRunTimeJobs(c, "'F','I','D'", 1, Threshold(3), Threshold(5))
expected = {'returnCode': 2, 'returnMessage': '[CRITICAL] - 10.0 Jobs are running longer than 1 days', 'performanceData': 'bareos.job.count=10.0;3;5;;'}
expected = {'returnCode': 2, 'returnMessage': '[CRITICAL] - 10.0 Jobs in state F,I,D are running longer than 1 days', 'performanceData': 'bareos.job.count=10.0;3;5;;'}
self.assertEqual(actual, expected)


def test_checkEmptyBackups(self):

c = mock.MagicMock()
Expand Down

0 comments on commit 274a299

Please sign in to comment.