サーバー統合 · 2 min read · Oct 18, 2025

Nagios 3.x.x/Icinga 1.x.x サーバー統合 SMS アラート用 FoxBox デバイスを使用した Debian Squeeze

Nagios 3.x.x/Icinga 1.x.x サーバー統合 SMS アラート用 FoxBox デバイスを使用した Debian Squeeze

このチュートリアルでは、標準の Nagios (または Icinga) 監視サーバーを SMS 通知外部デバイスである FoxBox ( www.smsfoxbox.it) と統合する方法を説明します。

1 予備ノート

FoxBox は、製造元によれば、ハードウェアの仕様が異なる 2 つの類似バージョン (G25 と LX800) があります。このガイドでは、SMS ゲートウェイ LX800 に言及します (私たちはその高いパフォーマンスと CompactFlash ストレージのためにこれを購入しましたが、他のバージョンにも問題なく拡張できると確信しています)。

私たちのサーバーは、Debian Squeeze 上で Nagios Core 3.5.0 (1.4.16 Nagios プラグイン付き) を実行しています。おそらく、異なるディストリビューションではパスが変更されますが、論理はほぼ同じです。

2 FoxBox 側のインストール

このデバイスは、これらの通信タスクのために設計されているため、ここで行うことはあまりありません。

  • 監視サーバーから到達可能な有効な IP アドレスを提供すること;
  • SMS を送信するためにテスト済みの完全に動作する SIM カードを挿入すること。

3 サーバー側のインストール

まず最初に、このスクリプトを /usr/lib/nagios/plugins/ フォルダー内に配置する必要があります:

#!/usr/bin/perl
use LWP::UserAgent;
use Getopt::Long;
use strict;
use warnings;
use constant OK => 0;
use constant WARNING => 1;
use constant CRITICAL => 2;
use constant UNKNOWN => 3;
use constant SEND_PAGE => "/source/send_sms.php";
my($host);
my($username);
my($password);
my($number);
my($message);
sub usage() {
    print("Usage: send_sms -h|--host  -u|--user  --pw|--pass
 -n|--number
 -m|--message \n\n");
    print(" - SMS FoxBox の IP アドレスまたはホスト名\n");
    print(" - SMS FoxBox 管理者の名前\n");
    print(" - SMS FoxBox 管理者のパスワード\n");
    print(" - SMS が送信される電話番号\n");
    print(" - 送信されるメッセージ\n");
}
sub send_sms {
    my($host, $user, $pass, $phonenum, $text) = @_;
    my($ua);
    my($html_page);
    my($response);
    my($status_code);
    $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $response = $ua->post("http://$host" . SEND_PAGE,
                [
                    "username" => $user,
                    "pwd" => $pass,
                    "from" => 'Nagios',
                    "nphone" => $phonenum,
                    "testo" => $text,
                    "nc" => "http://$host" . SEND_PAGE
                ]);
    if(!$response->is_success) {
        print("ERROR: " . $response->status_line . "\n");
        $status_code = UNKNOWN;
    }
    $html_page =  $response->content;
    if($html_page =~ /p class="(\w+)"/g) {
        if($1 eq "confneg") {
            print("ERROR: SMS を送信できません\n");
            $status_code = UNKNOWN;
        }
        else {
            $status_code = OK;
        }
    }
    else {
        print("ERROR: 不明なページ出力\n");
        $status_code = UNKNOWN;
    }
    return $status_code;
}
undef $host;
undef $username;
undef $password;
undef $number;
undef $message;
GetOptions(    'host|H=s'    => \$host,
        'user|u=s'     => \$username,
        'pass|pw=s'     => \$password,
        'number|n=s'     => \$number,
        'message|m=s'     => \$message);
if(!defined $host || !defined $username || !defined $password || !defined $number || !defined $message) {
    usage();
    exit(UNKNOWN);
}

$message =~ s/\\n/\n/g;
my($ret_status);
$ret_status = send_sms($host, $username, $password, $number, $message);
exit($ret_status);

このファイルの権限を適切に設定し、Nagios ユーザーが実行できるようにすることも重要です。

次に、従来のメールチャネルの代わりに SMS チャネルで動作する新しい通知コマンドを追加する必要があります。そのためには、/etc/nagios3/commands.cfg ファイルに次の行を追加します:

# 'notify-host-by-foxbox' コマンド定義
define command{
        command_name    notify-host-by-foxbox
        command_line    /usr/lib/nagios/plugins/sendSMS.sh -h "127.0.0.1" -u "nagiosadmin" -pw "nagios" -n "$CONTACTPAGER$" -m "ホストアラート: $HOSTNAME$ \nホスト状態: $HOSTSTATE$ \n日付/時間: $LONGDATETIME$"
        }
# 'notify-service-by-foxbox' コマンド定義
define command{
        command_name    notify-service-by-foxbox
        command_line    /usr/lib/nagios/plugins/sendSMS.sh -h "127.0.0.1" -u "nagiosadmin" -pw "nagios" -n "$CONTACTPAGER$" -m "サービスアラート: $HOSTALIAS$/$SERVICEDESC$ \nサービス状態: $SERVICESTATE$ \n日付/時間: $LONGDATETIME$"
        }

ご覧のとおり、連絡先に新しい情報が必要です: 電話番号です。したがって、/etc/nagios3/conf.d/contacts_nagios2.cfg ファイルで “pager” として定義する必要があります。

さらに、サービス/ホスト通知コマンドを設定します。デフォルトでは、これらはメールチャネルを使用していますが、新しい通知コマンドでアラートを送信したいため、”service_notification_commands” および “host_notification_commands” のパラメータも編集する必要があります:

define contact{
        contact_name                    test-contact
        use                             generic-contact
        alias                           tester
        email                           yourname@domain
        host_notification_commands      notify-host-by-foxbox
        service_notification_commands   notify-service-by-foxbox
        pager                           12453683421
        }

もちろん、設定が完了したら、効果を確認するために Nagios サービスを再起動する必要があります。

すべてが正常であることを確認するために、事前チェックを実行することもできます:

nagios3 -v /etc/nagios3/nagios.cfg

私が見る限り、このアーキテクチャは、すべてを一つにまとめた通知ソリューションを提供するために、いくつかの FoxBox バージョンでも実装されています (EasyG2 G25 および Monitoring LX800)。

(参考: www.smsfoxbox.it)

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。