3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

nagios3を入れてみた

Last updated at Posted at 2013-08-01

参考: 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

check_http で 403を監視する

  • 403であればOK
/usr/lib64/nagios/plugins/check_http \
  --ssl -H example.com --url=/abc/ --expect 403

-v を付けると詳細モード

# ArchLinuxだと以下
/usr/lib/monitoring-plugins/check_http

通知の件名に日付を追加

  • commands.cfg
define command {
    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" "本文" | /bin/mail -s "** 件名 ** $DATE$ $TIME$" $CONTACTEMAIL$
}
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?