3 # Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 import subprocess, json
21 inventory_json = subprocess.check_output(["icinga2-list-agents", "--batch"])
22 inventory = json.loads(inventory_json)
24 for agent, agent_info in inventory.items():
25 print "object Endpoint \"%s\" {" % (agent)
26 print " host = \"%s\"" % (agent)
29 print "object Zone \"%s\" {" % (agent_info["zone"])
30 if "parent_zone" in agent_info:
31 print " parent = \"%s\"" % (agent_info["parent_zone"])
32 print " endpoints = [ \"%s\" ]" % (agent)
36 print "object Host \"%s\" {" % (agent_info["zone"])
37 print " check_command = \"cluster-zone\""
41 print "apply Dependency \"host-zone-%s\" to Host {" % (agent_info["zone"])
42 print " parent_host_name = \"%s\"" % (agent_info["zone"])
43 print " assign where host.@zone == \"%s\"" % (agent_info["zone"])
47 print "apply Dependency \"service-zone-%s\" to Service {" % (agent_info["zone"])
48 print " parent_host_name = \"%s\"" % (agent_info["zone"])
49 print " assign where service.@zone == \"%s\"" % (agent_info["zone"])
53 print "zone \"%s\" {" % (agent_info["zone"])
55 for host, services in agent_info["repository"].items():
56 if host != agent_info["zone"]:
57 print "object Host \"%s\" {" % (host)
58 print " check_command = \"dummy\""
62 for service in services:
63 print "object Service \"%s\" {" % (service)
64 print " check_command = \"dummy\""
65 print " host_name = \"%s\"" % (host)