diff --git a/README.md b/README.md index 9694afa..17ed129 100644 --- a/README.md +++ b/README.md @@ -17,14 +17,21 @@ 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. diff --git a/icinga-gateway-command.py b/icinga-gateway-command.py index 9c14e95..85e81ed 100755 --- a/icinga-gateway-command.py +++ b/icinga-gateway-command.py @@ -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"])) diff --git a/server.py b/server.py index ec12ad3..5c3c6a4 100755 --- a/server.py +++ b/server.py @@ -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: