DEV Community

Fairywen
Fairywen

Posted on

Configuring check_oracle Nagios plugin

Let's see how to set-up Oracle database monitoring on an eyesofnetwork server, using check_oracle plugin.

Step 1 : Get check_oracle pluging

First, check_oracle plugin can already be available on Nagios server, look for yum package nagios-plugins-oracle.x86_64 : Nagios Plugin - check_oracle.
Install it if it's not.

Step 2 : Install oracle client

The lightest way to get all oracle dependancies we need is to :

  1. install an oracle-instantclient
  2. add tnsping by getting it on another server

Note : We also could have installed "full" oracle client, but I don't think it would have been relevant.

Step 2.1 : Get instant client

So let's get .rpm package on oracle instant client download page.

In this example we pick up version 19.14.0.0.0 in Basic Package (RPM) (wich contains SQL*Plus binary).

Once this package is pushed to targer server, install it :

[root@nagios-server ~]# yum install <path_to>/oracle-instantclient19.14-basic-19.14.0.0.0-1.x86_64.rpm
Modules complémentaires chargés : fastestmirror
Examen de oracle-instantclient19.14-basic-19.14.0.0.0-1.x86_64.rpm : oracle-instantclient19.14-basic-19.14.0.0.0-1.x86_64
Sélection de oracle-instantclient19.14-basic-19.14.0.0.0-1.x86_64.rpm pour installation
Résolution des dépendances
--> Lancement de la transaction de test
---> Le paquet oracle-instantclient19.14-basic.x86_64 0:19.14.0.0.0-1 sera installé
--> Résolution des dépendances terminée

Dépendances résolues

================================================================================================================================================================================================================================
 Package                                                    Architecture                      Version                                    Dépôt                                                                            Taille
================================================================================================================================================================================================================================
Installation :
 oracle-instantclient19.14-basic                            x86_64                            19.14.0.0.0-1                              /oracle-instantclient19.14-basic-19.14.0.0.0-1.x86_64                            226 M

Résumé de la transaction
================================================================================================================================================================================================================================
Installation   1 Paquet

Taille totale  : 226 M
Taille d'installation : 226 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installation : oracle-instantclient19.14-basic-19.14.0.0.0-1.x86_64                                                                                                                                                       1/1
  Vérification : oracle-instantclient19.14-basic-19.14.0.0.0-1.x86_64                                                                                                                                                       1/1

Installé :
  oracle-instantclient19.14-basic.x86_64 0:19.14.0.0.0-1

Terminé !
Enter fullscreen mode Exit fullscreen mode

At the end of installation, Oracle client is installed under /usr/lib/oracle/19.14/client64. That will be our ORACLE_HOME directory for next steps.

Step 2.2 Add tnsping

To do so we just have to get $ORACLE_HOME/bin/tnsping and $ORACLE_HOME/network/mesg/tnsus.msb from database server (also running on linux distribution), copy it to Nagios server in equivalent directories and check file permissions.

  1. tnsping
[root@nagios-server ~]# echo $ORACLE_HOME
/usr/lib/oracle/19.14/client64
[root@nagios-server ~]# mv tnsping $ORACLE_HOME/bin/
[root@nagios-server ~]# cd $ORACLE_HOME/bin/
[root@nagios-server bin]# ls -la
total 180
drwxr-xr-x 2 root   root    4096 11 mars  10:42 .
drwxr-xr-x 5 root   root    4096 11 mars  10:12 ..
-rwxr-xr-x 1 root   root   41504 25 déc.  14:20 adrci
-rwxr-xr-x 1 root   root   59032 25 déc.  14:20 genezi
-rwxr-xr-x 1 root   root   24512 25 déc.  14:22 sqlplus
-rw-rw-r-- 1 user   user   42216 11 mars  10:34 tnsping
[root@nagios-server bin]# chmod 755 tnsping
[root@nagios-server bin]# chown root.root tnsping
[root@nagios-server bin]# ls -la
total 180
drwxr-xr-x 2 root root  4096 11 mars  10:42 .
drwxr-xr-x 5 root root  4096 11 mars  10:12 ..
-rwxr-xr-x 1 root root 41504 25 déc.  14:20 adrci
-rwxr-xr-x 1 root root 59032 25 déc.  14:20 genezi
-rwxr-xr-x 1 root root 24512 25 déc.  14:22 sqlplus
-rwxr-xr-x 1 root root 42216 11 mars  10:34 tnsping
Enter fullscreen mode Exit fullscreen mode
  1. tnsus.msb
[root@nagios-server ~]# mkdir $ORACLE_HOME/network/mesg
[root@nagios-server ~]# mv tnsus.msb $ORACLE_HOME/network/mesg/.
[root@nagios-server ~]# cd $ORACLE_HOME/network/mesg
[root@nagios-server mesg]# ls -la
total 60
drwxr-xr-x 2 root   root    4096 11 mars  10:51 .
drwxr-xr-x 4 root   root    4096 11 mars  10:50 ..
-rw-rw-r-- 1 user   user   50688 11 mars  10:49 tnsus.msb
[root@nagios-server mesg]# chown root.root tnsus.msb
[root@nagios-server mesg]# chmod 644 tnsus.msb
[root@nagios-server mesg]# ls -la
total 60
drwxr-xr-x 2 root root  4096 11 mars  10:51 .
drwxr-xr-x 4 root root  4096 11 mars  10:50 ..
-rw-r--r-- 1 root root 50688 11 mars  10:49 tnsus.msb
Enter fullscreen mode Exit fullscreen mode

Step 3 : add tnsnames file

By default after installation, network/admin directory is under /usr/lib/oracle/19.14/client64/lib. Usually this would be under $ORACLE_HOME, so let's move it :

[root@nagios-server ~]# cd /usr/lib/oracle/19.14/client64/
[root@nagios-server client64]# mv lib/network .
Enter fullscreen mode Exit fullscreen mode

Then we can create an usual tnsnames.ora under $ORACLE_HOME/network/admin/ looking like this :

MY_DB =
  (DESCRIPTION =
    (ADDRESS =
      (PROTOCOL = <protocol>)(HOST = <ip>)(PORT = <port>))
    (CONNECT_DATA =
      (SID = ORA_SID)
    )
  )
Enter fullscreen mode Exit fullscreen mode

Step 4 : Configure check command

As explained in this Nagios support topic, Nagios plugins doesn't have access to environment variables when running, thus there is no point to set ORACLE_HOME or update LD_LIBRARY_PATH in linux system.
Instead, we have to set them directly in check command definition in /etc/nagios/objects/commands/commands.cfg, example for a tns check :

define command {
  command_name my_check_oracle_tns
  command_line /usr/bin/env LD_LIBRARY_PATH=/usr/lib/oracle/19.14/client64/lib ORACLE_HOME=/usr/lib/oracle/19.14/client64 /srv/eyesofnetwork/nagios/plugins/check_oracle --tns $ARG1$
}
Enter fullscreen mode Exit fullscreen mode

That's all, our Nagios server have now a new command to monitor Oracle database server 😃

Discussion (0)