]> granicus.if.org Git - icinga2/commitdiff
Implement --batch parameter for icinga2-list-agents.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 13 Apr 2014 09:10:17 +0000 (11:10 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 13 Apr 2014 09:10:17 +0000 (11:10 +0200)
Refs #6002

contrib/make-agent-config.py
tools/icinga2-forget-agent.cmake
tools/icinga2-list-agents.cmake

index 8524b8a785db56fc07a5acaf3cca6a95b61cc249..c61a4e6e95f29e933f03d2aae38ff7ed7a2a24f4 100755 (executable)
@@ -30,7 +30,7 @@
 
 import subprocess, json
 
-inventory_json = subprocess.check_output(["icinga2-list-agents"])
+inventory_json = subprocess.check_output(["icinga2-list-agents", "--batch"])
 inventory = json.loads(inventory_json)
 
 for host, hostinfo in inventory.items():
index 8cabe8832c4cf425b00311341a63e4a16b620bc0..42d2b74bdd9e76c1444f26002b653d301fafd6c8 100644 (file)
@@ -31,7 +31,7 @@ cn = sys.argv[1]
 inventory_file = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/agent/inventory/" + hashlib.sha256(cn).hexdigest()
 
 if not os.path.isfile(inventory_file):
-    warning("There's no inventory file for agent '%s'.")
+    warning("There's no inventory file for agent '%s'." % (cn))
     sys.exit(0)
 
 os.unlink(inventory_file)
index 8c9c427531af0a95d7afdc036456849c2b84d170..d1e5f1b98aa894304910bb1be44d88d3b6dcfb28 100644 (file)
 # along with this program; if not, write to the Free Software Foundation
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
-from __future__ import print_function
 import sys, os, json
 
-def warning(*objs):
-    print(*objs, file=sys.stderr)
-
 inventory_dir = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/agent/inventory/"
 
 inventory = {}
@@ -47,5 +43,19 @@ for root, dirs, files in os.walk(inventory_dir):
         except:
             pass
 
-json.dump(inventory, sys.stdout)
+if len(sys.argv) > 1 and sys.argv[1] == "--batch":
+    json.dump(inventory, sys.stdout)
+else:
+    for host, host_info in inventory.items():
+        if "peer" in host_info:
+            peer_info = host_info["peer"]
+            peer_addr = " (%s:%s)" % (peer_info["agent_host"], peer_info["agent_port"])
+        else:
+            peer_addr = ""
+
+        print "* %s%s" % (host, peer_addr)
+
+        for service in host_info["services"]:
+            print "    * %s" % (service)
+
 sys.exit(0)