nagios check_oracle_health install shell

2014-05-27

为了简化安装,写成脚本。

#ins_chk_ora_health.sh

#!/bin/sh

#输入ID,或者ID,针对多台主机

ID=$1
if [[ -z "$1" ]];then
echo "Usage: $0 ID"
exit 0;
fi

#防止重复执行后添加多次变量

sed -i '/ORACLE/d' ~/.bash_profile
grep ORACLE ~oracle/.bash_profile >> ~/.bash_profile
. ~/.bash_profile

#解决权限问题,否则报错:libnnz10.so: cannot restore segment prot after reloc

chcon -t texrel_shlib_t  $ORACLE_HOME/lib/libnnz10.so
chcon -t texrel_shlib_t  $ORACLE_HOME/lib/libclntsh.so.10.1

#添加tnsnames.ora,并防止重复添加

sed -i '/^DB/,$d' $ORACLE_HOME/network/admin/tnsnames.ora
cat >> $ORACLE_HOME/network/admin/tnsnames.ora << EOF

DB${ID} =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.10.1.${ID})(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dydb)
)
)
EOF

#下载解压安装包
wget -c http://wallcopper.com/tar/ora_health.gz -P /opt
cd /opt
tar zxf ora_health.gz
tar zxf DBI-1.631.tar.gz
tar zxf DBD-Oracle-1.70.tar.gz
tar zxf check_oracle_health-1.9.3.4.tar.gz

#安装3个包

pushd DBI-1.631;
perl Makefile.PL;make;make install
popd

pushd DBD-Oracle-1.70;
perl Makefile.PL;make;make install
popd

pushd check_oracle_health-1.9.3.4;
./configure;make;make install
popd

#修改nrpe配置

sed -i '/check_tnsping/d' /usr/local/nagios/etc/nrpe.cfg
sed -i '/check_session/d' /usr/local/nagios/etc/nrpe.cfg
cat > ora.txt << EOF
command[check_tnsping]=/usr/local/nagios/libexec/check_oracle_health --connect=DB${ID} --mode=tnsping
command[check_session]=/usr/local/nagios/libexec/check_oracle_health --connect=DB${ID} --username=system --password=whoami123456 --mo
de=sql --name='select count(1) from v\$session' --name2=current_sessions --warning 100 --critical 300
EOF

sed -i '/check_total_procs/r ora.txt' /usr/local/nagios/etc/nrpe.cfg

/etc/init.d/xinetd restart

#添加用户nagios到oinstall分组,否则报错:CRITICAL - cannot connect to DB17. ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc.

usermod -G oinstall nagios

#测试本机是否成功

source ~/.bash_profile

/usr/local/nagios/libexec/check_oracle_health --connect=DB${ID} --mode=tnsping
/usr/local/nagios/libexec/check_oracle_health --connect=DB${ID} --username=system --password=whoami123456 --mode=sql --name='select count(1) from v$session' --name2=current_sessions --warning 100 --critical 300

 

#nagios主机上增加check_tnsping.sh测试

/user/local/nagios/libexec/check_nrpe -H $1 -c check_tnsping

添加nagios配置:

define service{
use                     generic-service
host_name               172.16.1.1
service_description     tnsping
check_command           check_nrpe!check_tnsping
}

分类:Linux | 标签: |

相关日志

评论被关闭!