Module: check_mk
Branch: master
Commit: bdb441639b5609e273fd92b8cf745882c88272c0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bdb441639b5609…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 20 10:30:27 2013 +0100
FIX Improved error handling of SNMP commands
In the past, in normal SNMP mode, the stderr output of all
snmp related commands was completely suppressed. It was hard
to find out the source of problems in some cases, for example
timeouts. The execution of those programs has been changed to
output stderr messages for walks in all cases and for gets only
when -v is given.
---
.werks/217 | 13 +++++++++++++
ChangeLog | 3 +++
modules/check_mk.py | 14 +++++++++++---
modules/snmp.py | 13 +++++++------
web/plugins/wato/check_mk_configuration.py | 2 +-
5 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/.werks/217 b/.werks/217
new file mode 100644
index 0000000..7c397c9
--- /dev/null
+++ b/.werks/217
@@ -0,0 +1,13 @@
+Title: Improved error handling of SNMP commands
+Level: 1
+Component: core
+Version: 1.2.3i7
+Date: 1384939712
+Class: fix
+
+In the past, in normal SNMP mode, the stderr output of all
+snmp related commands was completely suppressed. It was hard
+to find out the source of problems in some cases, for example
+timeouts. The execution of those programs has been changed to
+output stderr messages for walks in all cases and for gets only
+when -v is given.
diff --git a/ChangeLog b/ChangeLog
index 6439fe9..8538a3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
1.2.3i7:
+ Core & Setup:
+ * 0217 FIX: Improved error handling of SNMP commands...
+
Checks & Agents:
* 0060 cisco_fantray: new check for monitoring fan trays of Cisco Nexus switches
* 0061 cisco_cpu: check now recognizes new object cpmCPUTotal5minRev...
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 91af074..a1cefa8 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -25,6 +25,7 @@
# Boston, MA 02110-1301 USA.
import os, sys, socket, time, getopt, glob, re, stat, py_compile, urllib, inspect
+import subprocess
# These variable will be substituted at 'make dist' time
check_mk_version = '(inofficial)'
@@ -761,13 +762,20 @@ def snmp_get_oid(hostname, ipaddress, oid):
portspec = snmp_port_spec(hostname)
command = snmp_base_command(commandtype, hostname) + \
- " -On -OQ -Oe -Ot %s%s %s 2>/dev/null" % (ipaddress, portspec,
oid_prefix)
+ " -On -OQ -Oe -Ot %s%s %s" % (ipaddress, portspec, oid_prefix)
if opt_debug:
sys.stdout.write("Running '%s'\n" % command)
- snmp_process = os.popen(command, "r")
- line = snmp_process.readline().strip()
+ snmp_process = subprocess.Popen(command, shell = True, stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
+ exitstatus = snmp_process.wait()
+ if exitstatus:
+ if opt_verbose:
+ sys.stderr.write(tty_red + tty_bold + "ERROR: " + tty_normal +
"SNMP error\n")
+ sys.stderr.write(snmp_process.stderr.read())
+ return None
+
+ line = snmp_process.stdout.readline().strip()
if not line:
if opt_debug:
sys.stdout.write("Error in response to snmpget.\n")
diff --git a/modules/snmp.py b/modules/snmp.py
index d858c35..b46d048 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -401,10 +401,11 @@ def snmp_decode_string(text):
def snmpwalk_on_suboid(hostname, ip, oid):
portspec = snmp_port_spec(hostname)
command = snmp_walk_command(hostname) + \
- " -OQ -OU -On -Ot %s%s %s 2>/dev/null" % (ip, portspec, oid)
+ " -OQ -OU -On -Ot %s%s %s" % (ip, portspec, oid)
if opt_debug:
sys.stderr.write(' Running %s\n' % (command,))
- snmp_process = os.popen(command, "r").xreadlines()
+
+ snmp_process = subprocess.Popen(command, shell = True, stdout = subprocess.PIPE)
# Ugly(1): in some cases snmpwalk inserts line feed within one
# dataset. This happens for example on hexdump outputs longer
@@ -414,8 +415,8 @@ def snmpwalk_on_suboid(hostname, ip, oid):
# a continuation line.
rowinfo = []
try:
- while True: # walk through all lines
- line = snmp_process.next().strip()
+ for line in snmp_process.stdout.xreadlines():
+ line = line.strip()
parts = line.split('=', 1)
if len(parts) < 2:
continue # broken line, must contain =
@@ -437,9 +438,9 @@ def snmpwalk_on_suboid(hostname, ip, oid):
except StopIteration:
pass
- exitstatus = snmp_process.close()
+ exitstatus = snmp_process.wait()
if exitstatus:
if opt_verbose:
sys.stderr.write(tty_red + tty_bold + "ERROR: " + tty_normal +
"SNMP error\n")
- raise MKSNMPError("SNMP Error on %s" % ip)
+ raise MKSNMPError("SNMP Error on %s (Exit-Code: %d)" % (ip,
exitstatus))
return rowinfo
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 48bf6d6..c34468b 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -2032,7 +2032,7 @@ register_rule(group,
help = _("A request is sent to the SNMP daemon, than wait up to
this "
" number of seconds until retrying."),
default_value = 1,
- minvalue = 0.5,
+ minvalue = 0.1,
maxvalue = 60,
allow_int = True,
unit = _("sec"),