Module: check_mk
Branch: master
Commit: 65d7e18e6c3d10dd46557ea5be653516a62d5b90
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=65d7e18e6c3d10…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Aug 13 10:17:17 2011 +0200
new config variable dyndns_hosts
---
ChangeLog | 2 ++
modules/check_mk.py | 41 ++++++++++++++++++++++++++++++++++++++++-
modules/check_mk_base.py | 22 ----------------------
3 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c858576..e793301 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,8 @@
TCP port (default is 6556) on a per-host basis.
* new config variable snmp_ports, allowing to specify the UDP port
to used with SNMP, on a per-host basis.
+ * new config variable dyndns_hosts. Hosts listed in this configuration
+ list (compatible to bulkwalk_hosts) use their hostname as IP address.
Checks & Agents:
* FIX: cisco_temp: skip non-present sensors at inventory
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 1376e5e..cacaede 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -265,6 +265,7 @@ snmp_hosts = [ (['snmp'], ALL_HOSTS)
]
tcp_hosts = [ (['tcp'], ALL_HOSTS), (NEGATE,
['snmp'], ALL_HOSTS), (['!ping'], ALL_HOSTS) ]
bulkwalk_hosts = []
usewalk_hosts = []
+dyndns_hosts = [] # use host name as ip address for these hosts
ignored_checktypes = [] # exclude from inventory
ignored_services = [] # exclude from inventory
ignored_checks = [] # exclude from inventory
@@ -940,6 +941,39 @@ def get_datasource_program(hostname, ipaddress):
else:
return programs[0].replace("<IP>",
ipaddress).replace("<HOST>", hostname)
+# Determine the IP address of a host
+def lookup_ipaddress(hostname):
+ # Quick hack, where all IP addresses are faked (--fake-dns)
+ if fake_dns:
+ return fake_dns
+
+ # Honor simulation mode und usewalk hosts. Never contact the network.
+ elif simulation_mode or opt_use_snmp_walk or \
+ (is_usewalk_host(hostname) and is_snmp_host(hostname)):
+ return "127.0.0.1"
+
+ # Now check, if IP address is hard coded by the user
+ ipa = ipaddresses.get(hostname)
+ if ipa:
+ return ipa
+
+ # Hosts listed in dyndns hosts always use dynamic DNS lookup.
+ # The use their hostname as IP address at all places
+ if in_binary_hostlist(hostname, dyndns_hosts):
+ return hostname
+
+ # Address has already been resolved in prior call to this function?
+ if hostname in g_dns_cache:
+ return g_dns_cache[hostname]
+
+ # No do the actual DNS lookup
+ try:
+ ipa = socket.gethostbyname(hostname)
+ except:
+ g_dns_cache[hostname] = None
+ raise
+ g_dns_cache[hostname] = ipa
+ return ipa
def agent_port_of(hostname):
ports = host_extra_conf(hostname, agent_ports)
@@ -2250,13 +2284,18 @@ no_inventory_possible = None
ipa = lookup_ipaddress(node)
needed_ipaddresses[node] = ipa
nodes.append( (node, ipa) )
- ipaddress = None
+ try:
+ ipaddress = lookup_ipaddress(hostname) # might throw exception
+ needed_ipaddresses[hostname] = ipaddress
+ except:
+ ipaddress = None
else:
ipaddress = lookup_ipaddress(hostname) # might throw exception
needed_ipaddresses[hostname] = ipaddress
nodes = [ (hostname, ipaddress) ]
output.write("ipaddresses = %r\n\n" % needed_ipaddresses)
+ output.write("def lookup_ipaddress(hostname):\n return
ipaddresses.get(hostname)\n\n");
# datasource programs. Is this host relevant?
# ACHTUNG: HIER GIBT ES BEI CLUSTERN EIN PROBLEM!! WIR MUESSEN DIE NODES
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 47a5e59..22d5c76 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -541,28 +541,6 @@ def parse_info(lines):
return info
-def lookup_ipaddress(hostname):
- if fake_dns:
- return fake_dns
-
- elif simulation_mode or opt_use_snmp_walk or \
- (is_usewalk_host(hostname) and is_snmp_host(hostname)):
- return "127.0.0.1"
- elif hostname in g_dns_cache:
- return g_dns_cache[hostname]
- else:
- ipa = ipaddresses.get(hostname)
- if ipa:
- return ipa
- else:
- try:
- ipa = socket.gethostbyname(hostname)
- except:
- g_dns_cache[hostname] = None
- raise
- g_dns_cache[hostname] = ipa
- return ipa
-
def cachefile_age(filename):
try:
return time.time() - os.stat(filename)[8]