What is Nagios ?
“Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.” https://www.nagios.org/
In simple words, you can monitor your servers (linux, MSSSQL, etc …) and databases (Oracle, SQL Server, Postgres, MySQL, MariaDB, etc …) with nagios.
We use the free version !!! đ
VM configuration :
OS : CentOS Linux 7 CPU : Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz Memory : 3GB Disk : 15GB
What we need :
- We need Nagios Core. This is the brain of our Nagios server. All the configuration will be done in this part (set the contacts, set the notification massages, etc …)
- We must install Nagios plugins. Plugins are standalone extensions to Nagios Core that make it possible to monitor anything and everything with Core. Plugins process command-line arguments, perform a specific check, and then return the results to Nagios Core
- The NRPE addon is designed to allow you to execute Nagios plugins on remote Linux/Unix machines. The main reason for doing this is to allow Nagios to monitor “local” resources (like CPU load, memory usage,etc.) on remote machines. Since these public resources are not usually exposed to external machines, an agent like NRPE must be installed on the remote Linux/Unix machines.
Preconditions
All below installation are as root user.
Installation steps
- Install Nagios Core (I will not explain it. Because their documentation is complete)
support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#CentOS - Install Nagios Plugins
support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#CentOS
- Install NRPE
https://support.nagios.com/kb/article.php?id=515 - Now you must decide which type of database you want to monitor. Then install the check_health plugin for it (you can install all of them if you want)
Here we install the Oracle and SQL Server check_health
Install and configure Oracle Check_health
You need Oracle client to communicate with an Oracle instanceÂ
- Download and install check_oracle_health (https://labs.consol.de/nagios/check_oracle_health/index.html)
wget https://labs.consol.de/assets/downloads/nagios/check_oracle_health-3.2.1.2.tar.gz tar xvfz check_oracle_health-3.2.1.2.tar.gz cd check_oracle_health-3.2.1.2 ./configure make make install
- Download and install Oracle Client (here we installed 12c version – https://www.oracle.com/database/technologies/oracle12c-linux-12201-downloads.html)
- Create check_oracle_health_wrapped file in /usr/local/nagios/libexec
- Set parameters+variables needed to start the plugin check_oracle_health
#!/bin/sh ### -------------------------------------------------------------------------------- ### ### We set some environment variable before to start the check_oracle_health script. ### -------------------------------------------------------------------------------- ### ### Set parameters+variables needed to start the plugin check_oracle_health: export ORACLE_HOME=/u01/app/oracle/product/12.2.0/client_1 export LD_LIBRARY_PATH=$ORACLE_HOME/lib export TNS_ADMIN=/usr/local/nagios/tns export PATH=$PATH:$ORACLE_HOME/bin export ARGS="$*" ### start the plugin check_oracle_health with the arguments of the Nagios Service: /usr/local/nagios/libexec/check_oracle_health $ARGS
- Create the tns folder in /usr/local/nagios and then make a tnsnames.ora file and add a tns
DBTEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.22.10.2)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SID = DBTEST) ) )
- Test the connection
[nagios@vmnagios objects]$ check_oracle_health_wrapped --connect DBTEST --mode tnsping
Install and configure MSSQL Check_health
- Download and install the check_mssql_health
wget https://labs.consol.de/assets/downloads/nagios/check_mssql_health-2.6.4.16.tar.gz tar xvfz check_mssql_health-2.6.4.16.tar.gz cd check_mssql_health-2.6.4.16 ./configure make make install
- Download and install freetds (www.freetds.org/software.html)
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.1.20.tar.gz tar xvfz freetds-1.1.20 ./configure --prefix=/usr/local/freetds make make install yum install freedts freetds-devel gcc make perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
- Download and install DBD-Sybase
wget http://search.cpan.org/CPAN/authors/id/M/ME/MEWP/DBD-Sybase-1.15.tar.gz tar xvfz DBD-Sybase-1.15 cd DBD-Sybase-1.15 export SYBASE=/usr/local/freetds perl Makefile.PL make make install
- Add your instance information in : /usr/local/freetds/etc/freetds.conf
Configuration steps
- Set your domaine name
[root@vmnagios ~]# cat /etc/resolv.conf # Generated by NetworkManager search exemple.ads nameserver 10.175.222.10
- Set SMPT and Postfix
[root@vmnagios ~]# /etc/postfix/main.cf ### ----------------- added by dbi-services ---------------- ### relayhost = http://smtp.exemple.net smtp_generic_maps = hash:/etc/postfix/generic sender_canonical_maps = hash:/etc/postfix/canonical -------------------------------------------------------- ###
- Configure Postfix
[root@vmnagios ~]# cat /etc/postfix/generic @localdomain.local [email protected] @.exemple.ads [email protected] [root@vmnagios ~]# cat /etc/postfix/canonical root [email protected] nagios [email protected]
After we need to generate the generic.db and canonical.db
postmap /etc/postfix/generic
postmap /etc/postfix/canonical
Done ! đ
Now you have a new Nagios Server. All you should do is to configure your client and create a config file on your brand new Nagios server.