2014-04-13 09:22:27 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Icinga 2
|
|
|
|
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation
|
|
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
import sys, os, json
|
2014-04-15 13:11:14 +02:00
|
|
|
from datetime import datetime
|
2014-04-13 09:22:27 +02:00
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
repository_dir = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/api/repository/"
|
2014-04-13 09:22:27 +02:00
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
repository = {}
|
2014-04-13 09:22:27 +02:00
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
for root, dirs, files in os.walk(repository_dir):
|
2014-04-13 09:22:27 +02:00
|
|
|
for file in files:
|
2014-04-13 09:45:14 +02:00
|
|
|
if len(file) != 64:
|
|
|
|
continue
|
|
|
|
|
2014-10-18 21:06:28 +02:00
|
|
|
fp = open(root + file + ".repo", "r")
|
2014-05-08 12:17:21 +02:00
|
|
|
repository_info = json.load(fp)
|
2014-04-13 09:45:14 +02:00
|
|
|
fp.close()
|
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
if not "endpoint" in repository_info:
|
2014-04-15 14:33:19 +02:00
|
|
|
continue
|
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
if not "seen" in repository_info:
|
|
|
|
repository_info["seen"] = 0
|
2014-04-15 13:11:14 +02:00
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
repository[repository_info["endpoint"]] = repository_info
|
2014-04-13 09:45:14 +02:00
|
|
|
|
|
|
|
try:
|
2014-10-18 21:06:28 +02:00
|
|
|
fp = open(root + file + ".settings", "r")
|
2014-04-13 09:45:14 +02:00
|
|
|
peer_info = json.load(fp)
|
|
|
|
fp.close()
|
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
repository[repository_info["endpoint"]]["peer"] = peer_info
|
2014-04-13 09:45:14 +02:00
|
|
|
except:
|
|
|
|
pass
|
2014-04-13 09:22:27 +02:00
|
|
|
|
2014-04-13 11:10:17 +02:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "--batch":
|
2014-05-08 12:17:21 +02:00
|
|
|
json.dump(repository, sys.stdout)
|
2014-04-13 11:10:17 +02:00
|
|
|
else:
|
2014-05-08 12:17:21 +02:00
|
|
|
for agent, agent_info in repository.items():
|
2014-04-15 13:11:14 +02:00
|
|
|
if "peer" in agent_info:
|
|
|
|
peer_info = agent_info["peer"]
|
2014-04-15 14:33:19 +02:00
|
|
|
peer_addr = "peer address: %s:%s" % (peer_info["agent_host"], peer_info["agent_port"])
|
2014-04-13 11:10:17 +02:00
|
|
|
else:
|
2014-04-15 13:11:14 +02:00
|
|
|
peer_addr = "no peer address"
|
|
|
|
|
2014-05-08 14:05:36 +02:00
|
|
|
print "* %s (%s, last seen: %s)" % (agent, peer_addr, datetime.fromtimestamp(agent_info["seen"]))
|
2014-04-13 11:10:17 +02:00
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
for host, services in agent_info["repository"].items():
|
2014-04-15 13:11:14 +02:00
|
|
|
print " * %s" % (host)
|
2014-04-13 11:10:17 +02:00
|
|
|
|
2014-05-08 12:17:21 +02:00
|
|
|
for service in services:
|
2014-04-15 13:11:14 +02:00
|
|
|
print " * %s" % (service)
|
2014-04-13 11:10:17 +02:00
|
|
|
|
2014-04-13 09:22:27 +02:00
|
|
|
sys.exit(0)
|
2014-05-08 12:17:21 +02:00
|
|
|
|