Module: check_mk
Branch: master
Commit: 1d0b8a388eb15c054ad461658b7bcd21513db88d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1d0b8a388eb15c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Feb 22 18:12:05 2018 +0100
5858 FIX agent_ipmi_sensors: Search PATH for ipmi-sensors command
The special agent was only searching the hard coded directories
/usr/sbin, /usr/bin, /usr/local/sbin and /usr/local/bin. Instead
of this, the special agent is now using the PATH variable of the
environment to search for this command, which also includes
environment related custom paths.
Change-Id: I1a85175ecfaefbd56227658ee9878cbbf0d42633
---
.werks/5858 | 14 ++++++
.werks/5859 | 10 +++++
agents/special/agent_ipmi_sensors | 92 +++++++++++++++++++--------------------
3 files changed, 70 insertions(+), 46 deletions(-)
diff --git a/.werks/5858 b/.werks/5858
new file mode 100644
index 0000000..5896f31
--- /dev/null
+++ b/.werks/5858
@@ -0,0 +1,14 @@
+Title: agent_ipmi_sensors: Search PATH for ipmi-sensors command
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1519319399
+Class: fix
+
+The special agent was only searching the hard coded directories
+/usr/sbin, /usr/bin, /usr/local/sbin and /usr/local/bin. Instead
+of this, the special agent is now using the PATH variable of the
+environment to search for this command, which also includes
+environment related custom paths.
diff --git a/.werks/5859 b/.werks/5859
new file mode 100644
index 0000000..c2b0834
--- /dev/null
+++ b/.werks/5859
@@ -0,0 +1,10 @@
+Title: agent_ipmi_sensors: Fixed exception when using debug mode
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1519320176
+Class: fix
+
+
diff --git a/agents/special/agent_ipmi_sensors b/agents/special/agent_ipmi_sensors
index 9ef158f..4410886 100755
--- a/agents/special/agent_ipmi_sensors
+++ b/agents/special/agent_ipmi_sensors
@@ -26,6 +26,7 @@
import os
+import errno
import sys
import getopt
import subprocess
@@ -60,26 +61,10 @@ OPTIONS:
with the remote host for IPMI 2.0.
""" )
-
-# output
-# ID | Name | Type | Reading | Units | Event
-# 4 | CPU Temp | Temperature | 28.00 | C | 'OK'
-# 71 | System Temp | Temperature | 28.00 | C | 'OK'
-# 607 | P1-DIMMC2 TEMP | Temperature | N/A | C | N/A
-
-
-def agent_ipmi_sensors_parse_data( ipmi_sensor_data ):
- for line in ipmi_sensor_data:
- if line.startswith( "ID" ):
- continue
- else:
- sys.stdout.write( "%s\n" % line )
-
-
-def agent_ipmi_sensors_main( cmdline_args ):
- short_options = 'u:p:l:' + 'D:k:'
- long_options = [ 'help', 'debug' ] + \
- [ 'quiet-cache', 'sdr-cache-recreate',
'interpret-oem-data',
+def agent_ipmi_sensors_main(cmdline_args):
+ short_options = 'u:p:l:D:k:'
+ long_options = [ 'help', 'debug'
+ 'quiet-cache', 'sdr-cache-recreate',
'interpret-oem-data',
'output-sensor-state',
'ignore-not-available-sensors',
'driver-type=', 'output-sensor-thresholds' ]
@@ -127,10 +112,6 @@ def agent_ipmi_sensors_main( cmdline_args ):
elif o in [ '--output-sensor-thresholds' ]:
additional_opts.append( o )
- if opt_debug:
- sys.stderr.write( "DEBUG: opts are '%s'.\n" % opts + \
- "DEBUG: args are '%s'.\n" % args )
-
if len(args) == 1:
hostname = args[0]
else:
@@ -141,33 +122,52 @@ def agent_ipmi_sensors_main( cmdline_args ):
sys.stderr.write( "ERROR: Credentials are missing.\n" )
sys.exit(1)
- for sub_path in [ "sbin", "bin", "local/sbin",
"local/bin" ]:
- ipmi_cmd = [ "/usr/%s/ipmi-sensors" % sub_path,
- "-h", hostname, "-u", username,
- "-p", password, "-l", privilege_lvl ] + \
- additional_opts
+ os.environ["PATH"] = "/usr/local/sbin:/usr/sbin:/sbin:" +
os.environ["PATH"]
+
+ ipmi_cmd = [ "ipmi-sensors",
+ "-h", hostname, "-u", username,
+ "-p", password, "-l", privilege_lvl ] + \
+ additional_opts
+ ipmi_cmd_str = subprocess.list2cmdline(ipmi_cmd)
- if opt_debug:
- sys.stderr.write( "DEBUG: try executing '%s'.\n" % "
".join( ipmi_cmd ) )
+ if opt_debug:
+ sys.stderr.write("Executing: '%s'\n" % ipmi_cmd_str)
+ try:
try:
- p = subprocess.Popen( ipmi_cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE )
- sensor_data, err = p.communicate()
- break
- except Exception, e:
- err = e
- if opt_debug:
- sys.stderr.write( "ERROR: '%s': %s.\n" % (ipmi_cmd_str,
e) )
- continue
+ p = subprocess.Popen(ipmi_cmd, shell=False, close_fds=True,
+ stdin=open(os.devnull),
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ except OSError, e:
+ if e.errno == errno.ENOENT: # No such file or directory
+ raise Exception("Could not find 'ipmi-sensors' command
(PATH: %s)" %
+
os.environ.get("PATH"))
+ else:
+ raise
+
+ stdout, stderr = p.communicate()
+ except Exception, e:
+ sys.stderr.write("ERROR: %s\n" % (e))
+ sys.exit(1)
- if err:
- sys.stderr.write( "ERROR: '%s'.\n" % err )
+ if stderr:
+ sys.stderr.write("ERROR: '%s'.\n" % stderr)
sys.exit(1)
- else:
- sys.stdout.write( "<<<ipmi_sensors:sep(124)>>>\n" )
- agent_ipmi_sensors_parse_data( sensor_data.splitlines() )
- sys.exit(0)
+
+ # output
+ # ID | Name | Type | Reading | Units | Event
+ # 4 | CPU Temp | Temperature | 28.00 | C | 'OK'
+ # 71 | System Temp | Temperature | 28.00 | C | 'OK'
+ # 607 | P1-DIMMC2 TEMP | Temperature | N/A | C | N/A
+ sys.stdout.write( "<<<ipmi_sensors:sep(124)>>>\n" )
+ for line in stdout.splitlines():
+ if line.startswith("ID"):
+ continue
+
+ sys.stdout.write( "%s\n" % line )
+
+ sys.exit(0)
if __name__ == "__main__":
- agent_ipmi_sensors_main( sys.argv[1:] )
+ agent_ipmi_sensors_main(sys.argv[1:])