diff options
author | Timothy Asir <tjeyasin@redhat.com> | 2014-06-11 18:31:56 +0530 |
---|---|---|
committer | Sahina Bose <sabose@redhat.com> | 2014-06-16 04:46:47 -0700 |
commit | d89e8d4ba22635e49f9d6a9bb9fa740f26bb538d (patch) | |
tree | d431f2678f7b2fae6cc30be050610dc03371d0d8 | |
parent | c408fed3cd1b960a53bbde75e842ff498de79420 (diff) |
Remove python-psutil dependency
Change-Id: I6267242de480f4c7a572eeac7a74472bf7ab9226
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1103759
Signed-off-by: Timothy Asir <tjeyasin@redhat.com>
Reviewed-on: http://review.gluster.org/8037
Tested-by: Timothy Asir <tim.gluster@gmail.com>
Reviewed-by: Sahina Bose <sabose@redhat.com>
-rw-r--r-- | gluster-nagios-addons.spec.in | 1 | ||||
-rwxr-xr-x | plugins/check_proc_util.py | 37 |
2 files changed, 25 insertions, 13 deletions
diff --git a/gluster-nagios-addons.spec.in b/gluster-nagios-addons.spec.in index 0ae3bed..885a641 100644 --- a/gluster-nagios-addons.spec.in +++ b/gluster-nagios-addons.spec.in @@ -84,7 +84,6 @@ Requires: python-inotify Requires: python-netaddr Requires: python-pthreading Requires: python-cpopen >= 1.3 -Requires: python-psutil Requires: python-lockfile Requires: python-daemon Requires: sysstat diff --git a/plugins/check_proc_util.py b/plugins/check_proc_util.py index 3a1061b..af0b0e5 100755 --- a/plugins/check_proc_util.py +++ b/plugins/check_proc_util.py @@ -16,8 +16,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # +import os import errno -import psutil from glusternagios import utils @@ -49,6 +49,13 @@ class CtdbNodeStatus: DISABLED = 'DISABLED' +def _pidExists(pid): + if type(pid) is int and pid > 0: + return os.path.exists("/proc/%s" % pid) + else: + raise ValueError("invalid pid :%s" % pid) + + def getBrickStatus(volumeName, brickName): status = None brickPath = brickName.split(':')[1] @@ -56,18 +63,24 @@ def getBrickStatus(volumeName, brickName): try: with open("%s/%s/run/%s" % ( _glusterVolPath, volumeName, pidFile)) as f: - if psutil.pid_exists(int(f.read().strip())): - status = utils.PluginStatusCode.OK - brickDevice = storage.getBrickDeviceName(brickPath) - disk = storage.getDisksForBrick(brickDevice) - cmd = [checkIdeSmartCmdPath.cmd, "-d", disk, "-n"] - rc, out, err = utils.execCmd(cmd) - if rc == utils.PluginStatusCode.CRITICAL and \ - "tests failed" in out[0]: - status = utils.PluginStatusCode.WARNING - msg = "WARNING: Brick %s: %s" % (brickPath, out[0]) - else: + try: + if _pidExists(int(f.read().strip())): + status = utils.PluginStatusCode.OK + brickDevice = storage.getBrickDeviceName(brickPath) + disk = storage.getDisksForBrick(brickDevice) + cmd = [checkIdeSmartCmdPath.cmd, "-d", disk, "-n"] + rc, out, err = utils.execCmd(cmd) + if rc == utils.PluginStatusCode.CRITICAL and \ + "tests failed" in out[0]: + status = utils.PluginStatusCode.WARNING + msg = "WARNING: Brick %s: %s" % (brickPath, out[0]) + else: + status = utils.PluginStatusCode.CRITICAL + except ValueError as e: status = utils.PluginStatusCode.CRITICAL + msg = "Invalid pid of brick %s: %s" % (brickPath, + str(e)) + return status, msg except IOError as e: if e.errno == errno.ENOENT: status = utils.PluginStatusCode.CRITICAL |