Skip to content

Commit

Permalink
Implement --batch parameter for icinga2-list-agents.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarbeutner committed Apr 13, 2014
1 parent a4b9cf3 commit 90d1118
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contrib/make-agent-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion tools/icinga2-forget-agent.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 15 additions & 5 deletions tools/icinga2-list-agents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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)

0 comments on commit 90d1118

Please sign in to comment.