说明 由于spool直接执行sql v$locked_object lo, dba_objects ao, v$session ,无法识别$符号,使用斜杠转义也是无效,所以sqlplus bol/bol @/opt/bolck_table.sh执行 没有问题

执行脚本
#[root@rac2 opt]# cat /opt/bolck_table_oracle.sh
#!/bin/bash
sqlplus bol/bol @/opt/bolck_table.sh

#sql语句脚本,将结果输入到/tmp/block_table.txt
[root@rac2 opt]# cat /opt/bolck_table.sh
spool /tmp/block_table.txt
select count(sess.sid) from v$locked_object lo, dba_objects ao, v$session sess where ao.object_id = lo.object_id and lo.session_id = sess.sid;
spool off
exit;

#zabbix key,获取 /tmp/block_table.txt里面的标识
[root@rac2 opt]# cat /etc/zabbix/zabbix_agentd.d/oracle_moniter.conf
UserParameter=oracle.gps_count,cat /tmp/GPS.txt |sed -n '5p'
UserParameter=oracle.block_table_count,cat /tmp/block_table.txt |sed -n '4p'
UserParameter=oracle.listenport,netstat -anltp|grep LISTEN|grep 1521|wc -l
UserParameter=oracle.process,ps -ef|grep BOL|wc -l
UserParameter=oracle.asm.process,ps -ef|grep asm|wc -l
UserParameter=oracle.status_online.process,/u01/app/11.2.0/grid/bin/crs_stat -t -v|grep 'ONLINE'|wc -l
UserParameter=oracle.status_offline.process,/u01/app/11.2.0/grid/bin/crs_stat -t -v|grep 'OFFLINE'|wc -l

#每10分钟执行一次
[root@rac2 opt]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
/10 * root su - oracle -s /bin/bash /opt/bolck_table_oracle.sh
在zabbix里面添加iterm,添加triggers即可