Module: check_mk
Branch: master
Commit: 0d5c87ce384576af8569f2ea8b7bb502c66cfab0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0d5c87ce384576…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Aug 9 17:25:36 2011 +0200
new config variable agent_ports
---
ChangeLog | 2 ++
modules/check_mk.py | 16 ++++++++++++++--
modules/check_mk_base.py | 4 ++--
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 33cbc19..faaad6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,8 @@
precompilation during cmk -C or cmk -R, but will do this the first
time the host is checked. This speeds up restarts. Default is False.
Nagios user needs write access in precompiled directory!
+ * new config variable agent_ports, allowing to specify the agent's
+ TCP port (default is 6556) on a per-host basis.
Checks & Agents:
* FIX: cisco_temp: skip non-present sensors at inventory
diff --git a/modules/check_mk.py b/modules/check_mk.py
index d59e5a7..e8cc557 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -210,6 +210,7 @@ NEGATE = '@negate' # negation in boolean lists
# Basic Settings
agent_port = 6556
+agent_ports = []
tcp_connect_timeout = 5.0
do_rrd_update = False
delay_precompile = False # delay Python compilation to Nagios
execution
@@ -938,6 +939,14 @@ def get_datasource_program(hostname, ipaddress):
return programs[0].replace("<IP>",
ipaddress).replace("<HOST>", hostname)
+def agent_port_of(hostname):
+ ports = host_extra_conf(hostname, agent_ports)
+ if len(ports) == 0:
+ return agent_port
+ else:
+ return ports[0]
+
+
def service_description(checkname, item):
if checkname not in check_info:
if item:
@@ -2119,7 +2128,7 @@ no_inventory_possible = None
# Compile in all neccessary global variables
output.write("\n# Global variables\n")
- for var in [ 'check_mk_version', 'agent_port',
'tcp_connect_timeout', 'agent_min_version',
+ for var in [ 'check_mk_version', 'tcp_connect_timeout',
'agent_min_version',
'perfdata_format', 'aggregation_output_format',
'aggr_summary_hostname', 'nagios_command_pipe_path',
'check_result_path', 'check_submission',
@@ -2247,6 +2256,9 @@ no_inventory_possible = None
# aggregation
output.write("def host_is_aggregated(hostname):\n return %r\n\n" %
host_is_aggregated(hostname))
+ # TCP port of agent
+ output.write("def agent_port_of(hostname):\n return %d\n\n" %
agent_port_of(hostname))
+
# Parameters for checks: Default values are defined in checks/*. The
# variables might be overridden by the user in main.mk. We need
# to set the actual values of those variables here. Otherwise the users'
@@ -3044,7 +3056,7 @@ def dump_host(hostname):
print tty_yellow + "Parents: " + tty_normal + ",
".join(parents_list)
print tty_yellow + "Host groups: " + tty_normal + ",
".join(hostgroups_of(hostname))
print tty_yellow + "Contact groups: " + tty_normal + ",
".join(host_contactgroups_of([hostname]))
- agenttype = "TCP (port: %d)" % agent_port
+ agenttype = "TCP (port: %d)" % agent_port_of(hostname)
if is_snmp_host(hostname):
credentials = snmp_credentials_of(hostname)
if is_bulkwalk_host(hostname):
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index b4897a9..47a5e59 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -462,7 +462,7 @@ def get_agent_info_tcp(hostname, ipaddress):
s.settimeout(tcp_connect_timeout)
except:
pass # some old Python versions lack settimeout(). Better ignore than fail
- s.connect((ipaddress, agent_port))
+ s.connect((ipaddress, agent_port_of(hostname)))
try:
s.setblocking(1)
except:
@@ -478,7 +478,7 @@ def get_agent_info_tcp(hostname, ipaddress):
return output
except Exception, e:
raise MKAgentError("Cannot get data from TCP port %s:%d: %s" %
- (ipaddress, agent_port, e))
+ (ipaddress, agent_port_of(hostname), e))
# Gets all information about one host so far cached.