设为首页 收藏本站
查看: 1606|回复: 0

[经验分享] 通过zabbix和ipmi来监控dell服务器

[复制链接]

尚未签到

发表于 2017-4-20 11:06:47 | 显示全部楼层 |阅读模式
  http://www.zabbix.com/wiki/doku.php?id=howto:dellipmi
  
IPMI on Dell Servers

  
The following article outlines how to use Zabbix to monitor the
information from Dell PowerEdge Servers without an agent, using the
Dell BMC via IP. I’ve done with with PowerEdge 1850, 1950, 2850, 2950
servers, some with DRAC4 cards at the  The Frontier School Division
. Questions/problems with the article?  Email me at asingl@frontiersd.mb.ca.


Enabling IPMI on Dell BMC

  
IPMI on the BMC is not enabled over IP by default on Dell PE servers.
You can enable IPMI over IP in the BIOS, or via a DRAC5 controller if
you have it installed.  Carlos' Corner blog with screenshots of IPMI IP setup on a DRAC5 card

  
Steps to Enable IPMI over IP



  • At boot, press Ctrl+E when the BMC is initializing.

  • Enable IPMI over LAN

  • NIC Selection (You may see this
    based on what server you have. If you have a DRAC, set this to
    dedicated, and it will use the DRAC NIC)

  • LAN Parameters - Set a static IP.

  • LAN user configuration - Create a user & password for access via the LAN
  Note:  You do not get a ping reply from the BMC over IP.  You will need to use IPMItool (See below) to query the BMC.




Install IPMItools on Zabbix server

  
You’ll need to install ipmitool, which is in the OpenIPMI-tools package.  On CentOS, you can use:


yum install OpenIPMI-tools

  to install, auto launch, and start the service. (You may only need
OpenIPMI-tools) On other distro’s, you’ll need to find the
OpenIPMI-tools package & install it.

  
Use the following command to query the remote BMC:


/usr/bin/ipmitool -H BMC_REMOTE_IP -U username -P password -I lan -L USER sdr

  BMC_REMOTE_IP=IP address assigned to the BMC.

  
username/password=Username/password assigned on the BMC.

  
sdr=reports on various hardware sensors.  Other options are sel for system event log, and fru for hardware information.




Perl Script to Parse Data

  
Now the question is how to take this data, and bring it into Zabbix.  Here’s a sample of a portion of the ipmitool sdr readout:


Temp             | 30 degrees C      | ok
Temp             | disabled          | ns
Ambient Temp     | 19 degrees C      | ok
Planar Temp      | 30 degrees C      | ok
Riser Temp       | 29 degrees C      | ok
Temp             | disabled          | ns
Temp             | disabled          | ns
CMOS Battery     | 3.11 Volts        | ok
FAN 1A RPM       | 7350 RPM          | ok
FAN 1B RPM       | 5025 RPM          | ok
FAN 2A RPM       | 7500 RPM          | ok
FAN 2B RPM       | 5025 RPM          | ok
FAN 3A RPM       | 7425 RPM          | ok
FAN 3B RPM       | 5175 RPM          | ok
FAN 4A RPM       | 7725 RPM          | ok
FAN 4B RPM       | 5175 RPM          | ok

  
Cron Data Dump

  This is only a small portion of what reads out. Data readout from
the BMC is also quite slow. I believe it’s using a 2400 baud serial
connection that shifts to IP. This becomes a problem for bringing into
Zabbix, as the Zabbix agent will time out on a script that reads
directly from the BMC.

  To solve this, we’ll create a cron job that pulls the data, &
puts it into a text file every 3 minutes. edit /etc/crontab & add
the following line:

*/3 * * * * root /etc/zabbix/ipmidump.sh

  This will run the script at /etc/zabbix/ipmidump.sh as root every 3 minutes.  Here’s an example of my ipmidump.sh script:


#!/bin/bash
/usr/bin/ipmitool -H server1_IP -U username -P password -I lan -L USER sdr>/etc/zabbix/server1.dump.$
cp /etc/zabbix/server1.dump.$ /etc/zabbix/server1.dump
/usr/bin/ipmitool -H server2_IP -U username -P password -I lan -L USER sdr>/etc/zabbix/server2.dump.$
cp /etc/zabbix/server2.dump.$ /etc/zabbix/server2.dump

  The script runs the IMPItool dump & places it into a temporary
text file, and then copies that file to it’s permanent location. Repeat
as needed for the number of servers you want to use IPMI for.

  
Parsing Data from the dumpNow we need a script that we can use with the Zabbix agent that will pull the data we want out of the dump.  Parse data from IPMI SDR Readout script(Credit to Rick Wagner for providing the Perlscript.  wagner.234@gmail.com)


#!/usr/bin/perl
# Script provided for Zabbix community by Rick Wagner (wagner.234@gmail.com)
 
 
use
strict;
use
warnings;
 
die
usage(
)
if
(
$#ARGV == -1);
 
my
$regex
= qr
/\s
*\|\s
*/;
my
$val
;
 
#my $OUTPUT;
 
if
(
open
(
FILE, "< /etc/zabbix/server1.dump"
)
)
{
while
(
<FILE>
)
{
chomp
(
$_
)
;
 
my
@fields
= split
(
/$regex
/,$_
)
;
#print $fields[0];
if
(
$#fields >= 2 && $ARGV[0] eq $fields[0]) {
last
if
(
$fields
[
2
]
eq 'ns'
)
;
 
$val
= $fields
[
1
]
;
last
;
}
}

}
else
{
die
"Error:. $!\n
"
;
}
 
if
(
defined
(
$val
)
)
{
(
$val
)
= (
$val
=~ /^(
\d+)
\s
+/)
;
print
$val
."\n
"
;
exit
(
0
)
;
}
else
{
exit
(
-1
)
;
}
 
sub
usage {
return
"Usage: ./$0 <key>"
}

  Usage:/etc/zabbix/server1.pl ‘Parameter’


/etc/zabbix/server1.pl 'Ambient Temp' (Returns 19)
/etc/zabbix/server1.pl 'FAN 1A RPM' (Returns 7350)

  
Linking to Zabbix Agent

  
Edit your zabbix_agentd.conf file & add the following UserParameter lines to the end of the file:


UserParameter=server1.ambtemp,/etc/zabbix/server1.pl 'Ambient Temp'
UserParameter=server1.fan1,/etc/zabbix/server1.pl 'FAN 1 RPM'

  
Restart the agent.  You can now query the Zabbix agent with:


zabbix_agentd -t server1.ambtemp
And you will see:
server1.ambtemp                [t|19]



Integrating with Zabbix

  Because we have added the custom queries to the IPMI into your
zabbix server’s zabbix_agentd, you will need to add the items to your
Zabbix Server Under Configuration/Items.



  • Configuration/Items

  • Create Item

  • Description: Server 1 Ambient Temperature

  • Type: ZABBIX agent

  • Key: server1.ambtemp

  • Units: Deg C

  • Update Interval: 180

  • Set remaining items as you wish
  You will now have history for whatever items you wish to add. I use
IPMI for temperatures, and fan monitoring. Because the data dump takes
over 60 seconds, I only have the cron running every 180 seconds.

  
Good luck!  Hopefully the time I spent getting this working will save you a lot of time in return.




Alternative which only uses a perl script and no zabbix agent

  The zabbix template to use with this perl script can be found hereor on the templatespage.
I guess the comments in the perl script speak for themselves, the
script can easily be extended to report more data, but I am only
interested in the fans and temperatures at the moment. Feel free to
post improvements.


#!/usr/bin/perl
 
#########################################################################
# The purpose of the perl script is to parse the output of ipmitool and #
# send it to a zabbix server, no zabbix_agent needed                    #
#                                                                       #
# You need to have impitool installed to use this script                #
#                                                                       #
# Suggested usage is to run this script from a cronjob                  #
#                                                                       #
# Have fun with it, Emiel Witteman                                      #
#########################################################################
 
use
strict;
use
warnings;
use
IO::Socket
;
use
IO::Select
;
use
MIME::Base64
;
 
#################
# Configuration #
#################
my
$zabbixserver
= "zabbix.somewhere.lan"
;
my
$zabbixport
= "10051"
;
my
$zabbixhost
= "myhost"
;
my
$fieldsep
= qr
/\s
*\|\s
*/;
 
my
$i
=0
;
my
$tempnr
=0
;
 
my
@IPMI
=split
(
/\n/,`ipmitool sensor`)
;
while
(
$IPMI
[
$i
]
)
{
my
@fields
= split
(
/$fieldsep
/,$IPMI
[
$i
]
)
;
 
###############
# Report FANs #
###############
#output from ipmitool:
#FAN 1 RPM        | 5250.000   | RPM        | ok    | na        | 2025.000  | na        | na        | na        | na
#FAN 2 RPM        | 5250.000   | RPM        | ok    | na        | 2025.000  | na        | na        | na        | na
#FAN 3 RPM        | 5400.000   | RPM        | ok    | na        | 2025.000  | na        | na        | na        | na
#FAN 4 RPM        | 5250.000   | RPM        | ok    | na        | 2025.000  | na        | na        | na        | na
#FAN 5 RPM        | 4200.000   | RPM        | ok    | 14400.000 | na        | 0.000     | 0.000     | na        | na
#FAN 6 RPM        | 4200.000   | RPM        | ok    | 14400.000 | na        | 0.000     | 0.000     | na        | na
if
(
$fields
[
0
]
=~ /FAN/)
{
#     print "DEBUG: $fields[0],$fields[1],$fields[2],$fields[3],$fields[4]\n";
$fields
[
0
]
=~ s
/RPM//;        #remove "RPM"
$fields
[
0
]
=~ s
/^\s
+|\s
+$//g; #remove starting/trailing whitespace
$fields
[
0
]
=~ s
/\s
/_/g;       #substitute whitespace by _
$fields
[
0
]
= lc
(
$fields
[
0
]
)
;  #make lowercase
&zabbix_sender(
$zabbixserver
, $zabbixhost
, "sensor.$fields[0].rpm"
, $fields
[
1
]
)
;
if
(
$fields
[
3
]
=~ /^ok$/)
{
&zabbix_sender(
$zabbixserver
, $zabbixhost
, "sensor.$fields[0].status"
, 1
)
;
}
else
{
&zabbix_sender(
$zabbixserver
, $zabbixhost
, "sensor.$fields[0].status"
, 0
)
;
}
}
 
################
# Report Temps #
################
#output from ipmitool:
#Temp             | -52.000    | degrees C  | ok    | na        | na        | na        | 85.000    | 90.000    | na
#Temp             | 50.000     | degrees C  | ok    | na        | na        | na        | 85.000    | 90.000    | na
#Temp             | 40.000     | degrees C  | ok    | 64.000    | na        | -128.000  | -128.000  | na        | na
#Temp             | 40.000     | degrees C  | ok    | 64.000    | na        | -128.000  | -128.000  | na        | na
#Ambient Temp     | 23.000     | degrees C  | ok    | na        | 3.000     | 8.000     | 42.000    | 47.000    | na
if
(
$fields
[
0
]
=~ /^Temp$/)
{
if
(
$tempnr
>0
)
{
$fields
[
0
]
= lc
(
$fields
[
0
]
)
;  #make lowercase
#       print "DEBUG: $fields[0],$fields[1],$fields[2],$fields[3],$fields[4]\n";
&zabbix_sender(
$zabbixserver
, $zabbixhost
, "sensor.$fields[0]$tempnr"
, $fields
[
1
]
)
;
if
(
$fields
[
3
]
=~ /^ok$/)
{
&zabbix_sender(
$zabbixserver
, $zabbixhost
, "sensor.$fields[0]$tempnr.status"
, 1
)
;
}
else
{
&zabbix_sender(
$zabbixserver
, $zabbixhost
, "sensor.$fields[0]$tempnr.status"
, 0
)
;
}
}
$tempnr
++;
}
if
(
$fields
[
0
]
=~ /^Ambient Temp$/)
{
$fields
[
0
]
=~ s
/\s
/_/g;       #substitute whitespace by _
$fields
[
0
]
= lc
(
$fields
[
0
]
)
;  #make lowercase
#     print "DEBUG: $fields[0],$fields[1],$fields[2],$fields[3],$fields[4]\n";
&zabbix_sender(
$zabbixserver
, $zabbixhost
, "sensor.$fields[0]"
, $fields
[
1
]
)
;
#     if ($fields[3] =~ /^ok$/){
#       &zabbix_sender($zabbixserver, $zabbixhost, "sensor.$fields[0].status", 1);
#     } else {
#       &zabbix_sender($zabbixserver, $zabbixhost, "sensor.$fields[0].status", 0);
#     }
}
 
$i
++;
}
 
sub
zabbix_sender
{
my
(
$zabbixserver
,$hostname
,$item
,$data
)
= @_
;
my
$timeout
=10
;
my
$result
;
 
my
$request
=sprintf
(
"<req>\n
<host>%s</host>\n
<key>%s</key>\n
<data>%s</data>\n
</req>\n
"
,
encode_base64(
$hostname
)
,encode_base64(
$item
)
,encode_base64(
$data
)
)
;
 
my
$sock
= new
IO::Socket
::INET
(
PeerAddr => $zabbixserver
, PeerPort => '10051'
, Proto => 'tcp'
, Timeout => $timeout
)
;
die
"Could not create socket: $!\n
"
unless
$sock
;
$sock
->send
(
$request
)
;
my
@handles
=IO::Select
->new
(
$sock
)
->can_read
(
$timeout
)
;
if
(
scalar
(
@handles
)
> 0
)
{
$sock
->recv
(
$result
,1024
)
;
if
(
$result
ne
"OK"
)
{
#only print response if not OK
print
"answer from zabbix server $zabbixserver: $result\n
"
;
}
}
else
{
print
"no answer from zabbix server\n
"
;
}
$sock
->close
(
)
;
}



<!---->

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-366794-1-1.html 上篇帖子: 总结zabbix开发app及使用经验 下篇帖子: 开源监控工具Zabbix
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表