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

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 #15 on: มิถุนายน 07, 2020, 08:39:03 PM »
==== For FreeBSD 11.x , 12.x
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

./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 /usr/local/etc/rc.d/nrpe
chmod 755 /usr/local/etc/rc.d/nrpe

/usr/local/etc/rc.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 #16 on: มิถุนายน 21, 2020, 01:22:40 PM »
ทำการ monitoring mysql_slave_status ติดตั้ง nrpe ที่เครื่อง mysql slave node แล้วทำการติดตั้ง script check_mysql_slavestatus.sh

===download script จาก
https://golfreeze.packetlove.com/check_mysql_slavestatus.sh
or
https://www.claudiokuenzler.com/monitoring-plugins/check_mysql_slavestatus.sh

ทำการเพิ่มใน nagios nrpe command
vi nrpe.cfg
### custom script by PKL ###
command[check_mysql_slavestatus]=/usr/local/nagios/libexec/check_mysql_slavestatus.sh -H 127.0.0.1 -P 3306 -u nagios -p checkstatus@

แล้วทำการ เพิ่มใน nagios ฝั่ง server
vi dbslave.cfg

define service{
        use                             local-service         ; Name of service template to use
        host_name                       dbslave.com
        service_description             Check_Mysql_Slave_Status
        check_command                   check_nrpe!check_mysql_slavestatus
        notifications_enabled           1
        }

ผลการแสดงจาก nagios จะแสดงเป็นดังนี้ พร้อมกับ ดูได้ว่า sync ตามหลัง master node อยู่กี่วินาที
OK: Slave SQL running: Yes Slave IO running: Yes / master: 192.168.1.9 / slave is 0 seconds behind master

special thank you for script from :
https://www.claudiokuenzler.com

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 #17 on: กันยายน 30, 2020, 06:53:37 PM »
เราสามารถทำการ debug nagios nrpe ได้ครับ

#strace -f -s 128 -e execve -p `pgrep -ox nrpe`
แล้วเปิดอีก terminal ทำการรัน

/usr/local/nagios/libexec/check_nrpe -H0 -c check_pose_score

ก็จะสามารถดู debug ได้ครับผม

strace: Process 23817 attached
[pid xxxx] execve("/usr/local/nagios/libexec/check_post_score.sh", ["/usr/local/nagios/libexec/check_post_score.sh"], 0x5564695cfb70 /* 9 vars */) = -1 ENOENT (No such file or directory)

ก็แสดงว่าไม่มีสิทธิ์ในการเข้าถึง folder เลยไม่เจอ path หรือ file ดังกล่างในสคิป check_pose_score.sh

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 #18 on: กุมภาพันธ์ 03, 2021, 02:47:08 PM »
=== compile make on centos 8.3 จะเจอ error นี้ครับ เกิดจาก lib ที่ใช้งานใน 2.1.1 เก่าเกินให้ทำการแก้ไขโดย download v.2.3.3 มา compile แทนนะครับ
===wget http://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz

make[3]: Entering directory '/home/golf/nagios_nrpe/nagios-plugins-2.1.1/lib'
gcc -DHAVE_CONFIG_H -I. -I..  -DNP_STATE_DIR_PREFIX=\"/usr/local/nagios/var\" -I. -I../gl -I../intl -I../plugins   -g -O2 -MT utils_base.o -MD -MP -MF .deps/utils_base.Tpo -c -o utils_base.o utils_base.c
In file included from ../plugins/common.h:117,
                 from utils_base.c:27:
../gl/getopt.h:198:8: error: redefinition of 'struct option'
 struct option
        ^~~~~~
In file included from /usr/include/getopt.h:36,
                 from ../gl/getopt.h:32,
                 from ../plugins/common.h:117,
                 from utils_base.c:27:
/usr/include/bits/getopt_ext.h:50:8: note: originally defined here
 struct option
        ^~~~~~
In file included from ../plugins/common.h:117,
                 from utils_base.c:27:
../gl/getopt.h:247:12: error: conflicting types for 'getopt_long'
 extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
            ^~~~~~~~~~~
In file included from /usr/include/getopt.h:36,
                 from ../gl/getopt.h:32,
                 from ../plugins/common.h:117,
                 from utils_base.c:27:
/usr/include/bits/getopt_ext.h:66:12: note: previous declaration of 'getopt_long' was here
 extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
            ^~~~~~~~~~~
In file included from ../plugins/common.h:117,
                 from utils_base.c:27:
../gl/getopt.h:251:12: error: conflicting types for 'getopt_long_only'
 extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
            ^~~~~~~~~~~~~~~~
In file included from /usr/include/getopt.h:36,
                 from ../gl/getopt.h:32,
                 from ../plugins/common.h:117,
                 from utils_base.c:27:
/usr/include/bits/getopt_ext.h:70:12: note: previous declaration of 'getopt_long_only' was here
 extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
            ^~~~~~~~~~~~~~~~
make[3]: *** [Makefile:1394: utils_base.o] Error 1
make[3]: Leaving directory '/home/golf/nagios_nrpe/nagios-plugins-2.1.1/lib'
make[2]: *** [Makefile:1427: all-recursive] Error 1
make[2]: Leaving directory '/home/golf/nagios_nrpe/nagios-plugins-2.1.1/lib'
make[1]: *** [Makefile:1418: all-recursive] Error 1
make[1]: Leaving directory '/home/golf/nagios_nrpe/nagios-plugins-2.1.1'
make: *** [Makefile:1341: all] Error 2


=== compile make on centos 8.3 จะเจอ error นี้ครับ เกิดจาก lib ที่ใช้งานใน 2.1.1 เก่าเกินให้ทำการแก้ไขโดย download v.2.3.3 มา compile แทนนะครับ
===wget http://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar zxf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3
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/

==> ต้องติดตั้ง compat-openssl10 ด้วยนะครับ
yum install compat-openssl10
ln -s /usr/lib64/libnsl.so.2 /usr/lib64/libnsl.so.1
updatedb
แล้วทำการ restart nrpe ดูอีกรอบนะครับ  8)
« Last Edit: กุมภาพันธ์ 03, 2021, 03:47:56 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 #19 on: มิถุนายน 17, 2021, 07:40:40 AM »
==== Do on agent site ====
##download checkMYSQLProcesslist.sh
https://support.nagios.com/forum/download/file.php?id=3124&sid=a03b04c54e4889c5a0b37aeff9bc9027

==add in nrpe.cfg
command[check_mysql_query]=/usr/local/nagios/libexec/check_mysql.sh

==create 1 db and 1 table and insert 1 query to check access
CREATE TABLE `status_nagios` (
  `id` int(3) NOT NULL,
  `name` varchar(14) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `status_nagios`
--
INSERT INTO `status_nagios` VALUES (1,'statusnagios');

==== Do on nagios server =====
# Define check mysql_query on devnagios
define service{
        use                             local-service         ; Name of service template to use
        host_name                       devnagios.packetlove.com
        service_description             Check_Mysql_query
        check_command                   check_nrpe!check_mysql_query
        }

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 #20 on: มกราคม 06, 2022, 04:34:44 PM »
##centos 8.x สามารถใช้งานตามนี้ได้เลย ต้องใช้เป็น nrpe 3.2.1 นะครับ จะได้ไม่เจอปัญหาเรื่อง
CHECK_NRPE: (ssl_err != 5) Error - Could not complete SSL handshake with ip: 1

tar zxf nrpe3.2.1.tar.gz

cp init-script /etc/init.d/nrpe
chmod 755 /etc/init.d/nrpe
แก้เป็นตามนี้
#NrpeBin=${exec_prefix}/bin/nrpe
NrpeBin=/usr/local/nagios/bin/nrpe
#NrpeCfg=${prefix}/etc/nrpe.cfg
NrpeCfg=/usr/local/nagios/etc/nrpe.cfg

แล้วก็ systemctl daemon-reload

start nrpe
/etc/init.d/nrpe restart
« Last Edit: มกราคม 06, 2022, 05:21:43 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 #21 on: มีนาคม 30, 2022, 10:57:05 PM »
ถ้าเจอ error โดยที่ check_nrpe บน freebsd 11.x , 12.x
/usr/local/nagios/libexec/check_nrpe -H 103.86.y.x -c check_home
CHECK_NRPE: (ssl_err != 5) Error - Could not complete SSL handshake with 103.86.y.x : 1


==install nrpe3
#pkg install net-mgmt/nrpe3
Proceed with this action? [y/N]: y
[1/2] Fetching nrpe3-3.2.1.txz: 100%   46 KiB   9.5kB/s    00:05   
[2/2] Fetching nagios-plugins-2.3.3_2,1.txz: 100%  400 KiB 204.7kB/s    00:02   
Checking integrity... done (0 conflicting)
[1/2] Installing nagios-plugins-2.3.3_2,1...
[1/2] Extracting nagios-plugins-2.3.3_2,1: 100%
[2/2] Installing nrpe3-3.2.1...
===> Creating groups.
Using existing group 'nagios'.
===> Creating users
Using existing user 'nagios'.
===> Creating homedir(s)
[2/2] Extracting nrpe3-3.2.1: 100%
=====
Message from nrpe3-3.2.1:

--
Enable NRPE in /etc/rc.conf with the following line:

   nrpe3_enable="YES"

 A sample configuration is available in /usr/local/etc/nrpe.cfg.sample.
 Copy to nrpe.cfg where required and edit to suit your needs.
« Last Edit: มีนาคม 30, 2022, 11:06:29 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 #22 on: เมษายน 03, 2022, 05:48:40 PM »
ในเครื่อง client ที่ติดตั้ง nrpe client ให้ allow port 5666 ด้วยนะครับเพื่อให้ฝั่ง server check_nrpe เข้ามาได้ครับ
ufw allow 5666/tcp
: )

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 #23 on: เมษายน 03, 2022, 06:23:36 PM »
ในกรณี disk เป็น volume group เราสามารถสั่ง check disk ระบุ partition ได้เลยครับ
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 6% -c 3% -p /

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 #24 on: มีนาคม 24, 2024, 08:14:46 AM »
ถ้าเข้าไม่ได้จากฝั่ง nagios server ให้ทำการ allow iptables ด้วยนะครับ ในกรณีท่ีมีการใช้งาน iptables
iptables -I INPUT -p tcp -s ip_nagios_server --dport 5666 -j ACCEPT