Discussion:
IPMI Commands in Zenoss
jhoffart
2013-11-08 17:57:14 UTC
Permalink
jhoffart [http://community.zenoss.org/people/jhoffart] created the discussion

"IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75212#75212

--------------------------------------------------------------
I am trying to use an IPMI command to pulling data from one of my servers in order to monitor cpu temp, fan speeds and so on, so far i have found that zenoss does not like the | symbol in my command and when i eliminate that symbol and the portion of the code after it only returns the first line of output form the command.

when i run the command from the bash shell on the server it returns the following:

# ipmitool -H 192.168.180.100 -U zenny -P macintosh sdr
System Temp      | 31 degrees C      | ok
CPU Temp         | 0 unspecified     | ok
FAN 1            | 5130 RPM          | ok
FAN 2            | 4860 RPM          | ok
FAN 3            | 4995 RPM          | ok
FAN 4            | disabled          | ns
FAN A            | 4725 RPM          | ok
Vcore            | 0.81 Volts        | ok
3.3VCC           | 3.36 Volts        | ok
12V              | 11.98 Volts       | ok
VDIMM            | 1.51 Volts        | ok
5VCC             | 5.06 Volts        | ok
-12V             | -11.87 Volts      | ok
VBAT             | 3.12 Volts        | ok
VSB              | 3.34 Volts        | ok
AVCC             | 3.36 Volts        | ok
Chassis Intru    | 0 unspecified     | nc
PS Status        | 0 unspecified     | nc

when i use | grep "FAN 1"

# ipmitool -H 192.168.180.100 -U zenny -P macintosh sdr | grep "FAN 1"
FAN 1            | 4995 RPM          | ok

Now when I run these commands in zenoss this is what it returns:

ipmitool -H 192.168.180.100 -U zenny -P macintosh sdr
System Temp | 31 degrees C | ok
(notice this only returns the first line of output compaired to when the command is run in the bash shell)

ipmitool -H 192.168.180.100 -U zenny -P macintosh sdr | grep "FAN 1"
Invalid SDR command: |
(when this is ran in the bash shell it returns the output for FAN 1 as shown above).
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75212#75212]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Rob Eagle
2013-11-14 13:13:23 UTC
Permalink
Rob Eagle [http://community.zenoss.org/people/reagle] created the discussion

"Re: IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75247#75247

--------------------------------------------------------------
jhoffart,
Not familiar with the ipmitool command, but when you say "Now when I run these commands in zenoss this is what it returns:" does that mean you are running it from the zenoss server or within the zenoss gui?
Can you first verify that it runs on the zenoss server (ie cli) and that all output is returned?
If so,
I think the issue is that the output for the command looks really similar to what zenoss is expecting (nagios output), but you need to have to re-format it: Status Message | Name=Value  Name=Value  Name=Value or for yours something like:
Status OK | Fan1RPM=5130, Fan1Status=1, Fan2RPM=4860, Fan2Status=1

Not sure if this is that actual correct format for multiple datapoints, but will try and reply when i verify.
--Rob

--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75247#75247]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
jhoffart
2013-11-14 14:36:07 UTC
Permalink
jhoffart [http://community.zenoss.org/people/jhoffart] created the discussion

"Re: IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75258#75258

--------------------------------------------------------------
Rob,
     I am trying to modify command to run and return the correct ouput in the zenoss GUI. My instance of zenoss is installed on a machine running centos and i have no problem running the command in the bash shell. You are also correct on the output and that is what I am try to currently figure out is how to return the multiline output of the command into a single string such as the one you mentioned.  "Status OK | Fan1RPM=5130, Fan1Status=1, Fan2RPM=4860, Fan2Status=1" this is the exact output i am looking for.
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75258#75258]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Rob Eagle
2013-11-14 17:06:40 UTC
Permalink
Rob Eagle [http://community.zenoss.org/people/reagle] created the discussion

"Re: IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75260#75260

--------------------------------------------------------------
jhoffart,
Kinda messy, but you might be able to do something like this:
#!/usr/bin/env python

import os
import re
import sys
from subprocess import Popen, PIPE

serverName = sys.argv[1]
usern = sys.argv[2]
passwd = sys.argv[3]

cmd_to_execute = "ipmitool -H " + serverName + " -U " +\
      usern + "-P " + passwd + \
      " /usr/bin/lparstat 1 1| awk '{print $5}' | sed '$!d'"

r=Popen(cmd_to_execute, shell=True, stdout=PIPE, stderr=PIPE)
results =  r.communicate()[0]
results = results.replace(" ", "")
results = results.replace("\n", "")
results = results.replace("=ok", "=1")
results = results.replace("=ns", "=0")
results = results.replace("\t", " ")
results = re.sub(r'(:?\=)(:?[0-9]+\.?[0-9]+|0)(:?[a-zA-Z]+)',r'\1\2', results)
print 'COUNT OK|' + results


right now it is producing something like:
COUNT OK|SystemTemp=31 SystemTempStatus=1 CPUTemp=0 CPUTempStatus=1 FAN1=5130 FAN1Status=1 FAN2=4860 FAN2Status=1 FAN3=4995 FAN3Status=1 FAN4=disabled FAN4Status=0 FANA=4725 FANAStatus=1 Vcore=0.81 VcoreStatus=1 3.3VCC=3.36 3.3VCCStatus=1 12V=11.98 12VStatus=1 VDIMM=1.51 VDIMMStatus=1 5VCC=5.06 5VCCStatus=1 -12V=-11.87Volts -12VStatus=1 VBAT=3.12 VBATStatus=1 VSB=3.34 VSBStatus=1 AVCC=3.36 AVCCStatus=1

which i think you will still have some issues on since the 12V, -12V and 3.3V are not naming standards that will probably work for datapoints.

You would place the file as /opt/zenoss/libexec/check_ipmtool.py on your zenoss install and use the following in your command template:
/opt/zenoss/bin/python /opt/zenoss/libexec/check_ipmtool.py ${dev/id} "${dev/zCommandUsername}"  "${dev/zCommandPassword}"

Would test from the cli using python check_imptool.py servername username password to see what output you get before running in zenoss, you might need to modify the command to execute a little.
Would also cleanup the script a little if you want, just an idea to get you going.
--Rob
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75260#75260]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
jhoffart
2013-11-19 17:09:59 UTC
Permalink
jhoffart [http://community.zenoss.org/people/jhoffart] created the discussion

"Re: IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75289#75289

--------------------------------------------------------------
Ok ran into a couple of issues with the code you provide but I was able to make some progress. The main problem I ran into is that the /usr/bin/lparstat directory does not exist on my server. The second is I kept getting an error when using the result.sub statement that you had in your code. So with some modifying this is what I have come up with so far.



#!/usr/bin/env python

import os
import re
import sys

serverName=sys.argv[1]
usern=sys.argv[2]
password=sys.argv[3]

from subprocess import Popen, PIPE

cmd_to_execute = "ipmitool -H " +serverName+  " -U " +usern+  " -P " +password+  " sdr"

r=Popen(cmd_to_execute, shell=True, stdout=PIPE, stderr=PIPE)

results = r.communicate()[0]

results = results.replace(" ","")
results = results.replace("\n","")
results = results.replace("|"," ")
results = results.replace("ok","=1")
results = results.replace("=ns","=0")
results = results.replace("\t"," ")

print 'COUNT OK|' + results


with this I can get the following output.

COUNT OK|SystemTemp 31degreesC =1CPUTemp 0unspecified =1FAN1 4995RPM =1FAN2 4860RPM =1FAN3 5130RPM =1FAN4 disabled nsFANA 4725RPM =1Vcore 0.88Volts =13.3VCC 3.36Volts =112V 11.98Volts =1VDIMM 1.52Volts =15VCC 5.06Volts =1-12V -11.87Volts =1VBAT 3.12Volts =1VSB 3.33Volts =1AVCC 3.36Volts =1ChassisIntru 0unspecified ncPSStatus 0unspecified nc

So the output is getting close to what I need but in need to find a way to eleminate the text after the number in example if the out put is SystemTemp 31degrees FAN1 4995RPM how do I remove degrees and RPM.

would like the output to look like SystemTemp=31 FAN1=4995.
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75289#75289]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Rob Eagle
2013-11-19 20:27:04 UTC
Permalink
Rob Eagle [http://community.zenoss.org/people/reagle] created the discussion

"Re: IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75290#75290

--------------------------------------------------------------
resutls = re.sub('(=)(\d+\.\d+|\d+)([a-zA-Z]+)',r'\g<1>'r'\g<2>',results)  -- will get rid of the names after the numbers on the right hand side of the =.

After i wrote this i also experimented with just running a single command that would would:
ipmitool -H 192.168.180.100 -U zenny -P macintosh | awk -F'|' '{ print $1 "=" $2 "\t" $1 "Status=" $3 "\t"}' | sed -e 's/ //g' -e 's/=ok/=1/g' -e 's/=ns/=0/g' -e 's/\t/ /g' -e 's/\(=\)\([0-9]*\.[0-9]*\)\([a-zA-Z]*\)/\1\2/g' -e 's/\(=\)\([0-9]*\)\([a-zA-Z]*\)/\1\2/g' -e 's/\(=\)\(-\)\([0-9]*\.[0-9]*\)\([a-zA-Z]*\)/\1\3/g' -e 's/-/negative/g' -e 's/\./_/g' | tr -d '\n' | sed -e '1 s|^|Status OK\||'

Hope this helps
--Rob
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75290#75290]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
jhoffart
2013-11-19 21:46:25 UTC
Permalink
jhoffart [http://community.zenoss.org/people/jhoffart] created the discussion

"Re: IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75291#75291

--------------------------------------------------------------
Thanks for the help Rob, I ended up taking the command you had come up with and inserting it into a bash shell and writting a command in zenoss to call that file. I did try to run the command directly from zenoss but kept running into an error.

Type: <class 'zope.tales.tales.CompilerError'> Value: $ must be doubled or followed by a simple path



Again thanks for the help. Calling the bash file in zenoss works exactly like i need it to and returns the info in the correct format needed as well.
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75291#75291]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Rob Eagle
2013-11-19 21:54:26 UTC
Permalink
Rob Eagle [http://community.zenoss.org/people/reagle] created the discussion

"Re: IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75280#75280

--------------------------------------------------------------
Sorry about that i was just using cat on the output you provided, but have no way of running your exact command on my system to fully test it.
If you would like some additional help on this, just let me know
--Rob
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75280#75280]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
rolfs
2013-11-20 07:16:16 UTC
Permalink
rolfs [http://community.zenoss.org/people/rolfs] created the discussion

"Re: IPMI Commands in Zenoss"

To view the discussion, visit: http://community.zenoss.org/message/75297#75297

--------------------------------------------------------------
Hi Jhoffart!
Post by Rob Eagle
#!/usr/bin/env python
import os
import re
import sys
serverName=sys.argv[1]
usern=sys.argv[2]
password=sys.argv[3]
from subprocess import Popen, PIPE
cmd_to_execute = "ipmitool -H " +serverName+  " -U " +usern+  " -P " +password+  " sdr"
r=Popen(cmd_to_execute, shell=True, stdout=PIPE, stderr=PIPE)
results = r.communicate()[0]
results = results.replace(" ","")
*results = results.replace("\n","")*
results = results.replace("|"," ")
results = results.replace("ok","=1")
results = results.replace("=ns","=0")
results = results.replace("\t"," ")
print 'COUNT OK|' + results
The newline is replaced with no space at all in the line above. Try changing it to this:
results = results.replace("\n"," ")

Maybe it will help? (did not test it)
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/75297#75297]

Start a new discussion in zenoss-users at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Loading...