Commit 3852b25a authored by Michael Friedrich's avatar Michael Friedrich
Browse files

Add python script for fetching the execution time from all services and joined hosts

parent cb7ba8ee
#!/usr/bin/env python
import requests
import json
def handle_response_execution_time(response):
execution_times = {}
results = response["results"]
for r in results:
obj_type = r["type"]
obj_name = r["name"]
obj_attrs = r["attrs"]
for attr, value in obj_attrs.iteritems():
if attr in "last_check_result" and value is not None:
execution_time = float(value["execution_end"]) - float(value["execution_start"])
execution_times[obj_name] = execution_time
# prefer joined hosts, and override them each instead of firing two queries
obj_joins = r["joins"]
for join, value in obj_joins.iteritems():
if join in "host":
cr = value["last_check_result"]
host_name = value["name"]
if cr is not None:
execution_times[host_name] = float(cr["execution_end"]) - float(cr["execution_start"])
for execution_time, obj in sorted([(value,key) for (key,value) in execution_times.items()], reverse=False):
print "Execution time: %2f seconds, Object name '%s'" % (float(execution_time), obj)
def main():
# Replace 'localhost' with your FQDN and certificate CN
# for SSL verification
#fqdn = "localhost"
fqdn = ""
port = 5665
user = "root"
password = "icinga"
request_url = "https://%s:%s/v1/objects/services" % (fqdn, port)
headers = {
'Accept': 'application/json',
'X-HTTP-Method-Override': 'GET'
data = {
"attrs": [ "name", "state", "last_check_result" ],
"joins": [ "", "host.state", "host.last_check_result" ],
r =,
auth=(user, password), # modify auth
verify="/usr/local/icinga2/etc/icinga2/pki/ca.crt") # modify trusted ca path
print "Request URL: " + str(r.url)
print "Status code: " + str(r.status_code)
if (r.status_code == 200):
print r.text
if __name__ == "__main__":
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment