Module: check_mk
Branch: master
Commit: bfe2a311e50c5c65d7f9f916f53bd8652fc53b60
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bfe2a311e50c5c…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Wed May 28 15:36:18 2014 +0200
agent_ibmsvc: improved error handling
---
agents/special/agent_ibmsvc | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/agents/special/agent_ibmsvc b/agents/special/agent_ibmsvc
index ba51bba..d536d9d 100755
--- a/agents/special/agent_ibmsvc
+++ b/agents/special/agent_ibmsvc
@@ -27,7 +27,7 @@
# needs to issue a command like
# ssh USER@HOSTNAME 'echo \<\<\<ibm_svc_host:sep\(58\)\>\>\>;
lshost -nohdr -delim :; echo \<\<\<ibm_svc_license:sep\(58\)\>\>\>;
lslicense -delim :; echo \<\<\<ibm_svc_mdisk:sep\(58\)\>\>\>; lsmdisk
-nohdr -delim :; echo \<\<\<ibm_svc_mdiskgrp:sep\(58\)\>\>\>; lsmdiskgrp
-nohdr -delim :; echo \<\<\<ibm_svc_node:sep\(58\)\>\>\>; lsnode -nohdr
-delim :; echo \<\<\<ibm_svc_nodestats:sep\(58\)\>\>\>; lsnodestats
-nohdr -delim :; echo \<\<\<ibm_svc_system:sep\(58\)\>\>\>; lssystem
-delim :; echo \<\<\<ibm_svc_systemstats:sep\(58\)\>\>\>; lssystemstats
-nohdr -delim :'
-import sys, os, getopt, re
+import sys, os, getopt, re, subprocess
import inspect, pprint # FOR DEBUGGING
@@ -182,8 +182,12 @@ cmd += "'"
if opt_debug:
sys.stderr.write("executing external command: %s\n" % cmd)
-for line in os.popen(cmd).readlines():
- print line,
+try:
+ for line in subprocess.check_output(cmd, shell=True).split('\n'):
+ print line,
+except subprocess.CalledProcessError:
+ print "Error connecting via ssh"
+ sys.exit(1)
#############################################################################