Author Topic: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server  (Read 15628 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« on: พฤษภาคม 07, 2016, 02:25:44 PM »
ถ้าท่านใช้งาน nagios เป็นตัวเชค status service บน server อยู่
อยากแนะนำ tool ของ nagios อีกตัวคือ nrpe ครับ สามารถช่วยให้การ monitoring ละเอียดและสบายขึ้นครับ

ฝั่ง client ลงสองตัวนะครับ nrpe กับ nagios-plugin
ฝั่ง monitoring server ลง nrpe + nagios (ลงไว้อยู่แล้ว)

##download nrpe new version
https://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

##Download nagios-plugin new version
http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

Install nrpe and nagios-plugin in remote host and nrpe on monitoring server

I. Overview

II. 6 steps to install Nagios plugin and NRPE on remote host.

Download Nagios Plugins and NRPE Add-on
Create nagios account
Install Nagios Plugins
Install NRPE
Setup NRPE to run as daemon
Modify the /usr/local/nagios/etc/nrpe.cfg
III. 4 Configuration steps on the Nagios monitoring server to monitor remote host:

Download NRPE Add-on
Install check_nrpe
Create host and service definition for remote host
Restart the nagios service

I. Overview:

Following three steps will happen on a very high level when Nagios (installed on the nagios-servers) monitors a service (for e.g. disk space usage) on the remote Linux host.
 
Nagios will execute check_nrpe command on nagios-server and request it to monitor disk usage
on remote host using check_disk command.
The check_nrpe on the nagios-server will contact the NRPE daemon on remote host
and request it to execute the check_disk on remote host.
The results of the check_disk command will be returned back by NRPE daemon to the check_nrpe on nagios-server.

Following flow summarizes the above explanation:

Nagios Server (check_nrpe) —–> Remote host (NRPE deamon) —–> check_disk

Nagios Server (check_nrpe) <—– Remote host (NRPE deamon) <—– check_disk (returns disk space usage)

II. 7 steps to install Nagios Plugins and NRPE on the remote host

1. ทำการ Download Nagios Plugins และ NRPE Add-on มาไว้ในเครื่อง remotehost

Download following files from Nagios.org and move to /home/downloads:

 nagios-plugins-2.1.1.tar.gz
 nrpe-2.15.tar.gz

2. Create nagios account
[remotehost]# useradd nagios
[remotehost]# passwd nagios

3. Install nagios-plugin
[remotehost]# cd /home/downloads
[remotehost]# tar xvfz nagios-plugins-2.1.1.tar.gz
[remotehost]# cd nagios-plugins-2.1.1
[remotehost]# export LDFLAGS=-ldl
[remotehost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
[remotehost]# make
[remotehost]# make install

ทำการเปลี่ยนสิทธิ์ของ folder nagios
[remotehost]# chown nagios:nagios /usr/local/nagios
[remotehost]# chown -R nagios:nagios /usr/local/nagios/libexec/

Note: On Red Hat, For me the ./configure command was hanging with the the message: “checking for redhat spopen problem…”. Add --enable-redhat-pthread-workaround to the ./configure command as a work-around for the above problem.

4. Install NRPE

[remotehost]# cd /home/downloads
[remotehost]# tar xvfz nrpe-2.15.tar.gz
[remotehost]# cd nrpe-2.15

[remotehost]# ./configure

####ถ้าเจอ error ssl header ใน centos ตอน configure แสดงว่ายังมี package ไม่ครบให้ทำการลงตัว openssl-devel
#yum install openssl-devel

####ถ้าใน debian , ubuntu
#apt-get install libssl-dev

ถ้าใน ubuntu อาจจะลองเชคว่ามี libssl-dev ยังนะครับถ้ามีแล้วก็ทำ link module ไป
#ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/libssl.so

เพิ่มเสร็จแล้วก็ ./configure อีกรอบนะครับ
[remotehost]# ./configure

[remotehost]# make all
[remotehost]# make install-plugin
[remotehost]# make install-daemon
[remotehost]# make install-daemon-config

ในส่วนนี้ถ้าต้องการให้รัน service ผ่าน xinetd ก็เพิ่มลงไปแต่ถ้าใครจะไปรันเป็น daemon service ก็สุดแค่นี้ครับผม : )

[remotehost]# make install-xinetd
5. Setup NRPE to run as daemon (i.e as part of xinetd):

Modify the /etc/xinetd.d/nrpe to add the ip-address of the Nagios monitoring server to the only_from directive. Note that there is a space after the 127.0.0.1 and the nagios monitoring server ip-address (in this example, nagios monitoring server ip-address is: 192.168.1.2)
       only_from       = 127.0.0.1 192.168.1.2
Modify the /etc/services and add the following at the end of the file.
       nrpe 5666/tcp # NRPE
Start the service
       [remotehost]#service xinetd restart
Verify whether NRPE is listening
       [remotehost]# netstat -at | grep nrpe
       tcp 0      0 *:nrpe *:*                         LISTEN
Verify to make sure the NRPE is functioning properly
[remotehost]# /usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v2.12

6. Modify the /usr/local/nagios/etc/nrpe.cfg

The nrpe.cfg file located on the remote host contains the commands that are needed to check the services on the remote host. By default the nrpe.cfg comes with few standard check commands as samples. check_users and check_load are shown below as an example.

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

In all the check commands, the “-w” stands for “Warning” and “-c” stands for “Critical”. for e.g. in the check_disk command below, if the available disk space gets to 20% of less, nagios will send warning message. If it gets to 10% or less, nagios will send critical message. Change the value of “-c” and “-w” parameter below depending on your environment.

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

Note: You can execute any of the commands shown in the nrpe.cfg on the command line on remote host and see the results for yourself. For e.g. When I executed the check_disk command on the command line, it displayed the following:

[remotehost]#/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
DISK CRITICAL - free space: / 6420 MB (10% inode=98%);| /=55032MB;51792;58266;0;64741

In the above example, since the free disk space on /dev/hda1 is only 10% , it is displaying the CRITICAL message, which will be returned to nagios server.

ขั้นตอนที่ ทำการติดตั้ง NRPE ในฝั่ง Server

4 Configuration steps on the Nagios monitoring server to monitor remote host:

1. Download NRPE Add-on

Download nrpe-2.12.tar.gz from Nagios.org and move to /home/downloads:

2. Install check_nrpe on the nagios monitoring server

[nagios-server]# tar xvfz nrpe-2.12.tar.gz
[nagios-server]# cd nrpe-2.1.2
[nagios-server]# ./configure
[nagios-server]# make all
[nagios-server]# make install-plugin

./configure will give a configuration summary as shown below:

*** Configuration summary for nrpe 2.12 05-31-2008 ***:

General Options:
————————-
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
 

Note: I got the “checking for SSL headers… configure: error: Cannot find ssl headers” error message while performing ./configure. Install openssl-devel as shown below and run the ./configure again to fix the problem.

[nagios-server]# rpm -ivh openssl-devel-0.9.7a-43.16.i386.rpm krb5-devel-1.3.4-47.i386.rpm zlib-devel-1.2.1.2-1.2.i386.rpm e2fsprogs-devel-1.35-12.5.
el4.i386.rpm
warning: openssl-devel-0.9.7a-43.16.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing… ########################################### [100%]
1:e2fsprogs-devel ########################################### [ 25%]
2:krb5-devel ########################################### [ 50%]
3:zlib-devel ########################################### [ 75%]
4:openssl-devel ########################################### [100%]
Verify whether nagios monitoring server can talk to the remotehost.

[nagios-server]#/usr/local/nagios/libexec/check_nrpe -H 192.168.1.3
NRPE v2.12

Note: 192.168.1.3 in the ip-address of the remotehost where the NRPE and nagios plugin was installed as explained in Section II above.

3. Create host and service definition for remotehost

Create a new configuration file /usr/local/nagios/etc/objects/remotehost.cfg to define the host and service definition for this particular remotehost. It is good to take the localhost.cfg and copy it as remotehost.cfg and start modifying it according to your needs.
 

host definition sample:

define host{
use linux-server
host_name remotehost
alias Remote Host
address 192.168.1.3
contact_groups admins
}

Service definition sample:

define service{
use generic-service
service_description Root Partition
contact_groups admins
check_command check_nrpe!check_disk
}
Note: In all the above examples, replace remotehost with the corresponding hostname of your remotehost.

4. Restart the nagios service

Restart the nagios as shown below and login to the nagios web (http://nagios-server/nagios/) to verify the status of the remotehost linux sever that was added to nagios for monitoring.

[nagios-server]# service nagios reload
« Last Edit: พฤษภาคม 25, 2019, 02:52:37 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #1 on: พฤษภาคม 07, 2016, 02:56:30 PM »
ถ้าใครจะใช้ตัว nrpe ผ่าน init-script แทนการใช้งานผ่าน xinetd ก็ได้นะครับผม
ก็ปรับตามนี้ครับ

#cd nrpe
#cp init-script /etc/init.d/nrpe
#chmod 755 /etc/init.d/nrpe

#/etc/init.d/nrpe restart
ก็ใช้งานได้เลยครับผม

ส่วน configure ของ nrpe จะอยู่ที่
$/usr/local/nagios/etc/nrpe.cfg

แล้วทำการตั้งค่าให้ nrpe start เองอัตโนมัติตอน reboot เครื่องครับ

###On CentOS
#chkconfig --level 235 nrpe on


###On debian and ubuntu
#update-rc.d nrpe defaults
« Last Edit: กุมภาพันธ์ 03, 2021, 02:56:23 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #2 on: พฤษภาคม 07, 2016, 03:29:49 PM »
ในส่วนของไฟล์ command.cfg ในเครื่อง monitoring_server ใส่เป็นแบบนี้นะครับ

define command {
       command_name                             check_nrpe
       command_line                             $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$ $ARG2$
}

แล้วในส่วนของ hosts.cfg
ใส่เป็น

define service{
        use                             local-service         ; Name of service template to use
        host_name                       kingkong.packetlove.com
        service_description             Current Users
        check_command                   check_nrpe!check_users
        }


golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #4 on: พฤษภาคม 07, 2016, 03:58:27 PM »
[root@dev objects]# /usr/local/nagios/libexec/check_nrpe -H 103.246.22.33 -c check_home
DISK OK - free space: /home 776813 MB (92% inode=99%);| /home=62310MB;707229;795633;0;884037
[root@dev objects]# /usr/local/nagios/libexec/check_nrpe -H 103.246.22.33 -c check_total_procs
PROCS OK: 266 processes | procs=266;320;400;0;
[root@dev objects]# /usr/local/nagios/libexec/check_nrpe -H 103.246.22.33 -c check_load

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #5 on: พฤษภาคม 08, 2016, 12:55:20 PM »
#!/bin/bash

###
###Shell script install on remote host  by golfreeze [at] packetlove.com ###
###

export PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin

cd /home/root
mkdir -p nagios_nrpe
cd nagios_nrpe

wget --no-check-certificate https://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

tar zxf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
useradd nagios
passwd nagios

export LDFLAGS=-ldl
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround && make && make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec/

cd ..
tar zxf nrpe-2.15.tar.gz
cd nrpe-2.15

./configure
make all
make install-plugin
make install-daemon
make install-daemon-config

cp init-script /etc/init.d/nrpe
chmod 755 /etc/init.d/nrpe

/etc/init.d/nrpe restart

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #6 on: พฤษภาคม 08, 2016, 02:06:31 PM »
ถ้าใครต้องการใช้งานตัว script เชค จำนวน mailqueue โดยให้ nrpe ทำการเชคให้ก็ download script ตามนี้ครับ
https://exchange.nagios.org/directory/Plugins/Email-and-Groupware/Exim/check_eximailqueue/details

ปัจจุบันเป็น version 1.3
#wget https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=1342&cf_id=35

check_eximailqueue_1.3

cd /usr/local/nagios/libexec
mv /root/check_eximailqueue .

แก้ไขค่า EXIM path, SUDO path
vi check_eximailqueue
EXIM=/usr/sbin/exim
SUDO=/usr/local/bin/sudo

แล้วเพิ่ม configure 2 ตัวลงใน sudoer เพื่อแก้ไขปัญหาตัว error
Mailqueue WARNING - query returned no output!

fixed by

#visudo
nagios  ALL=NOPASSWD:/usr/sbin/exim
Defaults:nagios !requiretty

ทำการเพิ่มสคิป check_eximailqueue ใน nrpe.cfg
###Check eximailqueue
command[check_eximailqueue]=/usr/local/nagios/libexec/check_eximailqueue -w 50 -c 100

Restart nrpe daemon 1 ครั้งในฝั่ง remotehost หรือฝั่ง client
#/etc/init.d/nrpe restart

เท่านี้ก็สามารถใช้งาน check_eximailqueue ได้ละครับผม
[root@dev libexec]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_eximailqueue
0
Mailqueue OK - 0 messages on queue
« Last Edit: มิถุนายน 21, 2020, 12:11:19 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #7 on: พฤษภาคม 08, 2016, 06:50:20 PM »
### nrpe2 init-script on freebsd 8-9

#!/bin/sh

# $FreeBSD: ports/net-mgmt/nrpe2/files/nrpe2.in,v 1.8 2012/10/08 08:15:28 dougb Exp $
#
# PROVIDE: nrpe2
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable nrpe2:
# nrpe2_enable (bool):    Set to "NO" by default.
#                         Set it to "YES" to enable nrpe2.
# nrpe2_flags (str):      Not set by default.
# nrpe2_configfile (str): Set to "/usr/local/etc/nrpe.cfg" by default.

. /etc/rc.subr

name=nrpe2
rcvar=nrpe2_enable

load_rc_config "${name}"

: ${nrpe2_enable:=NO}
: ${nrpe2_configfile:=/usr/local/nagios/etc/nrpe.cfg}

required_files="${nrpe2_configfile}"

command="/usr/local/nagios/bin/nrpe"
command_args="-c ${nrpe2_configfile} -d"
extra_commands="reload"
sig_reload=HUP

start_precmd=nrpe2_prestart
stop_precmd=find_pidfile

find_pidfile()
{
        [ -n "$nrpe2_pidfile" ] &&
            warn "No longer necessary to set nrpe2_pidfile in rc.conf[.local]"

        if type get_pidfile_from_conf >/dev/null 2>&1 &&
            get_pidfile_from_conf pid_file /usr/local/nagios/etc/nrpe.cfg; then
                pidfile="$_pidfile_from_conf"
        else
                pidfile='/var/run/nrpe2/nrpe2.pid'
        fi
}

nrpe2_prestart()
{
        find_pidfile
        install -d -o ${nrpe_user:-nagios} ${pidfile%/*}
}

run_rc_command "$1"

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #8 on: พฤษภาคม 31, 2016, 12:17:42 AM »
###check_postfixqueue

#!/bin/bash
#
# 19-07-2010
# Author: Cherwin Nooitmeer <cherwin@gmail.com>
#

# exit codes
e_ok=0
e_warning=1
e_critical=2
e_unknown=3

# regular expression that matches queue IDs (e.g. D71EF7AC80F8)
queue_id='^[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]'

usage="Invalid command line usage"

if [ -z $1 ]; then
    echo $usage
    exit $e_unknown
fi

while getopts ":w:c:" options
do
    case $options in
        w ) warning=$OPTARG ;;
        c ) critical=$OPTARG ;;
        * ) echo $usage
            exit $e_unknown ;;
    esac
done

# determine queue size
qsize=$(mailq | egrep -c $queue_id)
if [ -z $qsize ]
then
    exit $e_unknown
fi

if [ $qsize -ge $critical ]; then
    retval=$e_critical
elif [ $qsize -ge $warning ]; then
    retval=$e_warning
elif [ $qsize -lt $warning ]; then
    retval=$e_ok
fi

echo "$qsize mail(s) in queue | mail_queue=$qsize"
exit $retval

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #9 on: พฤษภาคม 31, 2016, 12:18:12 AM »
Client configuration
====================
1) Put the script in the appropiate directory on the client. If you compile from source, it should be /usr/local/nagios/libexec.

2) Add the following to nrpe.cfg.
command[check_queue]=/usr/local/nagios/libexec/check_postfix_queue -w 20 -c 40

3) Restart nrpe.

Server configuration
====================
1) Edit an existing nrpe service and change the check_command to check_nrpe!check_queue

2) Check if the configuration is correct. /usr/bin/nagios -v /etc/nagios/nagios.cfg

3) Restart Nagios. /etc/init.d/nagios restart

Changelog

12-08-2010
==========
- Added patch to display perfdata (thanks box2)
- Edits to honour Bash coding style
- Removed unnecessary pipe to wc(8)

https://exchange.nagios.org/directory/Plugins/Email-and-Groupware/Postfix/check_postfix_queue/details

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #10 on: กรกฎาคม 20, 2016, 08:13:07 AM »
สามารถตรวจเชคเอกสารเพิ่มเติมของ nrpe ได้จากที่นี่ครับ => http://golfreeze.packetlove.com/download/NRPE.pdf

For nrpe on freebsd 11.x , 12.x
pkg install -y wget autoconf automake gettext gcc openssl libmcrypt
cd /tmp
wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.2.1.tar.gz
tar xzf nrpe.tar.gz

==compile
cd /tmp/nrpe-nrpe-3.2.1/
./configure --enable-command-args --with-ssl=/usr/local/bin --with-ssl-inc=/usr/local/include/openssl --with-ssl-lib=/usr/local/lib
make all

== create user group
make install-groups-users

==make install
make install

==install configure file
make install-config

==install service and daemon
make install-init
echo '/etc/rc.d/nrpe start' >> /etc/rc.local

 ;)
Verify by Packetlove.com Team.
https://support.nagios.com/kb/article.php?id=515?__hsfp=998628806#FreeBSD
« Last Edit: มิถุนายน 07, 2020, 09:00:07 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #11 on: กรกฎาคม 20, 2016, 09:51:20 AM »
เรียกให้ NRPE ทำการเชค mysqld ในโหนด Remote Host 
เริ่มแรกเวลาเราลง nrpe-plugin package มันจะมี check_mysql มาให้อยู่ละครับ
เราก็ทำการแอด user ที่ node : remote host ที่เครื่องลูกนะครับ ไม่ใช่เครื่อง Nagios Server

# mysql -u xxxxx -p
mysql> CREATE USER 'nrpe'@'localhost' IDENTIFIED BY '*****';
mysql> exit

ทดลองเรียก command ผ่าน
# /usr/lib64/nagios/plugins/check_mysql -H localhost -u nrpe -p *****

หรือถ้าทำงานได้แล้วก็ทำการเพิ่ม command ลง nrpe ครับ
command[check_mysql]=/usr/lib64/nagios/plugins/check_mysql -H localhost -u nrpe -p *****

ทำการ restart nrpe service 1 รอบ
#/etc/init.d/nrpe restart

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #12 on: พฤษภาคม 23, 2017, 09:26:59 AM »
ในกรณีถ้าใช้งานเป็น debian , Ubuntu เวลา download script check_eximailqueue มาให้ทำการแก้ไข path

EXIM=/usr/local/exim/bin/exim
เป็น
EXIM=/usr/sbin/exim

ตาม path binary file ของ exim
ก็จะแก้ไขปัญหาเวลาเรียกแล้วเจอ error แบบนี้ได้ครับ
Mailqueue WARNING - query returned no output!

บางครั้งอาจจะเป็นเพราะ sudo path ผิดนะครับ
รบกวนแก้ไขให้ถูกต้อง ก็จะเรียกใช้งานได้ครับ

==หลังจากแก้ไขให้ถูกต้อง
/usr/local/nagios/libexec/check_eximailqueue -w 50 -c 100
Mailqueue OK - 0 messages on queue
« Last Edit: มิถุนายน 05, 2021, 03:55:16 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #13 on: พฤษภาคม 28, 2017, 04:41:20 PM »
สั่งให้ nrpe enable ทุกครั้งตอน restart server ผ่าน systemctl

ทำการเช็คก่อนว่าได้เปิดให้ enable ไว้อยู่แต่แรกหรือเปล่า
# systemctl is-enabled nrpe
disabled

ถ้าเจอว่า disabled อยู่ให้สั่งทำการ enable ทุกครั้งเวลา restart server
# systemctl enable nrpe
Synchronizing state for nrpe.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d nrpe defaults
insserv: warning: script 'nrpe' missing LSB tags and overrides
insserv: warning: script 'exim' missing LSB tags and overrides
Executing /usr/sbin/update-rc.d nrpe enable
update-rc.d: error: nrpe Default-Start contains no runlevels, aborting.

เสร็จแล้วทำการเช็คอีกครั้ง ก็จะถูก enable ไว้แล้ว แสดงว่าเวลา restart server มาใหม่ เซอร์วิสนี้ก็จะถูก start ขึ้นมาด้วยผ่าน systemctl ครับ
# systemctl is-enabled nrpe
enabled

ลองเล่นกันดูนะครับ : )

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Install nrpe and nagios-plugin in remote host and nrpe on monitoring server
« Reply #14 on: พฤษภาคม 26, 2019, 08:44:19 AM »
ในส่วนของ debian 8.x 9.x เจอ error (nrpe_client) ip: 10.xx.22.6

check_nrpe: Error: Could not complete SSL handshake
ต้องทำการ uninstall nrpe version 2.15 ออก แล้วไปใช้เวอร์ชั่น 3.1 ขึ้นไปแทน ครับ
เพราะ source ของ 3.1 ขึ้นไปจะทำการแก้ไขเรื่องของ dh , openssl และแก้ไขเรื่อง SSL handshake ครับ

สำหรับการ uninstall 2.15 ที่เป็นการ compile source มานั้น สามารถแก้ไขได้โดย
/etc/init.d/nrpe stop
cd /usr/local/
mv nagios 2.15_nagios

##ทำการดาวโหลด version 3.2.1 มาครับ
cd /home/nagios
wget https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.2.1.tar.gz
tar zxf nrpe-3.2.1.tar.gz
cd nrpe-3.2.1

##ทำการ enable command และทำการ configure
./configure --enable-command-args
make all

##สร้าง group-user nagios
make install-groups-users

##ทำการ make-install เพื่อสร้าง bin , libexec ของ nrpe
make install

##ทำการ make-file configure
make install-config


##ทำการ enable nrpe service ใน debian 8.x , 9.x
make install-init
systemctl enable nrpe.service


##ถ้ามีการใช้ iptables ให้เพิ่ม rule accept และ save ด้วยครับ
iptables -I INPUT -p tcp --destination-port 5666 -j ACCEPT
apt-get install -y iptables-persistent
##Answer yes to saving existing rules

iptables-save > /etc/iptables/rule

##ทำการแก้ไข configure /usr/local/nagios/etc/nrpe.cfg
dont_blame_nrpe=1
และ
allowed_hosts=127.0.0.1,10.xx.22.x

##ทำการ start nrpe
systemctl start nrpe.service

แล้วเชคดู port 5666 จะเห็นว่ามีการเปิดไว้อยู่
netstat -ntlp | grep 5666

##ทำการเทสดูที่เครื่อง nagios-server เพื่อเรียกมายังเครื่อง client ใหม่นี้ที่ลงเป็นเวอร์ชั่น 3.2.1 (debian)
/usr/local/nagios/libexec/check_nrpe -H 10.xx.22.6
NRPE v3.2.1

เท่านี้ก็เรียบร้อยครับ  ;)
ทีมงาน Packetlove.com

##reference
https://support.nagios.com/kb/article/nrpe-how-to-install-nrpe-v3-from-source-515.html#Debian
« Last Edit: พฤษภาคม 26, 2019, 09:01:02 AM by golfreeze »