在nagios中使用nrpe自定义脚本
nrpe的安裝
??? tar xvfz nrpe-2.13.tar.gz
??? cd nrpe-2.13
??? ./configure
??? make all
??? make install-plugin
??? make install-daemon
??? make install-daemon-config
??? yum install xinetd
??? make install-xinetd
[root@nhserver2 ~]# vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.5.10
[root@nhserver2 ~]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
??????? flags?????????? = REUSE
??????? socket_type???? = stream
??????? port??????????? = 5666
??????? wait??????????? = no
??????? user??????????? = nagios
??????? group?????????? = nagios
??????? server????????? = /usr/local/nagios/bin/nrpe
??????? server_args???? = -c /usr/local/nagios/etc/nrpe.cfg --inetd
??????? log_on_failure? += USERID
??????? disable???????? = no
??????? only_from?????? = 127.0.0.1 192.168.5.10?? # 這個(gè)IP可以不變,為本機(jī)
}
[root@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12
[root@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.10??? #192.168.5.10為nagios服務(wù)器的ip
NRPE v2.12
[root@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110?? #192.168.5.110還未開機(jī)
Connection refused or timed out
[root@nhserver2 ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110?? #192.168.5.110開機(jī)
CHECK_NRPE: Error - Could not complete SSL handshake.
[root@nhserver2 ~]# service xinetd restart? #重啟nrpe服務(wù)
=========================================================================================================================
在192.168.5.110被監(jiān)控端安裝nrpe
1.安裝nrpe依賴包
yum -y install gcc glibc glibc-common openssl openssl-devel
2.安裝nagios-plugin
useradd nagios
wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz/download
tar zxf nagios-plugins-1.4.15.tar.gz && cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chown -R nagios.nagios /usr/local/nagios
3.安裝nrpe
wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz
tar zxf nrpe-2.12.tar.gz && cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
4.啟動(dòng)nrpe并設(shè)置開機(jī)自啟動(dòng)
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.d/rc.local
[root@nhserver1 ~]# vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.5.10?? #將nagios的服務(wù)端IP加上
[root@nhserver1 ~]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
??????? flags?????????? = REUSE
??????? socket_type???? = stream
??????? port??????????? = 5666
??????? wait??????????? = no
??????? user??????????? = nagios
??????? group?????????? = nagios
??????? server????????? = /usr/local/nagios/bin/nrpe
??????? server_args???? = -c /usr/local/nagios/etc/nrpe.cfg --inetd
??????? log_on_failure? += USERID
??????? disable???????? = no
??????? only_from?????? = 127.0.0.1 192.168.5.10?? #將nagios的服務(wù)端IP加上
}
==============? 在nagios服務(wù)端測(cè)試 ====================
[root@nhserver2 ~]#
NRPE v2.12
=================================================================
要在被監(jiān)控端192.168.5.110加入自定義的腳本
[root@nhserver1 libexec]# vim /usr/local/nagios/libexec/nh_check_users
#!/bin/bash
# for nrpe check user
U=`who | wc -l`
if [ $U -le 3 ];then
echo "OK,current user is.$U"
exit 0
elif [ $U -gt 6 ];then
echo "CRITICAL,current user is.$U"
exit 2
else
echo "WARNING,current user is.$U"
exit 1
fi
定義該腳本為nagios用戶和nagios組
[root@nhserver1 libexec]# chown nagios.nagios /usr/local/nagios/libexec/nh_check_91
在NRPE上加入該自定義命令
[root@nhserver1 libexec]# vim /usr/local/nagios/etc/nrpe.cfg
command[nh_check_users]=/usr/local/nagios/libexec/nh_check_users
在服務(wù)端測(cè)試192.168.5.10,直接使用命令行
[root@nhserver2 libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110 -c nh_check_users
OK,current user is.1
=========================================================================
在服務(wù)端測(cè)試192.168.5.10的nagios中加入自定義腳本
[root@nhserver2 objects]# cd /usr/local/nagios/etc/objects
[root@nhserver2 objects]# vim hosts_192.168.5.110.cfg
define host{
??????? use???????????????????? linux-server
??????? host_name?????????????? 192.168.5.110
??????? alias?????????????????? 192.168.5.110
??????? address???????????????? 192.168.5.110
??????? }
define hostgroup{
??????? hostgroup_name????????? nh_linuxs
??????? alias?????????????????? nh_linuxs
??????? members???????????????? 192.168.5.110
??????? }
define service{
??????? use???????????????????? local-service
??????? host_name?????????????? 192.168.5.110
??????? service_description???? check-host-alive
??????? check_command?????????? check-host-alive
??????? max_check_attempts????? 5
??????? normal_check_interval?? 3
??????? retry_check_interval??? 2
??????? check_period??????????? 24x7
??????? notification_interval?? 10
??????? notification_period???? 24x7
???? }
define service{
??????? use???????????????????? local-service
??????? host_name?????????????? 192.168.5.110
??????? service_description???? SSH
??????? check_command?????????? check_ssh
??????? max_check_attempts????? 5
??????? normal_check_interval?? 3
??????? retry_check_interval??? 2
??????? check_period??????????? 24x7
??????? notification_interval?? 10
??????? notification_period???? 24x7
??????? }
define service{
??????? use???????????????????? local-service
??????? host_name?????????????? 192.168.5.110
??????? service_description???? check_nrpe_check_users
??????? check_command?????????? check_nrpe!nh_check_users
??????? max_check_attempts????? 5
??????? normal_check_interval?? 3
??????? retry_check_interval??? 2
??????? check_period??????????? 24x7
??????? notification_interval?? 10
??????? notification_period???? 24x7
??????? }
過一下,在nagios中就能觀察到check_nrpe_check_users自定義服務(wù)的狀態(tài)了,"OK,current user is.1".
[root@nhserver2 objects]# service nagios reload
Host Sort by host name (ascending)Sort by host name (descending)?? ?Service Sort by service name (ascending)Sort by service name (descending)?? ?
Status Sort by service status (ascending)Sort by service status (descending)?? ?Last Check Sort by last check time (ascending)Sort by last check time
(descending)?? ?Duration Sort by state duration (ascending)Sort by state duration time (descending)?? ?Attempt Sort by current attempt (ascending)Sort by
current attempt (descending)?? ?Status Information
192.168.5.110
?? ?
?? ?
SSH
?? ?
?? ?OK ?? ?04-04-2014 20:22:01 ?? ?0d 0h 1m 56s ?? ?1/5 ?? ?SSH OK - OpenSSH_5.3 (protocol 2.0)
?? ?
check-host-alive
?? ?
?? ?OK ?? ?04-04-2014 20:22:50 ?? ?0d 0h 2m 56s ?? ?1/5 ?? ?PING OK - Packet loss = 0%, RTA = 0.61 ms
?? ?
check_nrpe_check_users
?? ?
?? ?OK ?? ?04-04-2014 20:23:38 ?? ?0d 0h 0m 19s ?? ?1/5 ?? ?OK,current user is.1
轉(zhuǎn)載于:https://www.cnblogs.com/nhlinkin/p/3645951.html
總結(jié)
以上是生活随笔為你收集整理的在nagios中使用nrpe自定义脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Xamarin简介与Xamarin支持M
- 下一篇: Socket阻塞与非阻塞,同步与异步、I