mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
parent
3926b68c04
commit
f704468c4b
@ -27,7 +27,8 @@ for agent, agent_info in inventory.items():
|
|||||||
print "}"
|
print "}"
|
||||||
print ""
|
print ""
|
||||||
print "object Zone \"%s\" {" % (agent_info["zone"])
|
print "object Zone \"%s\" {" % (agent_info["zone"])
|
||||||
print " parent = \"%s\"" % (agent_info["parent_zone"])
|
if "parent_zone" in agent_info:
|
||||||
|
print " parent = \"%s\"" % (agent_info["parent_zone"])
|
||||||
print " endpoints = [ \"%s\" ]" % (agent)
|
print " endpoints = [ \"%s\" ]" % (agent)
|
||||||
print "}"
|
print "}"
|
||||||
print ""
|
print ""
|
||||||
|
@ -74,7 +74,7 @@ if [ -n "$1" ]; then
|
|||||||
|
|
||||||
if [ "$listener" = "y" ]; then
|
if [ "$listener" = "y" ]; then
|
||||||
while true; do
|
while true; do
|
||||||
echo -n "Which TCP port should the agent listen on? [8483] "
|
echo -n "Which TCP port should the agent listen on? [5665] "
|
||||||
if ! read listener_port; then
|
if ! read listener_port; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -83,7 +83,7 @@ if [ -n "$1" ]; then
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$listener_port" ]; then
|
if [ -z "$listener_port" ]; then
|
||||||
listener_port=8483
|
listener_port=5665
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1,97 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# Copyright (c) 2014 Yusuke Shinyama
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
|
||||||
# in the Software without restriction, including without limitation the rights
|
|
||||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
# copies of the Software, and to permit persons to whom the Software is
|
|
||||||
# furnished to do so, subject to the following conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be included in
|
|
||||||
# all copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
||||||
# IN THE SOFTWARE.
|
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
## NetstringParser
|
|
||||||
##
|
|
||||||
class NetstringParser(object):
|
|
||||||
"""
|
|
||||||
Decodes a netstring to a list of Python strings.
|
|
||||||
|
|
||||||
>>> parser = NetstringParser()
|
|
||||||
>>> parser.feed('3:456,')
|
|
||||||
>>> parser.results
|
|
||||||
['456']
|
|
||||||
>>> NetstringParser.parse('3:abc,4:defg,')
|
|
||||||
['abc', 'defg']
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.results = []
|
|
||||||
self.reset()
|
|
||||||
return
|
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
self._data = ''
|
|
||||||
self._length = 0
|
|
||||||
self._parse = self._parse_len
|
|
||||||
return
|
|
||||||
|
|
||||||
def feed(self, s):
|
|
||||||
i = 0
|
|
||||||
while i < len(s):
|
|
||||||
i = self._parse(s, i)
|
|
||||||
return
|
|
||||||
|
|
||||||
def _parse_len(self, s, i):
|
|
||||||
while i < len(s):
|
|
||||||
c = s[i]
|
|
||||||
if c < '0' or '9' < c:
|
|
||||||
self._parse = self._parse_sep
|
|
||||||
break
|
|
||||||
self._length *= 10
|
|
||||||
self._length += ord(c)-48
|
|
||||||
i += 1
|
|
||||||
return i
|
|
||||||
|
|
||||||
def _parse_sep(self, s, i):
|
|
||||||
if s[i] != ':': raise SyntaxError(i)
|
|
||||||
self._parse = self._parse_data
|
|
||||||
return i+1
|
|
||||||
|
|
||||||
def _parse_data(self, s, i):
|
|
||||||
n = min(self._length, len(s)-i)
|
|
||||||
self._data += s[i:i+n]
|
|
||||||
self._length -= n
|
|
||||||
if self._length == 0:
|
|
||||||
self._parse = self._parse_end
|
|
||||||
return i+n
|
|
||||||
|
|
||||||
def _parse_end(self, s, i):
|
|
||||||
if s[i] != ',': raise SyntaxError(i)
|
|
||||||
self.add_data(self._data)
|
|
||||||
self.reset()
|
|
||||||
return i+1
|
|
||||||
|
|
||||||
def add_data(self, data):
|
|
||||||
self.results.append(data)
|
|
||||||
return
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def parse(klass, s):
|
|
||||||
self = klass()
|
|
||||||
self.feed(s)
|
|
||||||
return self.results
|
|
||||||
|
|
||||||
# Icinga 2
|
# Icinga 2
|
||||||
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
|
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
|
||||||
#
|
#
|
||||||
@ -109,6 +16,7 @@ class NetstringParser(object):
|
|||||||
# along with this program; if not, write to the Free Software Foundation
|
# along with this program; if not, write to the Free Software Foundation
|
||||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import socket, ssl, sys, json, os, hashlib, time
|
import socket, ssl, sys, json, os, hashlib, time
|
||||||
|
|
||||||
def warning(*objs):
|
def warning(*objs):
|
||||||
@ -122,7 +30,7 @@ host = sys.argv[1]
|
|||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
port = int(sys.argv[2])
|
port = int(sys.argv[2])
|
||||||
else:
|
else:
|
||||||
port = 8483
|
port = 5665
|
||||||
|
|
||||||
agentpki = "@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/pki/agent"
|
agentpki = "@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/pki/agent"
|
||||||
keyfile = agentpki + "/agent.key"
|
keyfile = agentpki + "/agent.key"
|
||||||
@ -158,38 +66,15 @@ if cn == None:
|
|||||||
warning("Agent certificate does not have a commonName:", repr(subject))
|
warning("Agent certificate does not have a commonName:", repr(subject))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
ssl_sock.write('20:{"method":"get_crs"},')
|
|
||||||
|
|
||||||
nsp = NetstringParser()
|
|
||||||
while True:
|
|
||||||
data = ssl_sock.read()
|
|
||||||
if not data:
|
|
||||||
break
|
|
||||||
nsp.feed(data)
|
|
||||||
|
|
||||||
ssl_sock.close()
|
ssl_sock.close()
|
||||||
|
|
||||||
if len(nsp.results) != 1:
|
repository_file = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/api/repository/" + hashlib.sha256(cn).hexdigest()
|
||||||
warning("Agent returned invalid response: ", repr(nsp.results))
|
fp = open(repository_file, "w")
|
||||||
sys.exit(1)
|
repository_info = { "endpoint": cn, "seen": time.time(), "zone": cn, "repository": {} }
|
||||||
|
json.dump(repository_info, fp)
|
||||||
response = json.loads(nsp.results[0])
|
|
||||||
method = response['method']
|
|
||||||
|
|
||||||
if method != "push_crs":
|
|
||||||
warning("Agent did not return any check results. Make sure you're using the master certificate.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
params = response["params"]
|
|
||||||
params["seen"] = time.time()
|
|
||||||
|
|
||||||
inventory_file = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/agent/inventory/" + hashlib.sha256(cn).hexdigest()
|
|
||||||
fp = open(inventory_file, "w")
|
|
||||||
inventory_info = { "identity": cn, "params": params }
|
|
||||||
json.dump(inventory_info, fp)
|
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
peer_file = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/agent/inventory/" + hashlib.sha256(cn).hexdigest() + ".peer"
|
peer_file = "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/icinga2/agent/repository/" + hashlib.sha256(cn).hexdigest() + ".peer"
|
||||||
fp = open(peer_file, "w")
|
fp = open(peer_file, "w")
|
||||||
peer_info = { "agent_host": host, "agent_port": port }
|
peer_info = { "agent_host": host, "agent_port": port }
|
||||||
json.dump(peer_info, fp)
|
json.dump(peer_info, fp)
|
||||||
|
@ -59,7 +59,7 @@ else:
|
|||||||
else:
|
else:
|
||||||
peer_addr = "no peer address"
|
peer_addr = "no peer address"
|
||||||
|
|
||||||
print "* %s (zone: %s, parent zone: %s, %s, last seen: %s)" % (agent, agent_info["zone"], agent_info["parent_zone"], peer_addr, datetime.fromtimestamp(agent_info["seen"]))
|
print "* %s (%s, last seen: %s)" % (agent, peer_addr, datetime.fromtimestamp(agent_info["seen"]))
|
||||||
|
|
||||||
for host, services in agent_info["repository"].items():
|
for host, services in agent_info["repository"].items():
|
||||||
print " * %s" % (host)
|
print " * %s" % (host)
|
||||||
|
@ -258,7 +258,7 @@
|
|||||||
this.txtPeerPort.Name = "txtPeerPort";
|
this.txtPeerPort.Name = "txtPeerPort";
|
||||||
this.txtPeerPort.Size = new System.Drawing.Size(84, 20);
|
this.txtPeerPort.Size = new System.Drawing.Size(84, 20);
|
||||||
this.txtPeerPort.TabIndex = 2;
|
this.txtPeerPort.TabIndex = 2;
|
||||||
this.txtPeerPort.Text = "8483";
|
this.txtPeerPort.Text = "5665";
|
||||||
//
|
//
|
||||||
// lblPeerPort
|
// lblPeerPort
|
||||||
//
|
//
|
||||||
@ -330,7 +330,7 @@
|
|||||||
this.txtListenerPort.Name = "txtListenerPort";
|
this.txtListenerPort.Name = "txtListenerPort";
|
||||||
this.txtListenerPort.Size = new System.Drawing.Size(84, 20);
|
this.txtListenerPort.Size = new System.Drawing.Size(84, 20);
|
||||||
this.txtListenerPort.TabIndex = 1;
|
this.txtListenerPort.TabIndex = 1;
|
||||||
this.txtListenerPort.Text = "8483";
|
this.txtListenerPort.Text = "5665";
|
||||||
//
|
//
|
||||||
// lblListenerPort
|
// lblListenerPort
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user