Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed conf file such that level and ipmitool_bin are defined #179

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ipmi/conf.d/ipmi.pyconf
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ modules {
}

# Location of ipmitool binary
param timeout_bin {
param ipmitool_bin {
value = "/usr/bin/ipmitool"
}

param level {
value = "USER"
}

}

}
Expand Down
100 changes: 54 additions & 46 deletions ipmi/python_modules/ipmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,44 @@

stats_pos = {}

def get_metrics(params):
def get_metrics(params = None):
"""Return all metrics"""

global METRICS

if (time.time() - METRICS['time']) > METRICS_CACHE_MAX:

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']
new_metrics = {}
units = {}

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]

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()

# if not (("fan" in metric_name) or ("temp" in metric_name)):
# continue

# Skip missing sensors
if re.search("(0x)", value ) or value == 'na':
Expand All @@ -49,38 +61,33 @@ def get_metrics(params):
vmatch = re.search("([0-9.]+)", value)
if not vmatch:
continue
metric_value = float(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]


def get_value(name):
"""Return a value for the requested metric"""

try:
name = name[5:]

metrics = get_metrics()[0]

name = name.lstrip('ipmi_')

result = metrics['data'][name]

except Exception:
result = 0
# result = METRICS['data'][name]
result = get_metrics()[0]['data'][name]

return result

Expand Down Expand Up @@ -110,13 +117,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():
Expand All @@ -127,17 +134,18 @@ def metric_cleanup():
if __name__ == '__main__':

params = {
"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"
}
descriptors = metric_init(params)
"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"
}


while True:
descriptors = metric_init(params)
for d in descriptors:
v = d['call_back'](d['name'])
print '%s = %s' % (d['name'], v)
Expand Down