zabbixでOracle監視

##Orabbixのダウンロード

```
$ sudo mkdir /opt/orabbix
$ sudo unzip /opt/orabbix/orabbix-1.2.3.zip 
$ sudo cp /opt/orabbix/init.d/orabbix /etc/init.d
$ sudo chmod u+x /etc/init.d/orabbix 
$ sudo chmod u+x /opt/orabbix/run.sh 

```
http://sourceforge.net/projects/orabbix/files/latest/download
からorabbix-1.2.3.zipをダウンロードし/opt/orabbixに配置。
ファイルの解凍をし必要なファイルをコピーする。

##ORACLE側の設定
```
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
に接続されました。
SQL>

SQL> CREATE USER ZABBIX
IDENTIFIED BY [任意のパスワード]
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;

SQL> GRANT ALTER SESSION TO ZABBIX;

SQL> GRANT CREATE SESSION TO ZABBIX;

SQL> GRANT CONNECT TO ZABBIX;

SQL> ALTER USER ZABBIX DEFAULT ROLE ALL;

SQL> GRANT SELECT ON V_$INSTANCE TO ZABBIX;

SQL> GRANT SELECT ON DBA_USERS TO ZABBIX;

SQL> GRANT SELECT ON V_$LOG_HISTORY TO ZABBIX;

SQL> GRANT SELECT ON V_$PARAMETER TO ZABBIX;

SQL> GRANT SELECT ON SYS.DBA_AUDIT_SESSION TO ZABBIX;

SQL> GRANT SELECT ON V_$LOCK TO ZABBIX;

SQL> GRANT SELECT ON DBA_REGISTRY TO ZABBIX;

SQL> GRANT SELECT ON V_$LIBRARYCACHE TO ZABBIX;

SQL> GRANT SELECT ON V_$SYSSTAT TO ZABBIX;

SQL> GRANT SELECT ON V_$PARAMETER TO ZABBIX;

SQL> GRANT SELECT ON V_$LATCH TO ZABBIX;

SQL> GRANT SELECT ON V_$PGASTAT TO ZABBIX;

SQL> GRANT SELECT ON V_$SGASTAT TO ZABBIX;

SQL> GRANT SELECT ON V_$LIBRARYCACHE TO ZABBIX;

SQL> GRANT SELECT ON V_$PROCESS TO ZABBIX;

SQL> GRANT SELECT ON DBA_DATA_FILES TO ZABBIX;

SQL> GRANT SELECT ON DBA_TEMP_FILES TO ZABBIX;

SQL> GRANT SELECT ON DBA_FREE_SPACE TO ZABBIX;

SQL> GRANT SELECT ON V_$SYSTEM_EVENT TO ZABBIX;

SQL>  exec dbms_network_acl_admin.create_acl(acl => 'resolve.xml',description => 'resolve acl', principal =>'ZABBIX', is_grant => true, privilege => 'resolve');
 exec dbms_network_acl_admin.assign_acl(acl => 'resolve.xml', host =>'*');
 commit;

SQL> select utl_inaddr.get_host_name('127.0.0.1') from dual;
```
Oracle 11g XE をWindows機にインストールし、接続用のユーザー作成および権限の付与を実施。

##Templateの取り込み

![無題.png](https://qiita-image-store.s3.amazonaws.com/0/70042/59add639-a079-0921-3d90-4f07a61bbb91.png)

/opt/orabbix/template/Orabbix_export_full.xmlをZabbixにインポート。

##設定ファイルの作成
```
$ sudo cp /opt/orabbix/conf/config.props.sample /opt/orabbix/conf/config.props
$ sudo vi /opt/orabbix/conf/config.props

#comma separed list of Zabbix servers
ZabbixServerList=ZabbixServer1

ZabbixServer1.Address=XXX.XXX.XXX.XXX
ZabbixServer1.Port=10051

#pidFile
OrabbixDaemon.PidFile=./logs/orabbix.pid
#frequency of item's refresh
OrabbixDaemon.Sleep=300
#MaxThreadNumber should be >= than the number of your databases
OrabbixDaemon.MaxThreadNumber=100

#put here your databases in a comma separated list
DatabaseList=XE

#Configuration of Connection pool
#if not specified Orabbis is going to use default values (hardcoded)
#Maximum number of active connection inside pool
DatabaseList.MaxActive=10

#The maximum number of milliseconds that the pool will wait
#(when there are no available connections) for a connection to be returned
#before throwing an exception, or <= 0 to wait indefinitely.
DatabaseList.MaxWait=100
DatabaseList.MaxIdle=1
#define here your connection string for each database
XE.Url=jdbc:oracle:thin:@XXX.XXX.XXX.XXX:1521:XE
XE.User=XXXXXX
XE.Password=XXXXXX
#Those values are optionals if not specified Orabbix is going to use the general values
XE.MaxActive=10
XE.MaxWait=100
XE.MaxIdle=1
XE.QueryListFile=./conf/query.props
```
/opt/orabbix/conf/config.propsファイルのコピーして作成。
DatabaseList=XEは、ホスト登録時に使用するホスト名と統一する。

##起動ファイルの変更

```
$ sudo vi /etc/init.d/orabbix

```
```
# Source function library.
. /lib/lsb//init-functions

# Get config.
# . /etc/sysconfig/network
```
. /lib/lsb//init-functions debian用にパスを変更。
\# . /etc/sysconfig/network debian用にコメントアウト。

```
start(){
        echo -n "Starting Orabbix service:"
        cd $orabbix
        $startup
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/orabbix
        return $RETVAL
}

stop(){
        echo -n "Stopping Orabbix service:"
        pid=`ps -ef  |grep java |grep orabbix | awk '{ print $2 }'`
        kill `cat $orabbix/logs/orabbix.pid`
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f  /var/lock/orabbix
        return $RETVAL
```
/var/lock/orabbix ロックファイルのパスを変更。

```
$ sudo /etc/init.d/orabbix start
```
Orabbixを起動。

```
 2015-03-05 00:44:46,276 [pool-1-thread-1] INFO  Orabbix - Done with dbJob on database XE QueryList elapsed time 2007 ms
 2015-03-05 00:44:53,393 [main] INFO  Orabbix - Starting Orabbix Version 1.2.3
 2015-03-05 00:44:53,496 [main] INFO  Orabbix - Orabbix started with pid:21594
 2015-03-05 00:44:53,497 [main] INFO  Orabbix - PidFile -> ./logs/orabbix.pid
 2015-03-05 00:44:54,227 [main] INFO  Orabbix - DB Pool created: org.apache.commons.dbcp.datasources.SharedPoolDataSource@1975e01
 2015-03-05 00:44:54,228 [main] INFO  Orabbix - URL=jdbc:oracle:thin:@XXX.XXX.XXX.XXX:1521:XE
 2015-03-05 00:44:54,228 [main] INFO  Orabbix - maxPoolSize=10
 2015-03-05 00:44:54,228 [main] INFO  Orabbix - maxIdleSize=1
 2015-03-05 00:44:54,229 [main] INFO  Orabbix - maxIdleTime=1800000ms
 2015-03-05 00:44:54,229 [main] INFO  Orabbix - poolTimeout=100
 2015-03-05 00:44:54,229 [main] INFO  Orabbix - timeBetweenEvictionRunsMillis=-1
 2015-03-05 00:44:54,229 [main] INFO  Orabbix - numTestsPerEvictionRun=3
 2015-03-05 00:44:58,649 [main] INFO  Orabbix - Connected as ZABBIX
 2015-03-05 00:44:58,656 [main] INFO  Orabbix - --------- on Database -> XE
```
/opt/orabbix/logs/orabbix.logで起動しているかどうか確認する。

```
2015-03-05 00:42:32,953 [main] INFO  Orabbix - Starting Orabbix Version 1.2.3
 2015-03-05 00:42:33,034 [main] INFO  Orabbix - Orabbix started with pid:21173
 2015-03-05 00:42:33,034 [main] INFO  Orabbix - PidFile -> ./logs/orabbix.pid
 2015-03-05 00:42:33,043 [main] ERROR Orabbix - Error on Configurator getConnection while getting XE.Url null
 2015-03-05 00:42:33,043 [main] ERROR Orabbix - Error on Configurator getConnection while getting DefaultUser null
 2015-03-05 00:42:33,044 [main] ERROR Orabbix - Error on Configurator getConnection while getting XE.Password null
 2015-03-05 00:42:33,822 [main] INFO  Orabbix - DB Pool created: org.apache.commons.dbcp.datasources.SharedPoolDataSource@1975e01
 2015-03-05 00:42:33,822 [main] INFO  Orabbix - URL=
 2015-03-05 00:42:33,823 [main] INFO  Orabbix - maxPoolSize=10
 2015-03-05 00:42:33,823 [main] INFO  Orabbix - maxIdleSize=1
 2015-03-05 00:42:33,823 [main] INFO  Orabbix - maxIdleTime=1800000ms
 2015-03-05 00:42:33,823 [main] INFO  Orabbix - poolTimeout=100
 2015-03-05 00:42:33,824 [main] INFO  Orabbix - timeBetweenEvictionRunsMillis=-1
 2015-03-05 00:42:33,824 [main] INFO  Orabbix - numTestsPerEvictionRun=3
 2015-03-05 00:42:33,887 [main] ERROR Orabbix - Error on Configurator for database XE -->No suitable driver found for
 2015-03-05 00:42:33,887 [main] INFO  Orabbix - This Database XE removed
 2015-03-05 00:42:33,890 [main] ERROR Orabbix - ERROR on main - Connections is empty
```
接続情報などが間違っている場合、何かしらエラーがログに記録されます。

##ZABBIXのホスト作成
![無題.png](https://qiita-image-store.s3.amazonaws.com/0/70042/3449b418-5cdf-e283-1ce1-f854a70880f3.png)

ホスト名を設定ファイルを統一する。

![2.png](https://qiita-image-store.s3.amazonaws.com/0/70042/f69ba38a-c824-002b-1c4d-49bad525b983.png)

取り込んだテンプレートを選択する。

![無題.png](https://qiita-image-store.s3.amazonaws.com/0/70042/0b7c2927-d36a-d155-c573-be57008227c6.png)




以下、ドキュメントをおよび、URLを参照。
http://www.smartmarmot.com/wiki/index.php/Orabbix#Download_.26_Installation_Instructions
http://sysmagazine.com/posts/197746/