LoginSignup
2
5

More than 5 years have passed since last update.

nagios4をdockerで動かしてメール通知

Last updated at Posted at 2018-07-01

設定

  • ./objects/contacts.cfg
  • ./conf.d/nw_office.cfg
  • ./conf.d/custom-host.cfg

を作成する

./objects/contacts.cfg
define contact {
    contact_name            nagiosadmin             ; Short name of user
    use                     generic-contact         ; Inherit default values from generic-contact template (defined above)
    alias                   Nagios Admin            ; Full name of user
    email                   nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

define contactgroup {
    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 nagiosadmin
}
  • nagios@localhost を検知時受け取りたいメールアドレスに置換する。
./conf.d/nw_office.cfg
define host{
    use        custom-host
    host_name  host1
    address    192.168.0.4
}

define service{
    use                     generic-service
    service_description     check_ssh_host1
    host_name               host1
    check_command           check_ssh
    check_interval          1
}
  • 監視の周期を短くするため以下作成
./conf.d/custom-host.cfg
define host{
    name                            custom-host
    notifications_enabled           1
    event_handler_enabled           1
    flap_detection_enabled          1
    #failure_prediction_enabled      1
    process_perf_data               1
    retain_status_information       1
    retain_nonstatus_information    1
    check_command                   check-host-alive
    max_check_attempts              2
    notification_interval           60
    notification_period             24x7
    notification_options            d,u,r
    contact_groups                  admins
    register                        0
}

起動

docker run \
 --name nagios4 \
 --restart=always \
 -p 0.0.0.0:8080:80 \
\
 -e MAIL_RELAY_HOST="リレーサーバー" \
 -e MAIL_INET_PROTOCOLS="ipv4" \
 -e NAGIOS_FQDN="FQDNを適当に設定" \
 -e NAGIOS_TIMEZONE="Asia/Tokyo" \
\
 -v /etc/localtime:/etc/localtime \
 -v $(pwd)/conf.d:/opt/nagios/etc/conf.d \
 -v $(pwd)/objects/contacts.cfg:/opt/nagios/etc/objects/contacts.cfg \
 jasonrivers/nagios:latest
  • http://localhost:8080 にアクセス。

    • nagiosadmin / nagios
  • swapが無くてcritical表示されるのが嫌な場合は、 objects/localhost.cfg を修正する。

実行コマンドの場所

  • /opt/nagios/libexec/check_〜

グラフ表示

  • graphed-service を付ける
 define service{
-   use                     generic-service
+   use                     generic-service,graphed-service
    service_description     check_ssh_host1
    host_name               host1
    check_command           check_ssh
    check_interval          1
 }

スクリーンショット_2018-07-02_10-03-44.png

2
5
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
2
5