Implement --batch parameter for icinga2-list-agents.

Refs #6002
This commit is contained in:
Gunnar Beutner 2014-04-13 11:10:17 +02:00
parent a4b9cf33cc
commit 90d1118cb5
3 changed files with 17 additions and 7 deletions

View File

@ -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():

View 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)

View File

@ -16,12 +16,8 @@
# 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)