mirror of
https://github.com/FAUSheppy/icinga-webhook-gateway
synced 2025-12-06 07:21:38 +01:00
Merge branch 'master' of github.com:FAUSheppy/icinga-webhook-gateway
This commit is contained in:
11
README.md
11
README.md
@@ -17,15 +17,22 @@ Services are configured in *services.json* as objects like this:
|
||||
}
|
||||
|
||||
## Client Requests
|
||||
Client must send a *POST-request* with *Content-Type: application/json* containing the service name and secret token as fields.
|
||||
Client must send a *POST-request* with *Content-Type: application/json* containing the service name, secret token and status as fields, the *'info'* field is optional.
|
||||
|
||||
For example:
|
||||
|
||||
curl -X POST \
|
||||
-H "application/json" \
|
||||
-d "{ "service_name" : "name", "token" : "secret_token" } \
|
||||
-d "{ "service_name" : "name", "token" : "secret_token", \
|
||||
"status" : "OK|WARNING|CRITICAL", "info" : "additional information" } \
|
||||
https://server:port/
|
||||
|
||||
Or directly in native python:
|
||||
|
||||
import requests
|
||||
requests.post("https://server:port/", json={"service_name" : "name", "token" : "secret_token",
|
||||
"status" : "OK|WARNING|CRITICAL", "info" : "additional information" })
|
||||
|
||||
## Icinga (Serverside) Requests
|
||||
Use the [python-script]() as a command to execute, you can pass *protocol*, *host*, *port* and *service\_name* as arguments.
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ if __name__ == "__main__":
|
||||
response = requests.get(url)
|
||||
|
||||
# check response status #
|
||||
if response.status_code == 404:
|
||||
print("The gateway does not have this service configured (404)")
|
||||
sys.exit(STATUS_UNKOWN)
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
# validate response content #
|
||||
@@ -44,7 +48,8 @@ if __name__ == "__main__":
|
||||
|
||||
if not args.service == jsonDict["service"]:
|
||||
retService = jsonDict["service"]
|
||||
print("Gateway returned wrong bad name ({} for {})".format(retService, args.service))
|
||||
fmtText = "Gateway returned wrong or bad service name ({} for {})"
|
||||
print(fmtText.format(retService, args.service))
|
||||
|
||||
# handle content #
|
||||
parsedTime = datetime.datetime.fromtimestamp(int(jsonDict["timestamp"]))
|
||||
|
||||
@@ -80,7 +80,8 @@ def default():
|
||||
sqlalchemy.desc(Status.timestamp)).first()
|
||||
|
||||
if not lastSuccess and not lastFail:
|
||||
return flask.jsonify(buildReponseDict(None))
|
||||
# service has never reported in #
|
||||
return flask.jsonify(buildReponseDict(None, service=service))
|
||||
elif not lastSuccess and lastFail:
|
||||
return flask.jsonify(buildReponseDict(lastFail))
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user