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,14 +17,21 @@ Services are configured in *services.json* as objects like this:
|
|||||||
}
|
}
|
||||||
|
|
||||||
## Client Requests
|
## 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:
|
For example:
|
||||||
|
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-H "application/json" \
|
-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/
|
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
|
## Icinga (Serverside) Requests
|
||||||
Use the [python-script]() as a command to execute, you can pass *protocol*, *host*, *port* and *service\_name* as arguments.
|
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)
|
response = requests.get(url)
|
||||||
|
|
||||||
# check response status #
|
# 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()
|
response.raise_for_status()
|
||||||
|
|
||||||
# validate response content #
|
# validate response content #
|
||||||
@@ -44,7 +48,8 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
if not args.service == jsonDict["service"]:
|
if not args.service == jsonDict["service"]:
|
||||||
retService = 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 #
|
# handle content #
|
||||||
parsedTime = datetime.datetime.fromtimestamp(int(jsonDict["timestamp"]))
|
parsedTime = datetime.datetime.fromtimestamp(int(jsonDict["timestamp"]))
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ def default():
|
|||||||
sqlalchemy.desc(Status.timestamp)).first()
|
sqlalchemy.desc(Status.timestamp)).first()
|
||||||
|
|
||||||
if not lastSuccess and not lastFail:
|
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:
|
elif not lastSuccess and lastFail:
|
||||||
return flask.jsonify(buildReponseDict(lastFail))
|
return flask.jsonify(buildReponseDict(lastFail))
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user