From 2191482b080ccb0e235f885f6ab27bbc8d26bb70 Mon Sep 17 00:00:00 2001 From: briedel Date: Wed, 28 Jan 2015 18:58:02 -0700 Subject: [PATCH 1/4] Changed conf file such that level and ipmitool_bin are defined --- ipmi/conf.d/ipmi.pyconf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ipmi/conf.d/ipmi.pyconf b/ipmi/conf.d/ipmi.pyconf index 600c5f07..8acb58ba 100644 --- a/ipmi/conf.d/ipmi.pyconf +++ b/ipmi/conf.d/ipmi.pyconf @@ -31,10 +31,14 @@ modules { } # Location of ipmitool binary - param timeout_bin { + param ipmitool_bin { value = "/usr/bin/ipmitool" } + param level { + value = "USER" + } + } } From f9da5676ae9b9976b9171cbbfc03dec6a339575d Mon Sep 17 00:00:00 2001 From: briedel Date: Thu, 29 Jan 2015 09:53:14 -0700 Subject: [PATCH 2/4] Making the script work properly. It would return 0 for all values because the call to get_metrics() would not return the global metric dict properly. Go directly to the global METRICS --- ipmi/python_modules/ipmi.py | 72 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index 24769c11..8f436120 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -21,25 +21,27 @@ def get_metrics(params): if (time.time() - METRICS['time']) > METRICS_CACHE_MAX: - new_metrics = {} - units = {} + new_metrics = {} + units = {} - command = [ params['timeout_bin'], - "3", params['ipmitool_bin'], - "-H", params['ipmi_ip'], - "-U", params['username'], - '-P', params['password'], - '-L', params['level'], - 'sensor'] + command = [ params['timeout_bin'], + "3", params['ipmitool_bin'], + # "-H", params['ipmi_ip'], + # "-U", params['username'], + # '-P', params['password'], + # '-L', params['level'], + 'sensor'] p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0][:-1] for i, v in enumerate(p.split("\n")): data = v.split("|") + try: metric_name = data[0].strip().lower().replace("+", "").replace(" ", "_") - value = data[1].strip() + value = data[1].strip() + # Skip missing sensors if re.search("(0x)", value ) or value == 'na': @@ -49,21 +51,22 @@ def get_metrics(params): vmatch = re.search("([0-9.]+)", value) if not vmatch: continue + if metric_name == "p1-dimma1_temp": print vmatch, vmatch.group(1) metric_value = float(vmatch.group(1)) - + new_metrics[metric_name] = metric_value units[metric_name] = data[2].strip().replace("degrees C", "C") - + except ValueError: continue except IndexError: continue - - METRICS = { - 'time': time.time(), - 'data': new_metrics, - 'units': units - } + + METRICS = { + 'time': time.time(), + 'data': new_metrics, + 'units': units + } return [METRICS] @@ -71,16 +74,9 @@ def get_metrics(params): def get_value(name): """Return a value for the requested metric""" - try: - - metrics = get_metrics()[0] + name = name[5:] - name = name.lstrip('ipmi_') - - result = metrics['data'][name] - - except Exception: - result = 0 + result = METRICS['data'][name] return result @@ -110,13 +106,13 @@ def metric_init(params): metrics = get_metrics(params)[0] for item in metrics['data']: - descriptors.append(create_desc(Desc_Skel, { - "name" : params['metric_prefix'] + "_" + item, - 'groups' : params['metric_prefix'], - 'units' : metrics['units'][item] - })) - - + descriptors.append(create_desc(Desc_Skel, { + "name" : params['metric_prefix'] + "_" + item, + 'groups' : params['metric_prefix'], + 'units' : metrics['units'][item], + # "call_back" : get_value(item) + })) + return descriptors def metric_cleanup(): @@ -128,10 +124,10 @@ def metric_cleanup(): params = { "metric_prefix" : "ipmi", - "ipmi_ip" : "10.1.2.3", - "username" : "ADMIN", - "password" : "secret", - "level" : "USER", + # "ipmi_ip" : "10.1.2.3", + # "username" : "ADMIN", + # "password" : "secret", + # "level" : "USER", "ipmitool_bin" : "/usr/bin/ipmitool", "timeout_bin" : "/usr/bin/timeout" } From 25690cf6d8017931e806d6a78ad766ab90c6a0d0 Mon Sep 17 00:00:00 2001 From: briedel Date: Thu, 29 Jan 2015 09:59:17 -0700 Subject: [PATCH 3/4] Removed debugging output and have the descriptors be updated continuously when debugging --- ipmi/python_modules/ipmi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index 8f436120..58a47d4a 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -18,7 +18,6 @@ def get_metrics(params): """Return all metrics""" global METRICS - if (time.time() - METRICS['time']) > METRICS_CACHE_MAX: new_metrics = {} @@ -51,7 +50,7 @@ def get_metrics(params): vmatch = re.search("([0-9.]+)", value) if not vmatch: continue - if metric_name == "p1-dimma1_temp": print vmatch, vmatch.group(1) + metric_value = float(vmatch.group(1)) new_metrics[metric_name] = metric_value @@ -131,9 +130,10 @@ def metric_cleanup(): "ipmitool_bin" : "/usr/bin/ipmitool", "timeout_bin" : "/usr/bin/timeout" } - descriptors = metric_init(params) + while True: + descriptors = metric_init(params) for d in descriptors: v = d['call_back'](d['name']) print '%s = %s' % (d['name'], v) From c42bc5cd24731cb30238f1c4c4a87bcf46921d10 Mon Sep 17 00:00:00 2001 From: briedel Date: Mon, 2 Feb 2015 12:51:47 -0700 Subject: [PATCH 4/4] Changed back to get_value() instead of METRIC. METRIC was not being updated properly. Made params in get_value() option to make it work. --- ipmi/python_modules/ipmi.py | 38 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index 58a47d4a..c6874a44 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -14,7 +14,7 @@ stats_pos = {} -def get_metrics(params): +def get_metrics(params = None): """Return all metrics""" global METRICS @@ -23,13 +23,22 @@ def get_metrics(params): new_metrics = {} units = {} - command = [ params['timeout_bin'], - "3", params['ipmitool_bin'], - # "-H", params['ipmi_ip'], - # "-U", params['username'], - # '-P', params['password'], - # '-L', params['level'], - 'sensor'] + if params != None: + command = [ params['timeout_bin'], + "3", params['ipmitool_bin'], + # "-H", params['ipmi_ip'], + # "-U", params['username'], + # '-P', params['password'], + # '-L', params['level'], + 'sensor'] + else: + command = [ "/usr/bin/timeout", + "3", "/usr/bin/ipmitool", + # "-H", params['ipmi_ip'], + # "-U", params['username'], + # '-P', params['password'], + # '-L', params['level'], + 'sensor'] p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0][:-1] @@ -41,6 +50,8 @@ def get_metrics(params): metric_name = data[0].strip().lower().replace("+", "").replace(" ", "_") value = data[1].strip() + # if not (("fan" in metric_name) or ("temp" in metric_name)): + # continue # Skip missing sensors if re.search("(0x)", value ) or value == 'na': @@ -75,7 +86,8 @@ def get_value(name): name = name[5:] - result = METRICS['data'][name] + # result = METRICS['data'][name] + result = get_metrics()[0]['data'][name] return result @@ -122,14 +134,14 @@ def metric_cleanup(): if __name__ == '__main__': params = { - "metric_prefix" : "ipmi", + "metric_prefix" : "ipmi", # "ipmi_ip" : "10.1.2.3", # "username" : "ADMIN", # "password" : "secret", # "level" : "USER", - "ipmitool_bin" : "/usr/bin/ipmitool", - "timeout_bin" : "/usr/bin/timeout" - } + "ipmitool_bin" : "/usr/bin/ipmitool", + "timeout_bin" : "/usr/bin/timeout" + } while True: