Skip to content

Commit ee6b9c5

Browse files
Merge pull request #84 from garaimanoj/gt-1296
Change the logic to determine sync status and move to more standard Nagios levels
2 parents 26f586b + c9c4add commit ee6b9c5

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
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():

monitoring/publishing/templates/gridsync.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ <h3>APEL Synchronisation Test</h3>
3838
<td>{{ record.YearMonth }}</td>
3939
<td>{{ record.RecordStart }}</td>
4040
<td>{{ record.RecordEnd }}</td>
41-
<td>{{ record.RecordCountPublished|intcomma }}</td>
4241
<td>{{ record.RecordCountInDb|intcomma }}</td>
42+
<td>{{ record.RecordCountPublished|intcomma }}</td>
4343
<td>{{ record.SyncStatus }}</td>
4444
</tr>
4545
{% endfor %}

monitoring/publishing/templates/gridsync_singlesite.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ <h3>APEL Synchronisation Test</h3>
3838
</td>
3939
<td>{{ record.RecordStart }}</td>
4040
<td>{{ record.RecordEnd }}</td>
41-
<td>{{ record.RecordCountPublished|intcomma }}</td>
4241
<td>{{ record.RecordCountInDb|intcomma }}</td>
42+
<td>{{ record.RecordCountPublished|intcomma }}</td>
4343
<td>{{ record.SyncStatus }}</td>
4444
</tr>
4545
{% endfor %}

monitoring/publishing/templates/gridsync_submithost.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ <h3>APEL Synchronisation Test</h3>
3737
<td>{{ host.SubmitHost }}</td>
3838
<td>{{ host.RecordStart }}</td>
3939
<td>{{ host.RecordEnd }}</td>
40-
<td>{{ host.RecordCountPublished|intcomma }}</td>
4140
<td>{{ host.RecordCountInDb|intcomma }}</td>
41+
<td>{{ host.RecordCountPublished|intcomma }}</td>
4242
</tr>
4343
{% endfor %}
4444
</table>

0 commit comments

Comments
 (0)