Module: check_mk
Branch: master
Commit: 7344680e3ff9f8dd33bd35d6e433a0374bb65965
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7344680e3ff9f8…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Aug 9 18:50:57 2011 +0200
New config option snmp_ports
---
.bugs/84 | 7 +++++++
ChangeLog | 2 ++
modules/check_mk.py | 29 +++++++++++++++++++++++++----
modules/snmp.py | 8 +++++---
4 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/.bugs/84 b/.bugs/84
index 14187d8..7a794b7 100644
--- a/.bugs/84
+++ b/.bugs/84
@@ -16,3 +16,10 @@ So kann man z.B. auch eine alternative Portnummer verwenden oder
evtl. Dinge für die Sicherheitseinstellung einfacher konfigurieren.
Die Parameter sollen immer am Ende kommen. Dann kann man darüber
sogar die Community einstellen und Parameter für V3.
+
+Achtung: Die Portnummer kann man nicht über Optionen angeben,
+sondern hinter dem Hostnamen mit Doppelpunkt, z.B.
+snmpwalk -c public -v1 localhost:555.
+
+Das ist daher separat über snmp_ports implementiert.
+
diff --git a/ChangeLog b/ChangeLog
index badac5b..ee3123d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,8 @@
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.
+ * new config variable snmp_ports, allowing to specify the UDP port
+ to used with SNMP, 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 e8cc557..41bd031 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -211,6 +211,7 @@ NEGATE = '@negate' # negation in boolean lists
# Basic Settings
agent_port = 6556
agent_ports = []
+snmp_ports = [] # UDP ports used for SNMP
tcp_connect_timeout = 5.0
do_rrd_update = False
delay_precompile = False # delay Python compilation to Nagios
execution
@@ -655,8 +656,9 @@ def get_single_oid(hostname, ipaddress, oid):
oid_prefix = oid
commandtype = "get"
+ portspec = snmp_port_spec(hostname)
command = snmp_base_command(commandtype, hostname) + \
- " -On -OQ -Oe -Ot %s %s 2>/dev/null" % (ipaddress, oid_prefix)
+ " -On -OQ -Oe -Ot %s%s %s 2>/dev/null" % (ipaddress, portspec,
oid_prefix)
try:
if opt_debug:
sys.stdout.write("Running '%s'\n" % command)
@@ -946,6 +948,20 @@ def agent_port_of(hostname):
else:
return ports[0]
+def snmp_port_of(hostname):
+ ports = host_extra_conf(hostname, snmp_ports)
+ if len(ports) == 0:
+ return None # do not specify a port, use default
+ else:
+ return ports[0]
+
+def snmp_port_spec(hostname):
+ port = snmp_port_of(hostname)
+ if port == None:
+ return ""
+ else:
+ return ":%d" % port
+
def service_description(checkname, item):
if checkname not in check_info:
@@ -2256,8 +2272,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
+ # TCP and SNMP port of agent
output.write("def agent_port_of(hostname):\n return %d\n\n" %
agent_port_of(hostname))
+ output.write("def snmp_port_spec(hostname):\n return %r\n\n" %
snmp_port_spec(hostname))
# Parameters for checks: Default values are defined in checks/*. The
# variables might be overridden by the user in main.mk. We need
@@ -2900,7 +2917,8 @@ def do_snmpwalk_on(hostname, filename):
if opt_verbose:
sys.stdout.write("%s:\n" % hostname)
ip = lookup_ipaddress(hostname)
- cmd = snmp_walk_command(hostname) + " -On -Ob -OQ -Ot %s " % ip
+ portspec = snmp_port_spec(hostname)
+ cmd = snmp_walk_command(hostname) + " -On -Ob -OQ -Ot %s%s " % (ip,
portspec)
if opt_debug:
print 'Executing: %s' % cmd
out = file(filename, "w")
@@ -3063,7 +3081,10 @@ def dump_host(hostname):
bulk = "yes"
else:
bulk = "no"
- agenttype = "SNMP (community: '%s', bulk walk: %s)" %
(credentials, bulk)
+ portinfo = snmp_port_of(hostname)
+ if portinfo == None:
+ portinfo = 'default'
+ agenttype = "SNMP (community: '%s', bulk walk: %s, port: %s)" %
(credentials, bulk, portinfo)
print tty_yellow + "Type of agent: " + tty_normal + agenttype
is_aggregated = host_is_aggregated(hostname)
if is_aggregated:
diff --git a/modules/snmp.py b/modules/snmp.py
index 0ccff3e..de0ce2e 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -84,8 +84,9 @@ def get_snmp_explicit(hostname, ipaddress, mib, baseoid, suffixes):
mibinfo = " -m %s" % mib
else:
mibinfo = ""
- command = cmd + "%s -OQ -OU -Oe %s %s.%s 2>/dev/null" % \
- (mibinfo, ipaddress, baseoid, suffix)
+ portspec = snmp_port_spec(hostname)
+ command = cmd + "%s -OQ -OU -Oe %s%s %s.%s 2>/dev/null" % \
+ (mibinfo, ipaddress, portspec, baseoid, suffix)
if opt_debug:
sys.stderr.write(' Running %s\n' % (command,))
num_found = 0
@@ -112,8 +113,9 @@ def get_snmp_explicit(hostname, ipaddress, mib, baseoid, suffixes):
return info
def snmpwalk_on_suboid(hostname, ip, oid):
+ portspec = snmp_port_spec(hostname)
command = snmp_walk_command(hostname) + \
- " -OQ -OU -On -Ot %s %s 2>/dev/null" % (ip, oid)
+ " -OQ -OU -On -Ot %s%s %s 2>/dev/null" % (ip, portspec, oid)
if opt_debug:
sys.stderr.write(' Running %s\n' % (command,))
snmp_process = os.popen(command, "r").xreadlines()