check_vmware_api.plを使ってVMware ESXiのホスト情報の取得ができたので、実際にNagiosに監視対象として組み込んでみます
Monitoring the VMware ESXi with Nagios (1)
http://www.rootlinks.net/2013/08/20/monitoring-the-vmware-esxi-with-nagios-1/
Monitoring the VMware ESXi with Nagios (2)
http://www.rootlinks.net/2013/08/20/monitoring-the-vmware-esxi-with-nagios-2/
- リソースファイルにID,passwordを追加
- コマンドファイルに追記
- VMware ESXiのhostファイル追加
- Nagiosの設定ファイルのチェック
- Nagiosの設定ファイルの再読み込み
- 管理画面から確認
Nagiosのリソースファイルに監視対象のVMware ESXiにアクセスするためのユーザIDtoパスワードを追加します
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
[root@host1 ~]# vi /usr/local/nagios/etc/resource.cfg [root@host1 ~]# cat /usr/local/nagios/etc/resource.cfg ########################################################################### # # RESOURCE.CFG - Sample Resource File for Nagios 3.4.1 # # Last Modified: 09-10-2003 # # You can define $USERx$ macros in this file, which can in turn be used # in command definitions in your host config file(s). $USERx$ macros are # useful for storing sensitive information such as usernames, passwords, # etc. They are also handy for specifying the path to plugins and # event handlers - if you decide to move the plugins or event handlers to # a different directory in the future, you can just update one or two # $USERx$ macros, instead of modifying a lot of command definitions. # # The CGIs will not attempt to read the contents of resource files, so # you can set restrictive permissions (600 or 660) on them. # # Nagios supports up to 32 $USERx$ macros ($USER1$ through $USER32$) # # Resource files may also be used to store configuration directives for # external data sources like MySQL... # ########################################################################### # Sets $USER1$ to be the path to the plugins $USER1$=/usr/local/nagios/libexec # Sets $USER2$ to be the path to event handlers #$USER2$=/usr/local/nagios/libexec/eventhandlers # Store some usernames and passwords (hidden from the CGIs) #$USER3$=someuser #$USER4$=somepassword # VMware ESXi access user & password $USER11$=root $USER12$=password |
check_vmware_api.plを使ってESXiに対して情報を取得するコマンドを追記します
これは”/usr/local/nagios/etc/nagios.cfg”で”cfg_file=/usr/local/nagios/etc/objects/commands.cfg”が有効になっているか確認して下さい
下記の設定を/usr/local/nagios/etc/objects/commands.cfgに追記します
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# check vmware esxi machine # check cpu define command{ command_name check_vmware_api.pl_cpu command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l cpu -s usage -w $ARG1$ -c $ARG2$ } # check memory usage define command{ command_name check_vmware_api.pl_mem command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l mem -s usage -w $ARG1$ -c $ARG2$ } # check net usage define command{ command_name check_vmware_api.pl_net command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l net -s usage -w $ARG1$ -c $ARG2$ } # check runtime status define command{ command_name check_vmware_api.pl_runtime command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l runtime -s status } # check io read define command{ command_name check_vmware_api.pl_ioread command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l io -s read -w $ARG1$ -c $ARG2$ } # check io write define command{ command_name check_vmware_api.pl_iowrite command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l io -s write -w $ARG1$ -c $ARG2$ } |
これは”/usr/local/nagios/etc/nagios.cfg”で”cfg_dir=/usr/local/nagios/etc/servers”が有効になっているか確認して下さい
新たに/usr/local/nagios/etc/servers/vmware.cfgを作成して下記の項目を追加して下さい
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# Host esxi01.rootlinks.net define host{ use linux-server host_name esxi01 alias VMWare ESXi address 192.168.1.10 } # Define a service to "ping" the local machine define service{ use generic-service host_name esxi01 service_description PING check_command check_ping!100.0,20%!500.0,60% } # VMWare # check cpu define service{ use generic-service host_name esxi01 service_description ESXi CPU Load check_command check_vmware_api.pl_cpu!80!90 } # check memory usage define service{ use generic-service host_name esxi01 service_description ESXi Memory usage check_command check_vmware_api.pl_mem!80!90 } # check net define service{ use generic-service host_name esxi01 service_description ESXi Network usage check_command check_vmware_api.pl_net!102400!204800 } # check runtime status define service{ use generic-service host_name esxi01 service_description ESXi Runtime status check_command check_vmware_api.pl_runtime } # check io read define service{ use generic-service host_name esxi01 service_description ESXi IO read check_command check_vmware_api.pl_ioread!40!90 } # check io write define service{ use generic-service host_name esxi01 service_description ESXi IO write check_command check_vmware_api.pl_iowrite!40!90 } |
変更した設定ファイルチェックを行います
1 2 |
[root@host1 ~]# /etc/init.d/nagios checkconfig Running configuration check... OK. |
エラーが出た場合はNagiosの起動ができませんので各ファイルの記述を確認して下さい
1 2 |
[root@host1 ~]# /etc/init.d/nagios checkconfig Running configuration check... CONFIG ERROR! Check your Nagios configuration. |
変更した設定ファイルの再読み込みを行います
1 2 3 |
[root@host1 ~]# /etc/init.d/nagios reload Running configuration check...done. Reloading nagios configuration...done |
Nagiosの管理画面にアクセスしてVMware ESXiが登録されて、ホストの状態が取得できていれば大丈夫と思います