Nagios Monitoring Series Learning--check_nrpe Understanding

Source: Internet
Author: User


The Nagios server does not have a Check_nrpe plug-in by default and needs to compile and install Nrpe.


Nrpe provides the CHECK_NRP and Nrpe binaries and the configuration files required to start the process.


For the Nagios server, it only needs to Check_nrpe plug-in to send monitoring instructions, while the monitored side needs to be monitored by the Nrpe process to the server sent over the instructions (the default listener 5666), and execute the local plug-in to obtain information, and finally passed back to the monitoring side. This shows that the monitored side needs to install Nagios-plugins to obtain the plug-in, but if the monitoring side does not use the plug-in provided by the plugins component, of course, there is no need to install.


Nrpe Compilation and Installation summary:

User Nagios and group Nagios are used by default, preferably created in advance

[Email protected] nrpe-2.15]#/configure--prefix=/mnt #测试目录 [[email protected] nrpe-2.15]# [[email protected] nrpe-2. 15]# make all [[email protected] nrpe-2.15]# make install [[email protected] nrpe-2.15]#
[Email protected] nrpe-2.15]# Tree/mnt/mnt├──bin│└──nrpe└──libexec└──check_nrpe

Binaries and plugins have been generated, and for the Nagios server, after this step, directly copy the Check_nrpe to the Nagios plugin to store the directory (note executable permissions).


For the monitored side, the Check_nrpe plugin is useless, but requires Nrpe to provide a listening service, but at this time the installation directory does not have a configuration file:

[email protected] nrpe-2.15]# make Install-daemon-config/usr/bin/install-c-M 775-o nagios-g nagios-d/mnt/etc/usr/bi N/install-c-M 644-o nagios-g Nagios sample-config/nrpe.cfg/mnt/etc

You can manually copy the configuration files from the source directory to the installation directory and modify the subordinate and sample-config/nrpe.cfg groups.


Simply look at the configuration file, you need to modify the allowed_hosts, the Nagios server IP is added to the rear, separated by commas:

server_port=5666#server_address=127.0.0.1nrpe_user=nagiosnrpe_group=nagiosallowed_hosts=127.0.0.1, $NagiosIP

With the configuration file can start the Nrpe process, there are two ways, one is the independent daemon, a Super daemon way.

Independent Daemon:

[[EMAIL PROTECTED] NRPE-2.15]# [[EMAIL PROTECTED] NRPE-2.15]# NETSTAT -ANTP  | grep 5666[[email protected] nrpe-2.15]# /mnt/bin/nrpe  -c /mnt /etc/nrpe.cfg -n -d[[email protected] nrpe-2.15]# netstat -antp | grep  5666tcp        0      0  0.0.0.0:5666                 0.0.0.0:*                    LISTEN      13643/nrpe           tcp        0       0 :::5666                      :::*                          LISTEN      13643/nrpe           [[email protected] nrpe-2.15]#

-C Specify configuration file

-N does not use SSL, default is used, compile-time parameter--enable-ssl can be added, should be the default option

If the-n is used, the Nagios monitor also needs to specify this parameter when using Check_nrpe.

-D is started by independent daemon mode


The Super Daemon , which requires inetd or xinetd, specifies the "-i" parameter when editing the relevant configuration file.


For ease of start, add services to Chkconfig

Reference script:

#!/bin/bash# chkconfig: 35 78 22lock_file= '/var/lock/subsys/nrped ' NRPE_COMMAND= '/usr/local /nrpe/bin/nrpe ' nrpe_configure_file= '/usr/local/nrpe/etc/nrpe.cfg ' Start () {echo -n  "starting  nrped ...  "$NRPE _command -c  $NRPE _configure_file -d &>/dev/null  && touch  $LOCK _file &>/dev/null[[ $? -eq 0 ]] & & echo -e  "\033[1;32mok\033[0m"  | |  echo -e  "\033[1;31mfail\033[0m"  }stop () {echo -n  "STOPPING NRPED    "killall nrpe &>/dev/null && rm -f  $LOCK _file & >/dev/ull[[ $? -eq 0 ]] && echo -e  "\033[1;32mok\033[0m"  | |  echo -e  "\033[1;31mfail\033[0m"}status () {[[ -f  $LOCK _file ]] &&  echo  "nrpe is running&nbsp ..."  | |  echo  "Nrpe isn ' t running ...  "}case $1 in start)  start ;;  stop)  stop ;; Restart)  stop; start ;; Status)  status ;; Esac


Post-processing and testing:

[[email protected] nrpe-2.15]# chmod +x /etc/init.d/nrped[[email protected]  nrpe-2.15]# chkconfig --add nrped [[email protected] nrpe-2.15]#  Chkconfig --list| grep nrpednrped          0 :off1:off2:off3:on4:off5:on6:off[[email protected] nrpe-2.15]# service nrped  startstarting nrped ... ok[[email protected] nrpe-2.15]# service nrped  stop stopping nrped ... ok[[email protected] nrpe-2.15]# service  nrped restart stopping nrped ... failstarting nrped ... ok[[ EMAIL PROTECTED] NRPE-2.15]# SERVICE NRPED RESTART STOPPING NRPED&NBSP, .....  okstarting nrped ... ok[[email protected] nrpe-2.15]# service nrped  STATUSNRPE IS RUNNING&NBSP, ..... [[email protected]  nrpe-2.15]# netstat -antp | grep nrpetcp         0      0 0.0.0.0:5666                 0.0.0.0:*                    listen       13940/nrpe          tcp         0      0 :::5666                       :::*                          listen      13940/nrpe           [[email protected] nrpe-2.15]# 


about the monitored end plug-in:

The instructions that the Nagios monitoring side can invoke "remote" need to be defined in advance in the Nrpe configuration file of the monitored side, as follows:

Command[check_users]=/mnt/libexec/check_users-w 5-c 10command[check_load]=/mnt/libexec/check_load-w 15,10,5-c 30,25,20command[check_hda1]=/mnt/libexec/check_disk-w 20%-C 10%-p/dev/hda1command[check_zombie_procs]=/mnt/ Libexec/check_procs-w 5-c 10-s zcommand[check_total_procs]=/mnt/libexec/check_procs-w 150-c #command [check_users ]=/mnt/libexec/check_users-w $ARG 1$-C $ARG 2$ #command [check_load]=/mnt/libexec/check_load-w $ARG 1$-C $ARG 2$ #command [Check_disk]=/mnt/libexec/check_disk-w $ARG 1$-C $ARG 2$-P $ARG 3$ #command [Check_procs]=/mnt/libexec/check_procs-w $ arg1$-C $ARG 2$-S $ARG 3$

You can define a directive with a definite threshold value, or you can leave a "variable" for the monitoring side to specify.

These instructions are the instructions generated after the installation of Nagios-plugins, and now manually write a simple monitoring plugin with the shell.

The following rules are required to develop plug-ins:

The plug-in requires a return value and a piece of output, and Nagios accepts only the first output.

The corresponding relationship between the return value and Nagios five states is as follows:

0:ok

1:warnning

2:critical

3:unknown

4:pending


The script feature is simple to monitor the local memory, the code is as follows:

#!/bin/bash#author: linigyi#  "Memory check" ok=0warnning=1critical=2unknown=3pending=4mem_string =$ (FREE -M | GREP MEM) totle=$ (echo  $mem _string | awk  ' {print $2} ' ) used=$ (echo  $mem _string | awk  ' {print $3} ') free=$ (echo  $mem _string |  awk  ' {print $4} ') used_percent_string=$ (echo  "Scale=3; ${used}/${totle}"  | BC) used_percent_aa=${used_percent_string:1:2}used_percent_bb=${used_percent_string:3:1}if [[  $used _ percent_bb -ge 5 ]]; thenused_percent=$ ((used_percent_aa+=1)) elseused_percent=${used_ percent_aa}fi[[ $1 ==  '-W '  ]] && shift && warnning=$1  && shift[[ $1 ==  '-C '  ]] && shift &&  critical=$1 [[  $warnning  -gt  $critical  ]] && {echo value  wrong !! Exit  $PENDING}if [[  $used _percent -ge  $critical  ]]; thenecho critical -  Totle:  $totle  Used:  $used  Free:  $free,  used percent: ${used_ percent}%exit  $CRITICALelif  [[  $used _percent -ge  $warnning  ]]; thenecho  WARNNING - Totle:  $totle  Used:  $used  Free:  $free, used  percent: ${used_percent}%exit  $WARNNINGelseecho  OK - Totle:  $totle  used:   $used  Free:  $free, used percent: ${used_percent}%exit  $OKfi


Plug-in output format for basic analog plugins

Test Plug-ins:

First modify the configuration file and add the Nagios server IP to the Allow list:

[Email protected] mnt]# Cat/mnt/etc/nrpe.cfg | grep allowed_hostsallowed_hosts=127.0.0.1, 172.19.2.250[[email protected] mnt]#
[Email protected] mnt]# ls-l/mnt/libexec/total 240-rwxr-xr-x. 1 root root 160049 Apr 18:10 check_load-rwxr-xr-x. 1 root root 1098 Apr 18:14 check_mem-rwxrwxr-x. 1 Nagios nagios 76825 Apr 16:54 check_nrpe[[email protected] mnt]#

Plugins must have executable permissions! Copy a contrasting plug-in check_load

[Email protected] mnt]# Cat/mnt/etc/nrpe.cfg | grep ' ^command ' command_timeout=60command[check_users]=/mnt/libexec/check_users-w 5-c 10command[check_load]=/mnt/ Libexec/check_load-w 15,10,5-c 30,25,20command[check_hda1]=/mnt/libexec/check_disk-w 20%-C 10%-p/dev/hda1command[ Check_zombie_procs]=/mnt/libexec/check_procs-w 5-c 10-s zcommand[check_total_procs]=/mnt/libexec/check_procs-w 150 -C-Command[check_mem]=/mnt/libexec/check_mem-w 20-c 40[[email protected] mnt]#

The last CHECK_MEM directive defines itself.

Start Nrpe

[[email protected] mnt]# [[email protected] mnt]# killall nrpe[[email  protected] mnt]# netstat -antp | grep nrpe[[email protected] mnt]#  /mnt/bin/nrpe -c /mnt/etc/nrpe.cfg  -d [[email protected] mnt]#  netstat -antp | grep nrpetcp        0       0 0.0.0.0:5666                 0.0.0.0:*                    LISTEN      14831/nrpe           tcp        0       0 :::5666                       :::*                          LISTEN       14831/nrpe          [[email protected]  mnt]#


Do the testing on the Nagios server:

[[Email protected] libexec]# ip add show 1: lo: <loopback,up,lower_ up> mtu 16436 qdisc noqueue state unknown     link/ Loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00    inet 127.0.0.1/8  scope host lo    inet6 ::1/128 scope host         valid_lft forever preferred_lft forever2: eth0: < Broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state up qlen  1000    link/ether 00:1a:4a:94:7d:2e brd ff:ff:ff:ff:ff:ff     inet 172.19.2.250/24 brd 172.19.2.255 scope global eth0     inet6 fe80::21a:4aff:fe94:7d2e/64 scope link         valid_lft forever preferred_lft forever[[email protected] libexec]# [[email  Protected] libexec]# [[email protected] libexec]# pwd/usr/local/nagios/libexec[[email  protected] libexec]# ./check_nrpe  -h 192.168.2.162 -c check_loadok  - load average: 0.00, 0.00, 0.00|load1=0.000;15.000;30.000;0; load5=0.000; 10.000;25.000;0; load15=0.000;5.000;20.000;0; [[email protected] libexec]# [[email  protected] libexec]# echo $?0[[email protected] libexec]# [[email  Protected] libexec]# ./check_nrpe  -h 192.168.2.162 -c check_memwarnning  - totle: 3828 used: 871 free: 2956, used percent: 23%[[ email protected] libexec]# echo $?1[[email protected] libexec]#

Test success!


Monitoring services can now be added to the Nagios monitoring side!

This article is from the "retrograde person" blog, please be sure to keep this source http://lingyi.blog.51cto.com/2837715/1766785

Nagios Monitoring Series Learning--check_nrpe Understanding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.