<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>blog@insidesystems.net: Monitoring iLO2 with Nagios</title>
    <link>http://blog.insidesystems.net/articles/2007/09/05/monitoring-ilo2-with-nagios</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Monitoring iLO2 with Nagios</title>
      <description>&lt;p&gt;We have a whole bunch of HP servers, purchased in large part for their excellent &lt;a href="http://h18004.www1.hp.com/products/servers/management/iloadv2/index.html"&gt;Lights-Out&lt;/a&gt; management software.  We wanted to have Nagios monitor some basic things, like the status of the fans, internal temperatures, power supplies, and VRMs.&lt;/p&gt;


	&lt;p&gt;Fortunately, that turned out to be pretty easy.&lt;/p&gt;&lt;p&gt;The first step was to download the HP Lights-Out &lt;span class="caps"&gt;XML&lt;/span&gt; Perl Scripting Sample for Linux.  I did this even though I don&amp;#8217;t use Linux as a platform.  The resulting file contains a bunch of sample &lt;span class="caps"&gt;XML&lt;/span&gt; scripts for accomplishing various goals, and a perl script (locfg.pl) that submits them to an iLO2 processor.&lt;/p&gt;


	&lt;p&gt;I then used locfg.pl to submit the following &lt;span class="caps"&gt;XML&lt;/span&gt; to each of our servers, in order to create a user with no substantial privileges.&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
&amp;lt;RIBCL VERSION="2.0"&amp;gt;
  &amp;lt;LOGIN USER_LOGIN="adminuser" PASSWORD="adminpass"&amp;gt;
  &amp;lt;USER_INFO MODE="write"&amp;gt;
    &amp;lt;ADD_USER 
      USER_NAME="Nagios Monitor" 
      USER_LOGIN="nagiosuser" 
      PASSWORD="nagiospass"&amp;gt;
      &amp;lt;ADMIN_PRIV value ="N"/&amp;gt;
      &amp;lt;REMOTE_CONS_PRIV value ="N"/&amp;gt;
      &amp;lt;RESET_SERVER_PRIV value ="N"/&amp;gt;
      &amp;lt;VIRTUAL_MEDIA_PRIV value ="N"/&amp;gt;
      &amp;lt;CONFIG_ILO_PRIV value="N"/&amp;gt;
    &amp;lt;/ADD_USER&amp;gt;
  &amp;lt;/USER_INFO&amp;gt;
  &amp;lt;/LOGIN&amp;gt;
&amp;lt;/RIBCL&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;This script allowed me to quickly create unprivileged users on each of the iLO2 consoles.&lt;/p&gt;


	&lt;p&gt;Armed with an unprivileged user, I set about writing the actual plugin, and ended up with this:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
#!/usr/bin/env ruby
require 'optparse'
require 'socket'
require 'openssl'
require 'rexml/document'

# Command Line Options
options = {
  :server =&amp;gt; nil
}

opts = OptionParser.new do |opt|
  opt.banner = "Usage: #{$0}  [options]" 
  opt.on('-s', '--server HOSTNAME', String, "Hostname or IP of the server to query") { |i| options[:server] = i }
end
opts.parse!(ARGV)

if not options[:server]
  $stderr.puts "Server must be specified" 
  exit!
end

# iLO XML
xml_start = &amp;lt;&amp;lt;EOF
&amp;lt;RIBCL VERSION="2.22"&amp;gt;
  &amp;lt;LOGIN USER_LOGIN="nagiosuser" PASSWORD="nagiospass"&amp;gt;
EOF

xml_end = &amp;lt;&amp;lt;EOF
  &amp;lt;/LOGIN&amp;gt;
&amp;lt;/RIBCL&amp;gt;
EOF

xml_emhealth = &amp;lt;&amp;lt;EOF
&amp;lt;SERVER_INFO MODE="read"&amp;gt;
  &amp;lt;GET_EMBEDDED_HEALTH /&amp;gt;
&amp;lt;/SERVER_INFO&amp;gt;
EOF

error_cnt = 0
error_msg = ''
error_summary = ''

s = TCPsocket.open(options[:server], 443)
ssl = OpenSSL::SSL::SSLSocket.new(s, OpenSSL::SSL::SSLContext.new)
ssl.sync
ssl.connect
ssl.write("&amp;lt;?xml version=\"1.0\"?&amp;gt;\r\n")
ssl.write(xml_start)
ssl.write(xml_emhealth)
ssl.write(xml_end)
ssl.flush
res = ssl.readlines

ssl.close
s.close

doc = REXML::Document.new(res.to_s.match(/&amp;lt;GET_EMBEDDED_HEALTH_DATA&amp;gt;.*&amp;lt;\/GET_EMBEDDED_HEALTH_DATA&amp;gt;/m).to_s)

if ! doc.elements["GET_EMBEDDED_HEALTH_DATA"]
  error_cnt += 1
  error_msg += "Unable to fetch embedded health data\n" 
end

doc.root.elements["FANS"].each_element('//FAN') { |mod|
  if mod.elements["STATUS"].attributes['VALUE'] != 'Ok'
    error_cnt += 1
    error_msg += "#{mod.elements['LABEL'].attributes['VALUE']} - #{mod.elements['ZONE'].attributes['VALUE']} - #{mod.elements['STATUS'].attributes['VALUE']}\n" 
    error_summary += "#{mod.elements['LABEL'].attributes['VALUE']}." 
  end
}

doc.root.elements["TEMPERATURE"].each_element('//TEMP') { |mod|
  if mod.elements["STATUS"].attributes['VALUE'] != 'Ok' and mod.elements["STATUS"].attributes['VALUE'] != 'n/a'
    error_cnt += 1
    error_msg += "#{mod.elements['LABEL'].attributes['VALUE']} - #{mod.elements['LOCATION'].attributes['VALUE']} - #{mod.elements['STATUS'].attributes['VALUE']} - #{mod.elements['CURRENTREADING'].attributes['VALUE']} #{mod.elements['CURRENTREADING'].attributes['UNIT']} (Caution/Critical: #{mod.elements['CAUTION'].attributes['VALUE']}/#{mod.elements['CRITICAL'].attributes['VALUE']})\n" 
    error_summary += "#{mod.elements['LABEL'].attributes['VALUE']}." 
  end
}

doc.root.elements["VRM"].each_element('//MODULE') { |mod|
  if mod.elements["STATUS"].attributes['VALUE'] != 'Ok'
    error_cnt += 1
    error_msg += "#{mod.elements['LABEL'].attributes['VALUE']} - #{mod.elements['STATUS'].attributes['VALUE']}\n" 
    error_summary += "#{mod.elements['LABEL'].attributes['VALUE']}." 
  end
}

doc.root.elements["POWER_SUPPLIES"].each_element('//SUPPLY') { |mod|
  if mod.elements["STATUS"].attributes['VALUE'] != 'Ok'
    error_cnt += 1
    error_msg += "#{mod.elements['LABEL'].attributes['VALUE']} - #{mod.elements['STATUS'].attributes['VALUE']}\n" 
    error_summary += "#{mod.elements['LABEL'].attributes['VALUE']}." 
  end
}

if error_cnt == 0
  puts "OK: 0 problems" 
  rc=0
else
  puts "Critical: #{error_cnt} problems. #{error_summary}" 
  puts error_msg
  rc=2
end

exit rc
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Now having that in place, I simply added all of the iLO2 hosts to a hostgroup, and added a service to check that group using the script, and all my fans, power supplies and such are now monitored without any operating-system level overhead.&lt;/p&gt;</description>
      <pubDate>Wed, 05 Sep 2007 08:21:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:2a56f074-881c-4f4f-af36-91961aa2c1fe</guid>
      <author>Kevin Way</author>
      <link>http://blog.insidesystems.net/articles/2007/09/05/monitoring-ilo2-with-nagios</link>
      <category>FreeBSD</category>
      <category>Off-Topic</category>
      <category>System Administration</category>
    </item>
  </channel>
</rss>
