mirror of
https://github.com/FAUSheppy/icinga-webhook-gateway
synced 2025-12-09 08:48:38 +01:00
implement service timeout check
This commit is contained in:
14
server.py
14
server.py
@@ -14,6 +14,8 @@ from sqlalchemy.sql import func
|
|||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
import pytimeparse.timeparse as timeparse
|
||||||
|
|
||||||
app = flask.Flask("Icinga Report In Gateway")
|
app = flask.Flask("Icinga Report In Gateway")
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
|
||||||
app.config['JSON_CONFIG_FILE'] = 'services.json'
|
app.config['JSON_CONFIG_FILE'] = 'services.json'
|
||||||
@@ -69,6 +71,18 @@ def additionalDates():
|
|||||||
if not status:
|
if not status:
|
||||||
response = flask.Response("", 200, json=buildReponseDict(status, service=service))
|
response = flask.Response("", 200, json=buildReponseDict(status, service=service))
|
||||||
else:
|
else:
|
||||||
|
if status.status == "OK":
|
||||||
|
timeParsed = datetime.datetime.from_timestamp(status.timestamp)
|
||||||
|
delta = datetime.datetime.now() - timeParsed
|
||||||
|
timeout = timeparse.timeparse(serviceObj.timeout)
|
||||||
|
if not status.timestamp == 0 and timeout < delta:
|
||||||
|
status.info_text = "Service {} overdue since {}".format(service, delta.hours)
|
||||||
|
if timeout/delta > 0.9 or (delta-timeout).hours < 12:
|
||||||
|
status.status = "WARNING"
|
||||||
|
else:
|
||||||
|
status.status = "CRITICAL"
|
||||||
|
|
||||||
|
|
||||||
response = flask.Response("", 200, json=buildReponseDict(status))
|
response = flask.Response("", 200, json=buildReponseDict(status))
|
||||||
|
|
||||||
# finalize and return response #
|
# finalize and return response #
|
||||||
|
|||||||
Reference in New Issue
Block a user