From 6ff103d4a4276b124ae004a0fe3959bba2a241ed Mon Sep 17 00:00:00 2001 From: Nicolas Hennion Date: Sat, 27 Jul 2013 22:50:20 +0200 Subject: [PATCH] Command improvment --- glances/conf/glances.conf | 4 ++-- glances/glances.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/glances/conf/glances.conf b/glances/conf/glances.conf index b0905ca4..40932b0a 100644 --- a/glances/conf/glances.conf +++ b/glances/conf/glances.conf @@ -82,7 +82,7 @@ mem_critical=90 # An item is defined: # * description: Description of the processes (max 16 chars) # * regex: regular expression of the processes to monitor -# * command: (optional) shell command for extended stat +# * command: (optional) full path to shell command/script for extended stat # Use with caution. Should return a single line string. # * countmin: (optional) minimal number of processes # A warning will be displayed if number of process < count @@ -90,7 +90,7 @@ mem_critical=90 # A warning will be displayed if number of process > count list_1_description=Redis server list_1_regex=.*redis-server.* -list_1_command=redi s-cli CLIENT LIST +list_1_command=echo STAT list_2_description=Python programs list_2_regex=.*python.* list_2_countmin=1 diff --git a/glances/glances.py b/glances/glances.py index 2ceb3ccf..1a640c25 100644 --- a/glances/glances.py +++ b/glances/glances.py @@ -3064,8 +3064,11 @@ class glancesScreen: monitors.countmax(item))) # Build and print optional message if (monitors.command(item) != None): - monitormsg2 = "{0}".format( - subprocess.check_output(monitors.command(item), shell = True) if monitors.command(item) != "" else "") + try: + cmdret = subprocess.check_output(monitors.command(item), shell = True) + except subprocess.CalledProcessError: + cmdret = _("Error: ") + monitors.command(item) + monitormsg2 = "{0}".format(cmdret) self.term_window.addnstr(monitor_y, self.process_x + 35, monitormsg2, screen_x - process_x - 35) # else: -- GitLab