Add Linux Host To Nagios Monitoring Server

Menambahkan host linux pada nagios monitoring server

Install Nagios Server 4.4.6


Host Linux

  • Login ke host linux yang akan di tambahkan ke dalam monitoring nagios, lalu Install require dependencies packages.
  • Dependencies untuk host Centos
yum install -y epel-release nano wget gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel
  • Dependencies untuk host Ubuntu
sudo apt install autoconf gcc libmcrypt-dev make libssl-dev wget dc build-essential gettext -y
  • Add user dan group
useradd nagios
passwd nagios
  • Download nagios plugin
wget https://sys-ops.id/installer/nagios-plugins-2.4.5.tar.gz
tar -xvf nagios-plugins-2.4.5.tar.gz
cd nagios-plugins-2.4.5
  • Install nagios plugin
./configure && make all && make install && make install-plugin && make install-daemon && make install-config && make install-init

  • Install nagios nrpe dari default repo untuk ubuntu 18.04|20.04|22.04 dan alma 9|rocky 9
  • Edit file nrpe agent: /etc/nagios/nrpe.cfg
apt install nagios-nrpe-server -y
systemctl restart nagios-nrpe-server
----
yum install nrpe -y
systemctl restart nrpe
----
nano /etc/nagios/nrpe.cfg

  • Download nagios nrpe
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.0.3/nrpe-4.0.3.tar.gz
tar -xzf nrpe-4.0.3.tar.gz
cd nrpe-4.0.3
  • Install nagios nrpe
./configure && make all && make install && make install-plugin && make install-daemon && make install-config && make install-init
  • Tambahkan port 5666/tcp ke dalam system service linux
echo >> /etc/services
echo '# Nagios services' >> /etc/services
echo 'nrpe    5666/tcp' >> /etc/services
  • Allow nrpe host, edit file /usr/local/nagios/etc/nrpe.cfg tambahkan ip server nagios pada baris allowed_hosts
nano /usr/local/nagios/etc/nrpe.cfg

allowed_hosts=127.0.0.1,localhost,103.157.27.142
  • Jalankan service nrpe
systemctl start nrpe
systemctl enable nrpe
systemctl status nrpe
systemctl status nrpe
● nrpe.service - Nagios Remote Plugin Executor
   Loaded: loaded (/usr/lib/systemd/system/nrpe.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-10-12 04:20:27 UTC; 3h 4min ago
     Docs: http://www.nagios.org/documentation
 Main PID: 18520 (nrpe)
   CGroup: /system.slice/nrpe.service
           └─18520 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -f

Oct 12 04:20:27 server-web01 systemd[1]: Stopped Nagios Remote Plugin Executor.
Oct 12 04:20:27 server-web01 systemd[1]: Started Nagios Remote Plugin Executor.
Oct 12 04:20:27 server-web01 nrpe[18520]: Starting up daemon
Oct 12 04:20:27 server-web01 nrpe[18520]: Server listening on 0.0.0.0 port 5666.
Oct 12 04:20:27 server-web01 nrpe[18520]: Server listening on :: port 5666.
Oct 12 04:20:27 server-web01 nrpe[18520]: Listening for connections on port 5666
Oct 12 04:20:27 server-web01 nrpe[18520]: Allowing connections from: 127.0.0.1,localhost,103.157.27.142
  • Cek netstat untuk port 5666/tcp, pastikan status LISTEN
netstat -tulpn | grep nrpe

tcp        0      0 0.0.0.0:5666       0.0.0.0:*     LISTEN      18520/nrpe
tcp6       0      0 :::5666            :::*          LISTEN      18520/nrpe
  • Cek versi nrpe
/usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v4.0.3
  • Cek beberapa status plugin yang akan di gunakan
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
USERS OK - 1 users currently logged in |users=1;5;10;0

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK - load average: 0.00, 0.02, 0.05|load1=0.000;0.150;0.300;0; load5=0.020;0.100;0.250;0; load15=0.050;0.050;0.200;0;

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK - load average: 0.00, 0.02, 0.05|load1=0.000;0.150;0.300;0; load5=0.020;0.100;0.250;0; load15=0.050;0.050;0.200;0;

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_disk
DISK OK - free space: /var/tmp 17594 MiB (85.95% inode=100%);| /var/tmp=2874MiB;16374;18421;0;20468

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
PROCS OK: 105 processes | procs=105;150;200;0;

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_swap
SWAP OK - 100% free (1023 MB out of 1023 MB) |swap=1023MB;204;102;0;1023

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_http
HTTP OK: HTTP/1.1 200 OK - 258 bytes in 0.002 second response time |time=0.001675s;;;0.000000 size=258B;;;0

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_ssh
SSH OK - OpenSSH_7.4 (protocol 2.0) | time=0.015334s;;;0.000000;10.000000

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_mysql
TCP OK - 0.002 second response time on 103.157.27.152 port 3306|time=0.002343s;;;0.000000;10.000000

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_uptime
Uptime OK: 0 day(s) 5 hour(s) 33 minute(s) | uptime=0.000000;;;

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_memory
memory OK: 79.62% (1463 MB) available | mem_total=1838MB mem_used=209MB;;;0;1838 mem_free=1240MB 
mem_shared=16MB mem_buffers=2MB mem_cached=386MB mem_available=1463MB;367;183;0;1838 mem_active=279MB mem_anonpages=124MB mem_committed=799MB mem_dirty=0MB mem_inactive=193MB

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_ftp
TCP OK - 0.001 second response time on 103.157.27.152 port 21|time=0.001000s;;;0.000000;10.000000

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_cpu
OK - CPU Usage = 6% |  CPU_USER=4;;;; CPU_SYSTEM=2;;;; CPU_IDLE=94;;;; CPU_IOWAIT=0;;;; CPU_ST=0;;;;
  • Konfigurasi file nrpe /usr/local/nagios/etc/nrpe.cfg , tambahkan plugin yang akan digunakan untuk monitoring server host linux.
nano /usr/local/nagios/etc/nrpe.cfg
# This is by far the most secure method of using NRPE

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -u GB -p /
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_ssh]=/usr/local/nagios/libexec/check_ssh -p 22 -H 103.157.27.152
command[check_swap]=/usr/local/nagios/libexec/check_swap  -w 20% -c 10%
command[check_http]=/usr/local/nagios/libexec/check_http -I 103.157.27.152
command[check_memory]=/usr/local/nagios/libexec/check_memory -a -b -m --available -w 20%: -c 10%:
command[check_uptime]=/usr/local/nagios/libexec/check_uptime -u days
command[check_mysql]=/usr/local/nagios/libexec/check_tcp -H 103.157.27.152 -p 3306
command[check_mail]=/usr/local/nagios/libexec/check_tcp -H 103.157.27.152 -p 25
command[check_network]=/usr/local/nagios/libexec/check_network -l -d -e -p -m -C
command[check_ftp]=/usr/local/nagios/libexec/check_tcp -H 103.157.27.152 -p 21
command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh -w 80 -c 90
  • Restart service nrpe
systemctl restart nrpe

Nagios Monitoring Server


Nagios Server

  • Login ke server nagios , lalu download nagios nrpe
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.0.3/nrpe-4.0.3.tar.gz
tar -xzf nrpe-4.0.3.tar.gz
cd nrpe-4.0.3
  • Install nagios nrpe
./configure
make all
make install
make install-plugin
make install-daemon
make install-config
make install-init
  • Tambahkan port 5666/tcp ke dalam system service linux
echo >> /etc/services
echo '# Nagios services' >> /etc/services
echo 'nrpe    5666/tcp' >> /etc/services
  • Jalankan service nrpe
systemctl start nrpe
systemctl enable nrpe
systemctl status nrpe
  • Cek netstat untuk port 5666/tcp, pastikan status LISTEN
netstat -tulpn | grep nrpe

tcp        0      0 0.0.0.0:5666            0.0.0.0:*               LISTEN      9449/nrpe
tcp6       0      0 :::5666                 :::*                    LISTEN      9449/nrpe
  • Cek versi nrpe
/usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v4.0.3
  • Menambahkan host group pada nagios, buat file hostgroups.cfg
nano /usr/local/nagios/etc/objects/hostgroups.cfg

define hostgroup{
        hostgroup_name server_groups
        alias   Group VM Server alias
}
  • Menambahkan service group pada nagios, buat file servicegroups.cfg
nano /usr/local/nagios/etc/objects/servicegroups.cfg

define servicegroup {
    servicegroup_name  ping
    alias              PING
}
define servicegroup {
    servicegroup_name  cpu
    alias              CPU
}
define servicegroup {
    servicegroup_name  memory
    alias              Memory
}
define servicegroup {
    servicegroup_name  disk
    alias              Disk
}
define servicegroup {
    servicegroup_name  ssh
    alias              SSH
}
define servicegroup {
    servicegroup_name  swap
    alias              Swap
}
define servicegroup {
    servicegroup_name  http
    alias              HTTP
}
define servicegroup {
    servicegroup_name  uptime
    alias              Uptime
}
define servicegroup {
    servicegroup_name  mysql
    alias              MySQL
}
define servicegroup {
    servicegroup_name  smtp
    alias              SMPT
}
define servicegroup {
    servicegroup_name  rdp
    alias              RDP
}
  • Tambahkan baris berikut pada bagian bawah file /usr/local/nagios/etc/nagios.cfg
nano /usr/local/nagios/etc/nagios.cfg

# You can specify individual object config files 
cfg_file=/usr/local/nagios/etc/host01.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/servicegroups.cfg
  • Edit file /usr/local/nagios/etc/host01.cfg
nano /usr/local/nagios/etc/host01.cfg
## Default Linux Host Template ##
define host{
name                            ID1VMC1:vm-linux 
use                             generic-host  
check_period                    24x7
check_interval                  1
retry_interval                  3
max_check_attempts              10
check_command                   check-host-alive
notification_period             24x7
notification_interval           30
notification_options            d,r
contact_groups                  admins
register                        0         
}

## Default
define host{
        use                     ID1VMC1:vm-linux 
        host_name               ID1VMC1:vm-linux 
        alias                   ID1VMC1:vm-linux
        address                 202.236.156.79  
        hostgroups		       server_groups
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     PING
        check_command           check_ping!100.0,20%!500.0,60%
        servicegroups		    ping
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     CPU
        check_command           check_nrpe!check_cpu
        servicegroups		    cpu
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     Memory
        check_command           check_nrpe!check_memory
        servicegroups		    memory
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     Root Partition
        check_command           check_nrpe!check_disk
        servicegroups		    disk
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     SSH
        check_command           check_nrpe!check_ssh
        servicegroups		    ssh
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     HTTP
        check_command           check_nrpe!check_http
        servicegroups		    http
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     Swap Usage
        check_command           check_nrpe!check_swap
        servicegroups		    swap
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     Uptime
        check_command           check_nrpe!check_uptime
        servicegroups		    uptime
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     MySQL
        check_command           check_nrpe!check_db
        servicegroups		    mysql
}

define service{
        use                     generic-service
        host_name               ID1VMC1:vm-linux
        service_description     SMTP
        check_command           check_nrpe!check_mail
        servicegroups		    smtp
}
  • Tambahkan nrpe command pada bagian bawah file /usr/local/nagios/etc/objects/commands.cfg
nano /usr/local/nagios/etc/objects/commands.cfg

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
  • Cek file konfigurasi nagios, pastikan tidak ada error
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.4.6
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2020-04-28
License: GPL
Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...
Running pre-flight check on configuration data...

Checking objects...
        Checked 22 services.
        Checked 2 hosts.
        Checked 1 host groups.
        Checked 0 service groups.
        Checked 1 contacts.
        Checked 1 contact groups.
        Checked 25 commands.
        Checked 5 time periods.
        Checked 0 host escalations.
        Checked 0 service escalations.
Checking for circular paths...
        Checked 2 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
  • Restart service nagios server
systemctl restart nagios

  • Login ke dalam web nagios server http://ip_server_nagios/nagios , sudah ada host baru: server-web01 dengan beberapa status service yang sedang aktif monitoring server-web01

  • Menambahkan nagios plugin pada host linux pada directory /usr/local/nagios/libexec/
  • Download plugin check_memory dan check_network dan check_cpu
  • Pada plugin check_disk sesuaikan dengan nama disk pada partisi linux
  • Contoh penggunaan plugin check_tcp untuk monitoring port 25:
./check_tcp -H 103.157.27.152 -p 25
TCP OK - 0.001 second response time on 103.157.27.152 port 25|time=0.001183s;;;0.000000;10.000000
cd /usr/local/nagios/libexec/
wget https://sys-ops.id/installer/check_memory
wget https://sys-ops.id/installer/check_cpu.sh
chmod 755 check_memory check_cpu.sh
systemctl restart nrpe

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.