Selasa, 07 Mei 2019

How to Install - Oracle Plugin check_oracle_health (CentOS 6)


Prerequisites

Oracle software

The Oracle database server or instant client must be up and running.

CentOS packages

yum -y install cpan sharutils

Perl packages

Find out the absolute path of ORACLE_HOME and set the Oracle environment.
This is required for the installation of DBD::Oracle.

if Oracle 11gR2 server installated

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

if Oracle Instantclient installated

export ORACLE_HOME=/usr/lib/oracle/11.2/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

Install Perl DBD::Oracle module

wget http://www.cpan.org/modules/by-module/DBD/DBD-Oracle-1.74.tar.gz
tar zxvf DBD-Oracle-1.74.tar.gz
cd DBD-Oracle-1.74
perl Makefile.PL -l
make && make test
make install


Download and install the check_oracle_health plugin

Check for the latest version at http://labs.consol.de/lang/en/nagios/check_oracle_health/, scroll down to "Download".

cd /tmp
wget https://labs.consol.de/assets/downloads/nagios/check_oracle_health-3.1.0.3.tar.gz
tar xzf check_oracle_health-3.1.0.3.tar.gz
cd /tmp/check_oracle_health-*
./configure
make
make install
cp /usr/local/nagios/libexec/check_oracle_health /usr/lib64/nagios/plugins/

Set up the Oracle user "nagios" in target server

# as root:
su - oracle
sqlplus / as sysdba
CREATE USER nagios IDENTIFIED BY oradbmon;
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;
exit # leave SQL*Plus
exit # back to root

Test locally

Please replace the path to ORACLE_HOME and the connect string as appropriate. In the following example,
the connect string refers to the alias in $ORACLE_HOME/network/admin/tnsnames.ora if your install server version
if you install instantclient connect string refers to the alias in /etc/tnsnames.ora

/usr/local/nagios/libexec/check_oracle_health --connect XE --user nagios --password oradbmon --environment ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe --mode tablespace-usage

Now you have to configure the check command in nagios. For the command to work, it needs to have the oracle client paths added to the environment variables – ORACLE_HOME, LD_LIBRARY_PATH,PATH. To avoid all sorts of issues in passing environment variables in nagios and altering the startup script of nagios to set them (as described on the author’s site), just pass the variables directly in the command. The latest version of check_oracle_health allows that.

Define command in /usr/local/nagios/etc/objects/command.cfg

vi /usr/local/nagios/etc/objects/command.cfg

# Oracle Database check health command
# check_oracle_health    !  SID  !  USER  !  Pass  !  Warn  !  crit  !  mode

define command {
        command_name check_oracle_health
        command_line $USER1$/check_oracle_health --environment PATH=$PATH:$ORACLE_HOME/bin --environment LD_LIBRARY_PATH=$ORACLE_HOME/lib --connect $ARG1$ --user $ARG2$ --password $ARG3$ --mode $ARG4$
        }


# Oracle Check Tablespace per name
# check_oracle_health_tbs_name    !  SID  !  USER  !  Pass  !  Warn  !  crit  !  mode  ! tbs_name

define command {
        command_name check_oracle_health_tbs_name
        command_line $USER1$/check_oracle_health --environment PATH=$PATH:$ORACLE_HOME/bin --environment LD_LIBRARY_PATH=$ORACLE_HOME/lib --connect $ARG1$ --user $ARG2$ --password $ARG3$ --mode $ARG4$ --name $ARG5$
        }

Define service in /usr/local/nagios/etc/servers/oracledbtest.cfg

define host{

use                                     linux-server
host_name                               oracledbtest
alias                                   oracledbtest
address                                 192.168.xx.yy
max_check_attempts                      5
check_period                            24x7
notification_interval                   30
notification_period                     24x7
}

### Change last argument to the different modes
### tns-ping , process-usage , sga-shared-pool-free

define service {
        use                             local-service
        host_name                       oracledbtest
        service_description             Oracle Connection Time
        check_command                   check_oracle_health!XE!nagios!oradbmon!connection-time
        notifications_enabled           1
}

define service {
        use                             local-service
        host_name                       oracledbtest
        service_description             Oracle Connected Users
        check_command                   check_oracle_health!XE!nagios!oradbmon!connected-users
        notifications_enabled           1
}

### Change last argument to the different tablespace
### users, undotbs

define service {
        use                             local-service
        host_name                       oracledbtest
        service_description             Oracle Tablespace Usage Users
        check_command                   check_oracle_health_tbs_name!XE!nagios!oradbmon!tablespace-usage!users
        notifications_enabled           1
}

You can add all the modes you want. You can manually test the command like so. It’s very important that the ORACLE_HOME and other variables are set. They can be passed to the command directly, this way you don’t need to modify your nagios startup script to set the vars in the nagios user enviornment.




Tidak ada komentar: