Skip to content

Commit

Permalink
[WIP] fix queries with states
Browse files Browse the repository at this point in the history
  • Loading branch information
martialblog committed Sep 23, 2024
1 parent 274a299 commit c63d0dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion check_bareos.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def checkSingleJob(cursor, name, state, kind, time, warning, critical):
query = """
SELECT Job.Name,Job.JobStatus, Job.Starttime
FROM Job
WHERE Job.Name like '%"""+name+"""%' AND Job.JobStatus like '"""+state+"""' AND (starttime > (now()::date-"""+str(time)+""" * '1 day'::INTERVAL) OR starttime IS NULL) AND Job.Level in ("""+kind+""");
WHERE Job.Name like '%"""+name+"""%' AND Job.JobStatus in ("""+state+""") AND (starttime > (now()::date-"""+str(time)+""" * '1 day'::INTERVAL) OR starttime IS NULL) AND Job.Level in ("""+kind+""");
"""

cursor.execute(query)
Expand Down
4 changes: 2 additions & 2 deletions test_check_bareos.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ def test_checkSingleJob(self):

# Nothing returned from DB
c.fetchall.return_value = []
actual = checkSingleJob(c, "Jobby", "E", "'F','I','D'", 1, Threshold(1), Threshold(2))
actual = checkSingleJob(c, "Jobby", "'E'", "'F','I','D'", 1, Threshold(1), Threshold(2))
expected = {'performanceData': "'bareos.Job terminated in error'=0;1;2;;", 'returnCode': 0, 'returnMessage': '[OK] - 0 Jobs are in the state: Job terminated in error'}
self.assertEqual(actual, expected)

c.execute.assert_called_with("\n SELECT Job.Name,Job.JobStatus, Job.Starttime\n FROM Job\n WHERE Job.Name like '%Jobby%' AND Job.JobStatus like 'E' AND (starttime > (now()::date-1 * '1 day'::INTERVAL) OR starttime IS NULL) AND Job.Level in ('F','I','D');\n ")
c.execute.assert_called_with("\n SELECT Job.Name,Job.JobStatus, Job.Starttime\n FROM Job\n WHERE Job.Name like '%Jobby%' AND Job.JobStatus in ('E') AND (starttime > (now()::date-1 * '1 day'::INTERVAL) OR starttime IS NULL) AND Job.Level in ('F','I','D');\n ")

# Missing Name
actual = checkSingleJob(c, None, "T", "'F','I','D'", 1, Threshold(1), Threshold(2))
Expand Down

0 comments on commit c63d0dc

Please sign in to comment.