CentOS Stream 8
Sponsored Link

Nagios 4 : しきい値を設定する2021/06/03

 
しきい値の設定です。
デフォルトで有効になっている監視項目はしきい値も設定されていますが、変更する場合は以下のように設定します。
[1] しきい値は、デフォルトの項目については、監視設定ファイルに定義してあります。
Nagios サーバーのローカルホストの監視設定ファイル中で、それぞれの監視項目は [define service] で括られている部分が該当し、 [check_command] で指定されたコマンドに [!] で続くパラメーターがしきい値になります。 例えば、ルートパーティションのディスク使用量の監視は以下のように設定されています。
[root@dlp ~]#
vi /etc/nagios/objects/localhost.cfg
.....
.....
# Define a service to check the disk space of the root partition
# on the local machine.  Warning if < 20% free, critical if
# < 10% free space on partition.

# 上の説明にもある通り、空き容量が 20% を切ると Warning, 10% を切ると Critical

# しきい値を変更する場合はこの値を変更する

define service {

    use                     local-service           ; Name of service template to use
    host_name               localhost
    service_description     Root Partition
    check_command           check_local_disk!20%!10%!/
}
.....
.....

[root@dlp ~]#
systemctl restart nagios

[2] プラグインを追加した場合等で、自身でコマンド定義からしきい値まで設定する場合は以下のような流れになります。 (下例は [check_ntp_time] プラグイン追加時)
[root@dlp ~]#
dnf --enablerepo=epel -y install nagios-plugins-ntp
# 追加したプラグインのオプション等の使用方法を調べる

[root@dlp ~]#
/usr/lib64/nagios/plugins/check_ntp_time -h

.....
.....

 -w, --warning=THRESHOLD
    Offset to result in warning status (seconds)
 -c, --critical=THRESHOLD
    Offset to result in critical status (seconds)

.....
.....

# 調べたしきい値のオプション指定に従ってコマンドの定義を追加する

[root@dlp ~]#
vi /etc/nagios/objects/commands.cfg
# 最終行に追記

define command {
    command_name    check_ntp_time
    command_line    $USER1$/check_ntp_time -H $ARG1$ -w $ARG2$ -c $ARG3$
}

# しきい値も含めてサービスの定義を追加する

[root@dlp ~]#
vi /etc/nagios/objects/localhost.cfg
# 最終行に追記

# NTP サーバーとの時間が 1秒差で Warning, 2秒差で Critical

define service {
    use                     local-service
    host_name               localhost
    service_description     NTP_TIME
    check_command           check_ntp_time!ntp.nict.jp!1!2
    notifications_enabled   1
}

[root@dlp ~]#
systemctl restart nagios

[3] しきい値を超えると以下のようなメールが設定したメールアドレスへ送信されます。
From nagios@dlp.srv.world  Wed Jun  2 23:02:06 2021
Return-Path: <nagios@dlp.srv.world>
X-Original-To: root@localhost
Delivered-To: root@localhost
Date: Wed, 02 Jun 2021 23:02:06 -0500
To: root@localhost
Subject: ** PROBLEM Service Alert: localhost/NTP_TIME is CRITICAL **
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: nagios@dlp.srv.world
Status: R

***** Nagios *****

Notification Type: PROBLEM

Service: NTP_TIME
Host: localhost
Address: 127.0.0.1
State: CRITICAL

Date/Time: Wed Jun 2 23:02:06 CDT 2021

Additional Info:

NTP CRITICAL: Offset -8.077222943 secs, stratum best:0 worst:1
関連コンテンツ