1. In nagios server, edit nagios.cfg file and
uncomment windows
2. Test whether the Nagios server can monitor the Windows
server or not.
##Example: checking the Windows server uptime
[root@emcl libexec]# ./check_nt -H 192.168.56.4 -p 12489 -v UPTIME
System Uptime - 0 day(s) 1 hour(s) 27 minute(s) |uptime=87
##Example: Checking memory used in the Windows server
[root@emcl libexec]# ./check_nt -H 192.168.56.4 -p 12489 -v MEMUSE
Memory usage: total:11839.65 MB - used: 1655.86 MB (14%) - free: 10183.79 MB (86%) | 'Memory usage'=1655.86MB;0.00;0.00;0.00;11839.65
3. Edit windows.cfg file, and add the new
Windows host machine that we want to monitor.
[root@emcl ~]# vi /usr/local/nagios/etc/objects/windows.cfg
define host {
use windows-server ; Inherit default values from a template
host_name WIN-VV69BDNGNH2 ; The name we're giving to this server
alias windows-servers ; A longer name for the server
address 192.168.56.4 ; IP address of Windows remote
}
define hostgroup {
hostgroup_name windows-servers ; The name of the hostgroup
alias Windows Servers ; Long name of the group
}
define service{
use generic-service
host_name WIN-VV69BDNGNH2
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
check_interval 1
max_check_attempts 1
retry_interval 1
}
define service{
use generic-service
host_name WIN-VV69BDNGNH2
service_description Drive C Disk usage
check_command check_nt!USEDDISKSPACE!-l C
check_interval 1
max_check_attempts 1
retry_interval 1
}
Save the file and check if every this is working without any errors and restart nagios service on Nageios server
Monitoring Oracle Database with Nagios involves using plugins and
configurations that allow Nagios to check the status and performance of the
Oracle Database.
Download and install oracle instant client for Nagios server
1. Install the libnslpackage which is a required package for instant client for Linux 8
[root@emcl etc]# dnf install libnsl -y
Last metadata expiration check: 1:31:06 ago on Fri 15 Dec 2023 05:26:18 PM EST.
Package libnsl-2.28-164.0.1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
2. For downloading instance client go to the oracle websitehttps://www.oracle.com/ and do the following
From the top menu go to Resources then click Developer Downloads
1. Creating nagios user in the database and giving it the required access
[oracle@emcl ~]$ sqlplus / as sysdba
create user nagios identified by nagios;
grant create session to nagios;
grant select any dictionary to nagios;
grant select on V_$SYSSTAT to nagios;
grant select on V_$INSTANCE to nagios;
grant select on V_$LOG to nagios;
grant select on SYS.DBA_DATA_FILES to nagios;
grant select on SYS.DBA_FREE_SPACE to nagios;
Set up Check_Oracle_Health on Nagios server
1. prerequisite for installing Check_Oracle_Health on OEL8.5 (our nagios server)
1_1. The installation of the Perl modules DBI and DBD::Oracle are required. perl-DBI.x86_64 rpm exists on OEL8 ISO image and we will install it. In addition, we need to install libaio and Perl-CPAN related RPMs, I checked my system it was already installed.
[root@emcl software]# yum search perl-DBI
Last metadata expiration check: 1:04:11 ago on Wed 03 Jan 2024 03:03:33 PM EST.
======================================================== Name Exactly Matched: perl-DBI =========================================================
perl-DBI.x86_64 : A database access API for perl
[root@emcl software]# yum install perl-DBI.x86_64
[root@emcl software]# rpm -qa | grep perl-DBI
perl-DBI-1.641-3.module+el8.3.0+7665+79fef143.x86_64
[root@emcl software]# rpm -qa | grep libaio
libaio-0.3.112-1.el8.x86_64
[root@emcl DBD-Oracle-1.83-0]# rpm -qa | grep perl-CPAN
perl-CPAN-Meta-Requirements-2.140-396.el8.noarch
perl-CPAN-Meta-2.150010-396.el8.noarch
perl-CPAN-Meta-YAML-0.018-397.el8.noarch
perl-CPAN-2.18-397.el8.noarch
###Prerequisites:
####Oracle Instant Client:
[root@emcl software]# rpm -qa | grep oracle-instantclient
oracle-instantclient-sqlplus-21.12.0.0.0-1.el8.x86_64
oracle-instantclient-devel-21.12.0.0.0-1.el8.x86_64
oracle-instantclient-basic-21.12.0.0.0-1.el8.x86_64
The DBD::Oracle Perl module is not in an RPM repository, the good thing
is that you can download it via CPAN. Run the following command with the root user.
[root@emcl software]# perl -MCPAN -e shell
During the installation, you may be prompted to provide the paths to the Oracle Instant Client libraries and include files. Make sure to provide the correct paths.
[root@emcl DBD-Oracle-1.83-0]# make
[root@emcl DBD-Oracle-1.83-0]# make install
Verify installation using the following command.
[root@emcl DBD-Oracle-1.83-0]# perl -e 'use DBD::Oracle; print "DBD::Oracle is installed\n";'
DBD::Oracle is installed
2. Download and Install check_oracle_health:
[root@emcl software]# cd /software/
[root@emcl software]# wget https://labs.consol.de/assets/downloads/nagios/check_oracle_health-3.3.2.1.tar.gz
--2024-01-03 16:14:26-- https://labs.consol.de/assets/downloads/nagios/check_oracle_health-3.3.2.1.tar.gz
Resolving labs.consol.de (labs.consol.de)... 94.185.89.33, 2a03:3680:0:2::21
Connecting to labs.consol.de (labs.consol.de)|94.185.89.33|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 173953 (170K) [application/octet-stream]
Saving to: ‘check_oracle_health-3.3.2.1.tar.gz’
check_oracle_health-3.3.2.1.tar.gz 100%[===================================================================>] 169.88K 721KB/s in 0.2s
2024-01-03 16:14:27 (721 KB/s) - ‘check_oracle_health-3.3.2.1.tar.gz’ saved [173953/173953]
[root@emcl DBD-Oracle-1.83-0]# cd /software/
[root@emcl software]# tar xzf check_oracle_health-3.3.2.1.tar.gz
[root@emcl software]# cd check_oracle_health-3.3.2.1
[root@emcl libexec]# ./configure -prefix=/usr/local/nagios -with-nagios-user=nagios
-bash: ./configure: No such file or directory
[root@emcl libexec]# cd /software/check_oracle_health-3.3.2.1
[root@emcl check_oracle_health-3.3.2.1]# ./configure -prefix=/usr/local/nagios -with-nagios-user=nagios
[root@emcl check_oracle_health-3.3.2.1]# make
[root@emcl check_oracle_health-3.3.2.1]# make install
Here are some examples of testing the Check_Oracle_health
###checking the existance of check_oracle_health are created under /usr/local/nagios/libexec/ path
[root@emcl check_oracle_health-3.3.2.1]# cd /usr/local/nagios/libexec/
[root@emcl libexec]# ll check_oracle
check_oracle check_oracle_health
[root@emcl libexec]# /usr/local/nagios/libexec/check_oracle_health -V
check_oracle_health (3.3.2.1)
This nagios plugin comes with ABSOLUTELY NO WARRANTY. You may redistribute
copies of this plugin under the terms of the GNU General Public License.
##checking tnsping
[root@emcl libexec]# /usr/local/nagios/libexec/check_oracle_health --connect=192.168.56.10:1521/pdb1.amir.net --username=nagios --password=nagios --mode tnsping
OK - connection established to 192.168.56.10:1521/pdb1.amir.net.
##checking tablespaces usage
[root@emcl libexec]# /usr/local/nagios/libexec/check_oracle_health --connect=192.168.56.10:1521/pdb1.amir.net --username=nagios --password=nagios --mode tablespace-usage
OK - tbs USERS usage is 0.00%, tbs UNDOTBS1 usage is 0.03%, tbs TEMP usage is 0.00%, tbs SYSTEM usage is 0.84%, tbs SYSAUX usage is 0.81% |
'tbs_users_usage_pct'=0.00%;90;98 'tbs_users_usage'=1MB;29491;32112;0;32767 'tbs_users_alloc'=5MB;;;0;32767 'tbs_undotbs1_usage_pct'=0.03%;90;98 'tbs_undotbs1_usage'=9MB;29491;32112;0;32767 'tbs_undotbs1_alloc'=100MB;;;0;32767 'tbs_temp_usage_pct'=0.00%;90;98 'tbs_temp_usage'=0MB;265420;289013;0;294911 'tbs_temp_alloc'=1152MB;;;0;294911 'tbs_system_usage_pct'=0.84%;90;98 'tbs_system_usage'=276MB;29491;32112;0;32767 'tbs_system_alloc'=280MB;;;0;32767 'tbs_sysaux_usage_pct'=0.81%;90;98 'tbs_sysaux_usage'=264MB;29491;32112;0;32767 'tbs_sysaux_alloc'=280MB;;;0;32767
##checking ASM disks
[root@emcl ~]# /usr/local/nagios/libexec/check_oracle_health --connect=192.168.56.10:1521/pdb1.amir.net --username=nagios --password=nagios --mode asm-diskgroup-usage
OK - dg DATA usage is 25.27%, dg FRA usage is 9.30% | 'dg_data_usage_pct'=25.27%;90;98 'dg_data_usage'=4140MB;14742;16052;0;16380 'dg_data_size'=16380MB 'dg_fra_usage_pct'=9.30%;90;98 'dg_fra_usage'=952MB;9212;10031;0;10236 'dg_fra_size'=10236MB
Configuring Nagios-related files on the Nagios server to check the Oracle server
using CHECK_ORACLE_HEALTH
1. Configuration of Nagios server files including hosts.cfg, services.cfg and commands.cfg for checking tablespace usage
[root@emcl ~]# vi /usr/local/nagios/etc/hosts.cfg
## Default
define host{
use linux-box ; Inherit default values from a template
host_name src ; The name we're giving to this server
alias Oracle Linux Server release 7.9 ; A longer name for the server
address 192.168.56.10 ; IP address of Remote Linux host
}
##add this to the end of following file
[root@emcl admin]# vi /usr/local/nagios/etc/services.cfg
define service {
use generic-service
host_name src
service_description Oracle Tablespace Usage
check_command check_oracle_health_tablespace!1521!pdb1.amir.net!nagios!nagios!tablespace-usage
}
[root@emcl ~]# vi /usr/local/nagios/etc/objects/commands.cfg
define command {
command_name check_oracle_health_tablespace
command_line $USER1$/check_oracle_health --connect=$HOSTADDRESS$:$ARG1$/$ARG2$ --username=$ARG3$ --password=$ARG4$ --mode $ARG5$
}
2. Nagios configuration for tnsping
[root@emcl ~]# vi /usr/local/nagios/etc/services.cfg
define service {
use generic-service
host_name src
service_description TNS Ping
check_command check_oracle_health_tnsping!1521!pdb1.amir.net!tnsping
}
[root@emcl ~]# vi /usr/local/nagios/etc/objects/commands.cfg
define command {
command_name check_oracle_health_tnsping
command_line $USER1$/check_oracle_health --connect=$HOSTADDRESS$:$ARG1$/$ARG2$ --mode $ARG3$
}
3. Nagios configuration for ASM Diskgroup Free Space
[root@emcl ~]# vi /usr/local/nagios/etc/services.cfg
define service {
use generic-service
host_name src
service_description ASM Diskgroup Free Space
check_command check_oracle_health_asm_disk_used!1521!pdb1.amir.net!nagios!nagios!asm-diskgroup-usage
}
[root@emcl ~]# vi /usr/local/nagios/etc/objects/commands.cfg
define command {
command_name check_oracle_health_asm_disk_used
command_line $USER1$/check_oracle_health --connect=$HOSTADDRESS$:$ARG1$/$ARG2$ --username=$ARG3$ --password=$ARG4$ --mode $ARG5$
}
To monitor a remote Linux host using Nagios, we'll need to install
Nagios Plugins and NRPE (Nagios Remote Plugin Executor) on the remote
host.
NRPE (Nagios Remote Plugin Executor):
NRPE is a Nagios agent that allows remote systems to execute Nagios
plugins on them. It facilitates the monitoring of local resources and services
on remote hosts. NRPE can be installed on various operating systems, including
Linux and Windows.
Here's a brief overview of how NRPE works:
Nagios Server: The Nagios server initiates a check by sending a command
to the NRPE daemon on the remote host.
NRPE Daemon: The NRPE daemon on the remote host receives the command,
executes the specified plugin locally, and returns the results to the Nagios
server.
Monitoring Plugins: Plugins are scripts or executables that perform
specific checks (e.g., checking CPU usage, disk space, etc.) on the remote
host.
Secure Communication: NRPE uses encryption and authentication to ensure
secure communication between the Nagios server and the remote host.
Configuring NRPE and Nagios Plugin on remote Linux host
To monitor the remote Linux host we must install NRPE and Nagios Plugin,
here are the steps:
1. First let's check my Linux version
[root@src ~]# more /etc/*release;
::::::::::::::
/etc/oracle-release
::::::::::::::
Oracle Linux Server release 7.9
2. Install Required Packages
2_1. Configuring the YUM repository, I copied Linux 7 on my host in /software path.
[root@src ~]# more /etc/yum.repos.d/oracle-linux-ol7.repo
[ol7_latest]
name=Oracle Linux $releasever Latest ($basearch)
baseurl=file:///software/linux7
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=0
enabled=1
[root@src linux7]# yum update
2_2. Then install the following packages.
[root@src linux7]# yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel tar wget
2_3. Create Nagios user
[root@src linux7]# useradd nagios
[root@src linux7]# passwd nagios
Changing password for user nagios.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
2_4. Create directory for Nagios Plugin and download the package in this directory
[root@src nagios]# tar -xvf nagios-plugins-2.3.3.tar.gz
[root@src nagios]# ls -l
total 2724
drwxr-xr-x 15 root root 4096 Mar 11 2020 nagios-plugins-2.3.3
-rw-r--r-- 1 root root 2782610 Dec 15 16:36 nagios-plugins-2.3.3.tar.gz
[root@src nagios]# cd nagios-plugins-2.3.3
[root@src nagios-plugins-2.3.3]# ./configure
[root@src nagios-plugins-2.3.3]# make
[root@src nagios-plugins-2.3.3]# make install
##Set the permissions on the plugin directory using the chown command.
[root@src nagios-plugins-2.3.3]# chown nagios.nagios /usr/local/nagios
[root@src nagios-plugins-2.3.3]# chown -R nagios.nagios /usr/local/nagios/libexec
4. Install NRPE: Download the latest package, compile and install NRPE.
[root@src nagios]# cd /root/nagios
[root@src nagios]# wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.0.2/nrpe-4.0.2.tar.gz
[root@src nagios]# tar xzf nrpe-4.0.2.tar.gz
[root@src nagios]# cd nrpe-4.0.2
[root@src nrpe-4.0.2]# ./configure
[root@src nrpe-4.0.2]# make all
cd ./src/; make
make[1]: Entering directory `/root/nagios/nrpe-4.0.2/src'
gcc -g -O2 -I/usr/include/krb5 -DHAVE_CONFIG_H -I ../include -I ./../include -o nrpe ./nrpe.c ./utils.c ./acl.c -lssl -lcrypto -lnsl
gcc -g -O2 -I/usr/include/krb5 -DHAVE_CONFIG_H -I ../include -I ./../include -o check_nrpe ./check_nrpe.c ./utils.c -lssl -lcrypto -lnsl
make[1]: Leaving directory `/root/nagios/nrpe-4.0.2/src'
*** Compile finished ***
You can now continue with the installation or upgrade process.
Read the PDF documentation (docs/NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.
[root@src nrpe-4.0.2]# make install-plugin
cd ./src/; make install-plugin
make[1]: Entering directory `/root/nagios/nrpe-4.0.2/src'
/usr/bin/install -c -m 755 -d /usr/local/nagios/bin
/usr/bin/install -c -m 755 ../uninstall /usr/local/nagios/bin/nrpe-uninstall
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios check_nrpe /usr/local/nagios/libexec
make[1]: Leaving directory `/root/nagios/nrpe-4.0.2/src'
[root@src nrpe-4.0.2]# make install-daemon
cd ./src/; make install-daemon
make[1]: Entering directory `/root/nagios/nrpe-4.0.2/src'
/usr/bin/install -c -m 755 -d /usr/local/nagios/bin
/usr/bin/install -c -m 755 ../uninstall /usr/local/nagios/bin/nrpe-uninstall
/usr/bin/install -c -m 755 nrpe /usr/local/nagios/bin
/usr/bin/install -c -m 755 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 755 -d /usr/lib/tmpfiles.d
/usr/bin/install -c -m 644 ../startup/tmpfile.conf /usr/lib/tmpfiles.d/nrpe.conf
make[1]: Leaving directory `/root/nagios/nrpe-4.0.2/src'
[root@src nrpe-4.0.2]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 644 -o nagios -g nagios sample-config/nrpe.cfg /usr/local/nagios/etc
[root@src nrpe-4.0.2]# make install-init
/usr/bin/install -c -m 644 startup/default-service /usr/lib/systemd/system/nrpe.service
4_1. Now open /usr/local/nagios/etc/nrpe.cfg file and add the local host and
IP address of the Nagios Monitoring Server.
[root@src nrpe-4.0.2]# vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.56.2
4_2. Restart NRPE:
[root@src nrpe-4.0.2]# systemctl enable nrpe
Created symlink from /etc/systemd/system/multi-user.target.wants/nrpe.service to /usr/lib/systemd/system/nrpe.service.
[root@src nrpe-4.0.2]# systemctl restart nrpe
4_3. Open NRPE Port in Firewall (I disabled the firewall in my Linux)
If a firewall is enabled on your Nagios server, you must allow traffic on the NRPE port (default is 5666). Update your firewall rules accordingly.
# /usr/local/nagios/libexec/check_nrpe -H <remote_linux_ip_address>
[root@emcl libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.56.10
-bash: /usr/local/nagios/libexec/check_nrpe: No such file or directory
# I checkedm, I the package source that I download for the Nagios server shit file was missing, therefore, I copied it from the remote host.
[root@emcl libexec]# ll | wc -l
63
##on the client
[root@src libexec]# ll | wc -l
64
[root@src ~]# scp /usr/local/nagios/libexec/check_nrpe root@192.168.56.2://usr/local/nagios/libexec/
The authenticity of host '192.168.56.2 (192.168.56.2)' can't be established.
ECDSA key fingerprint is SHA256:A8Z6mVuYWIrJWJkMuDJ7qiGkLHBBWvmcRbMQuoM2ZNM.
ECDSA key fingerprint is MD5:7b:35:06:3e:fe:43:90:7d:c6:a8:0a:00:2c:01:72:b5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.2' (ECDSA) to the list of known hosts.
root@192.168.56.2's password:
check_nrpe
###Now, it is working on the server on server
[root@emcl libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.56.10
NRPE v4.0.2
2. Adding the following information in nagios.cfg file
[root@emcl libexec]# cd /usr/local/nagios/etc/
[root@emcl etc]# touch hosts.cfg
[root@emcl etc]# touch services.cfg
[root@emcl etc]# vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
3. Configuring Nagios Host, Services and command Files
3_1. Configuring Host file
[root@emcl etc]# more /usr/local/nagios/etc/hosts.cfg
## Default Linux Host Template ##
define host{
name linux-box ; Name of this template
use generic-host ; Inherit default values
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0 ; DONT REGISTER THIS - ITS A TEMPLATE
}
## Default
define host{
use linux-box ; Inherit default values from a template
host_name src ; The name we're giving to this server
alias Oracle Linux Server release 7.9 ; A longer name for the server
address 192.168.56.10 ; IP address of Remote Linux host
}
3_2. Configuring services.cfg file
define service{
use generic-service
host_name src
service_description CPU Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name src
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use generic-service
host_name src
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name src
service_description SSH Monitoring
check_command check_nrpe!check_ssh
}
define service{
use generic-service
host_name src
service_description FTP Monitoring
check_command check_nrpe!check_ftp
}
3_3. Configuring NRPE Command Definition file
# vi /usr/local/nagios/etc/objects/commands.cfg
###add following to the end of the file
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
3_4. Checking the configuraion is done correctly [root@emcl etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
3_5. Restart the Nagios service on the Nagios server