Skip to content

Commit e1bd867

Browse files
committed
Change the logic to determine sync status and move to more standard Nagios levels
1 parent 5660033 commit e1bd867

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

monitoring/db_update_sqlite.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django.db import DatabaseError
1313
import pandas as pd
1414
from django.utils.timezone import make_aware, is_naive
15+
from datetime import datetime
1516

1617

1718
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
@@ -138,15 +139,34 @@ def determine_sync_status(f):
138139
"""
139140
Helper to determine sync status between published and the database record counts.
140141
"""
142+
if is_current_month(f):
143+
return "OK [ Current month ]"
144+
141145
RecordCountPublished = f.get("RecordCountPublished")
142146
RecordCountInDb = f.get("RecordCountInDb")
143-
rel_diff1 = abs(RecordCountPublished - RecordCountInDb)/RecordCountInDb
144-
rel_diff2 = abs(RecordCountPublished - RecordCountInDb)/RecordCountPublished
145-
if rel_diff1 < 0.01 or rel_diff2 < 0.01:
146-
syncstatus = "OK"
147-
else:
148-
syncstatus = "ERROR [ Please use the Gap Publisher to synchronise this dataset]"
149-
return syncstatus
147+
148+
# catches None or zero
149+
if not RecordCountPublished or not RecordCountInDb:
150+
return "WARNING [ Invalid record counts ]"
151+
152+
diff = abs(RecordCountPublished - RecordCountInDb)
153+
rel_diff1 = diff/RecordCountInDb
154+
rel_diff2 = diff/RecordCountPublished
155+
if RecordCountPublished > RecordCountInDb or rel_diff1 < 0.01 or rel_diff2 < 0.01:
156+
return "OK"
157+
158+
return "WARNING [ Please try to republish the missing data or raise a GGUS ticket ]"
159+
160+
161+
def is_current_month(f):
162+
month = f.get("Month")
163+
year = f.get("Year")
164+
165+
if month is None or year is None:
166+
return False
167+
168+
now = datetime.now()
169+
return now.month == month and now.year == year
150170

151171

152172
def refresh_gridsite():

0 commit comments

Comments
 (0)