-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathipmi.py
More file actions
executable file
·39 lines (29 loc) · 811 Bytes
/
ipmi.py
File metadata and controls
executable file
·39 lines (29 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
import sys
import pyghmi
from pyghmi.ipmi import command
from StringIO import StringIO
HOST = '192.168.1.10'
USERNAME = 'ADMIN'
PASSWORD = 'ADMIN'
def sanitize_string(s):
s = s.lower()
s = s.replace(' ', '_')
s = s.replace('-', '_')
s = s.replace('+', '')
s = s.replace('.', '_')
return s
buf = StringIO()
buf.write('OK | ')
try:
cmd = command.Command(HOST, USERNAME, PASSWORD)
except pyghmi.exceptions.IpmiException as ex:
print 'WARNING - ' + ex.message
sys.exit(2)
for sensor in cmd.get_sensor_data():
if sensor.value:
type = sanitize_string(sensor.type)
name = sanitize_string(sensor.name)
unit = sensor.units
buf.write('{0}.{1}={2}{3};;;; '.format(type, name, sensor.value, unit))
print buf.getvalue()