]> granicus.if.org Git - icinga2/blob - contrib/make-agent-config.py
DB IDO: Remove deleted custom variables
[icinga2] / contrib / make-agent-config.py
1 #!/usr/bin/env python
2 # Icinga 2
3 # Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)
4 #
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.
9 #
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.
14 #
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.
18
19 import subprocess, json
20
21 inventory_json = subprocess.check_output(["icinga2", "agent", "list", "--batch"])
22 inventory = json.loads(inventory_json)
23
24 for agent, agent_info in inventory.items():
25     print "object Endpoint \"%s\" {" % (agent)
26     print "  host = \"%s\"" % (agent)
27     print "}"
28     print ""
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)
33     print "}"
34     print ""
35
36     print "object Host \"%s\" {" % (agent_info["zone"])
37     print "  check_command = \"cluster-zone\""
38     print "}"
39     print ""
40
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"])
44     print "}"
45     print ""
46
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"])
50     print "}"
51     print ""
52
53     for host, services in agent_info["repository"].items():
54         if host != agent_info["zone"]:
55             print "object Host \"%s\" {" % (host)
56             print "  check_command = \"dummy\""
57             print "  zone = \"%s\"" % (agent_info["zone"])
58             print "}"
59             print ""
60
61         for service in services:
62             print "object Service \"%s\" {" % (service)
63             print "  check_command = \"dummy\""
64             print "  host_name = \"%s\"" % (host)
65             print "  zone = \"%s\"" % (agent_info["zone"])
66             print "}"
67             print ""
68