Help us understand the problem. What is going on with this article?

nagios3を入れてみた

More than 3 years have passed since last update.

参考: http://www.atmarkit.co.jp/ait/articles/0211/28/news001.html

準備

インストール
$ sudo apt-get install nagios3 nagios-plugins-extra
  • 途中、nagiosadminユーザのパスワードの設定がある。 webインターフェースにログインする時に必要。
web設定
$ sudo ln -s /usr/share/nagios3/htdocs/ /var/www/nagios3
$ sudo /etc/init.d/apache2 restart
nagios3設定
$ sudo vim /etc/nagios3/nagios.cfg
cfg_dir=/etc/nagios3/servers <- コメントアウトする。
$ sudo mkdir /etc/nagios3/servers/
nagios.cfg
-check_external_commands=0
+check_external_commands=1

監視対象設定

/etc/nagios3/servers/office.cfg
# host
define host{
    use        generic-host
    host_name  server-01
    address    221.111.xxx.xx1
}
define host{
    use        generic-host
    host_name  server-02
    address    221.111.xxx.xx2
}

# hostgroup
define hostgroup{
    hostgroup_name office-server
    members server-01, server-02
}

# commands
define command{
    command_name check_http-host1
    command_line $USER1$/check_http -I 221.111.xxx.xx1 -u http://221.111.xxx.xx1/check.html
}
define command{
    command_name check_http-host2
    command_line $USER1$/check_http -I 221.111.xxx.xx2 -u http://221.111.xxx.xx2/check.html
}
# http
define service{
    use                     generic-service
    host_name               server-01
    service_description     http
    check_command           check_http-host1
}
define service{
    use                     generic-service
    host_name               server-02
    service_description     http
    check_command           check_http-host2
}

監視方法の変更

/etc/nagios3/conf.d/generic-service_nagios2.cfg の設定を継承する。

define service{
    ...
    normal_check_interval   1 ; チェック間隔。default 5 min
    notification_interval   1 ; 再通知間隔。default 0
    flap_detection_enabled  0 ; テストでサービスdown,upを繰り返した場合、通知が来なくなるので。
    ...
}

通知先の修正

$ sudo vim /etc/nagios3/conf.d/contacts_nagios2.cfg
define contact{
        contact_name                    root
        alias                           Root
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           root@localhost
        }
cfgファイルのチェック
$ sudo nagios3 -v /etc/nagios3/nagios.cfg
nagios再起動
$ sudo /etc/init.d/nagios3 restart

plugin

リスト(check_ の文字は省略しています。)

  • ls /usr/lib/nagios/plugins/

apt backuppc breeze by_ssh cert_expire clamd cluster dhcp dig disk disk_smb dns dnssec_delegation dummy email_delivery email_delivery_epn entropy file_age flexlm fping ftp game haproxy host hpasm hpjd http httpd_status icmp ide_smart ifoperstatus ifstatus imap imap_quota imap_quota_epn imap_receive imap_receive_epn ipmi_sensor ircd jabber ldap ldaps libs lm_sensors load log mailq memcached mrtg mrtgtraf multipath mysql mysql_health mysql_query nagios nntp nntps nt ntp ntp_peer ntp_time nwstat oracle overcr packages pgsql ping pop printer procs radius raid rbl real rpc rta_multi running_kernel sensors simap smtp smtp_send smtp_send_epn snmp snmp_environment soas spop ssh ssl_cert ssmtp statusfile swap tcp time udp ups users wave webinject whois zone_auth zone_rrsig_expiration

使い方

$ /usr/lib/nagios/plugins/check_http

を実行するとオプションが表示されるので、それをdefine command {} で設定し、define service{} で利用する。

Error: Could not stat() command file '/var/lib/nagios3/rw/nagios.cmd'

dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
sudo /etc/init.d/nagios3 restart
tukiyo3
好き:レトロ風ゲーム、宗教音楽
https://tukiyo.github.io
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away