====== Pandora FMS と SMS ゲートウェイのインストールと設定 ======
{{indexmenu_n>2}}
[[ja:documentation:start|Pandora FMS ドキュメント一覧に戻る]]
===== GSM デバイスについて =====
シリアルポート(USB) を通して SMS を送信するためには、特別なデバイスを利用します。USB ケーブルで接続することができる GSM モジュールまたは、携帯電話と一般的な USB ケーブルの組み合わせが利用できます。どれであるかはそれほど重要ではなく、ここで利用しているものは、MTX 65 v3 です。以下のウェブサイトでだいたい 100$ くらいで入手できます。
* http://matrix.es
* http://www.youtube.com/watch?v=OxcKAarS2M0
Yutube のものでは、GSM アンテナ(例えばデータセンターが地下にある場合に便利)のようないくつかのオプションとともに小さくて互換性のあるものです。
GSM 携帯を利用することも良いオプションです。現在ほとんどの(GSM)携帯は linux でサポートされています。
===== デバイスのインストール =====
最初にハードウエアの設定を行います。このデバイスにはいくつかのパーツがあります。
* 小さいコネクタの通常の USB ケーブル
* 電源アダプタ (この例ではヨーロッパの 220v のものです。あまりかであれば 110v のものが必要です。)
* SIM カード
* Pandora FMS の SMS ゲートウェイデバイス
{{ :wiki:sms_package.jpg }}
Pandora FMS の SMS ゲートウェイデバイスを開きます。
{{ :wiki:imag0026.jpg }}
SIM カードを挿します。
{{ :wiki:imag0027.jpg }}
電源を接続し、SMS ゲートウェイデバイスに USB ケーブルを接続します。
{{ :wiki:imag0030.jpg }}
さらにそれを Pandora FMS サーバの USB ポートに接続します。
{{ :wiki:imag0029.jpg }}
サーバへデバイスを接続して数秒したら、コマンドラインから "dmesg" を実行します。次のような画面が表示されます。
{{ :wiki:smsstep1.png }}
This means your device has been recognized by the kernel and it is ready to accept commands on a device, such as ''/dev/ttyACM0''.
これは、デバイスを kernel が ''/dev/ttyACM0'' として認識し、利用できるようになったことを示します。
ここまでくればハードウエアの設定は完了です。うまくいってない場合は、次の手順を確認してください。
* デバイスが接続され、LED が緑で点滅しているかどうか。
* デバイスが USB ポートに接続されているか。一方が SMS デバイス、他方が Pandora FMS サーバになっているか。
* デバイスに SIM カードが正しく挿入されているかどうか。
===== 新たなデバイスを利用するための SMSTools の設定 =====
このデバイスは、SMSTools というソフトウエアパッケージで制御します。smstools は、Linux ディストリビューションにより提供されているパッケージまたは、Artica が提供している RPM パッケージ(提供はRPMパッケージのみ)を使ってインストールできます。
==== RPM を利用しているシステム ====
我々の RPM を利用するのが簡単です。次のようにインストールするだけです。
# rpm -i smstools*.rpm
==== SMStools の設定 ====
基本設定ファイルを編集します。
# vi /etc/smsd.conf
次の設定を書きます。dmesg の出力が ttyACM0 でない場合は、システムが検出した tty デバイスに応じて変更してください。
# Example smsd.conf. Read the manual for a description
devices = GSM1
logfile = /var/log/smsd.log
loglevel = 10
[GSM1]
device = /dev/ttyACM0
incoming = no
pin = 2920
SIM に設定された暗証番号を定義します。この例では、"2920" です。
そして、smstools を手動で起動します。
# /usr/bin/smstools start
SMS の送信テストをします。電話番号はプリフィックスを含めて指定することに注意してください。この例では、+34 がスペインで、電話番号が 627934648 です。
$ sendsms 34627934648 "Pandora FMS rocks"
数分待って、すべて正常化どうかログを確認します。数秒で SMS を受信します。ネットワークによっては、最初の SMS は 10-20秒遅れるので、それ以上待ってください。次の SMS からすぐに届きます。SMSTools は、メッセージ送信にキューを利用します。たくさん送信したい場合、携帯のネットワークの処理に依存した速さになります。
ログの確認は次の通りです。
# cat /var/log/smsd.log
2009-11-12 11:30:12,2, smsd: Smsd v2.2.20 started.
2009-11-12 11:30:12,6, smsd: outgoing file checker has started.
2009-11-12 11:30:12,6, GSM1: Modem handler 0 has started.
2009-11-12 11:30:13,6, smsd: Moved file /var/spool/sms/outgoing/send_mNZxHa to /var/spool/sms/checked
2009-11-12 11:30:13,6, smsd: I have to send 1 short message for /var/spool/sms/checked/send_iUegPD
2009-11-12 11:30:13,6, GSM1: Sending SMS from to 627934648
2009-11-12 11:30:13,6, GSM1: Checking if modem is ready
2009-11-12 11:30:13,7, GSM1: -> AT
2009-11-12 11:30:13,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:14,7, GSM1: <- AT
OK
2009-11-12 11:30:14,6, GSM1: Checking if modem needs PIN
2009-11-12 11:30:14,7, GSM1: -> AT+CPIN?
2009-11-12 11:30:14,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:14,7, GSM1: <- AT+CPIN?
+CPIN: SIM PIN
OK
2009-11-12 11:30:14,5, GSM1: Modem needs PIN, entering PIN...
2009-11-12 11:30:14,7, GSM1: -> AT+CPIN="2920"
2009-11-12 11:30:14,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:15,7, GSM1: <- AT+CPIN="2920"
OK
2009-11-12 11:30:15,7, GSM1: -> AT+CPIN?
2009-11-12 11:30:15,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:15,7, GSM1: <- AT+CPIN?
+CPIN: READY
OK
2009-11-12 11:30:15,6, GSM1: PIN Ready
2009-11-12 11:30:15,6, GSM1: Checking if Modem is registered to the network
2009-11-12 11:30:15,7, GSM1: -> AT+CREG?
2009-11-12 11:30:15,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:16,7, GSM1: <- AT+CREG?
+CREG: 0,2
OK
2009-11-12 11:30:16,5, GSM1: Modem is not registered, waiting 10 sec. before retrying
2009-11-12 11:30:26,7, GSM1: -> AT+CREG?
2009-11-12 11:30:26,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:26,7, GSM1: <- AT+CREG?
+CREG: 0,5
OK
2009-11-12 11:30:26,6, GSM1: Modem is registered to a roaming partner network
2009-11-12 11:30:26,6, GSM1: Selecting PDU mode
2009-11-12 11:30:26,7, GSM1: -> AT+CMGF=0
2009-11-12 11:30:26,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:26,7, GSM1: <- AT+CMGF=0
OK
2009-11-12 11:30:26,7, GSM1: -> AT+CMGS=94
2009-11-12 11:30:26,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:27,7, GSM1: <- AT+CMGS=94
>
2009-11-12 11:30:27,7, GSM1: -> 001100099126974346F900F1FF5CC8373BCC0295E7F437A83C07D5DDA076D93D0FABCBA069730A2297417079BD2C0EBB406779789C0ECF41F0B71C44AF83C66FB7391D76EBC32C503B3C46BFE96516081E7693DFF230C8D89C82E4EFF17A0E
2009-11-12 11:30:27,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:31,7, GSM1: <- 001100099126974346F900F1FF5CC8373BCC0295E7F437A83C07D5DDA076D93D0FABCBA069730A2297417079BD2C0EBB406779789C0ECF41F0B71C44AF83C66FB7391D76EBC32C503B3C46BFE96516081E7693DFF230C8D89C82E4EFF17A0E
+CMGS: 0
OK
2009-11-12 11:30:31,5, GSM1: SMS sent, To: 627934648
2009-11-12 11:30:31,6, smsd: Deleted file /var/spool/sms/checked/send_iUegPD
2009-11-12 11:30:32,6, smsd: I have to send 1 short message for /var/spool/sms/checked/send_mNZxHa
2009-11-12 11:30:32,6, GSM1: Sending SMS from to 34627934648
2009-11-12 11:30:32,7, GSM1: -> AT+CMGS=29
2009-11-12 11:30:32,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:33,7, GSM1: <- AT+CMGS=29
>
2009-11-12 11:30:33,7, GSM1: -> 0011000B914326974346F900F1FF11D0B09BFC968741C6E614247F8FD773
2009-11-12 11:30:33,7, GSM1: Command is sent, waiting for the answer
2009-11-12 11:30:36,7, GSM1: <- 0011000B914326974346F900F1FF11D0B09BFC968741C6E614247F8FD773
+CMGS: 1
OK
2009-11-12 11:30:36,5, GSM1: SMS sent, To: 34627934648
2009-11-12 11:30:36,6, smsd: Deleted file /var/spool/sms/checked/send_mNZxHa
最後に、今後のために次の対応をしておきます。
**1.** 不必要にログファイルが巨大にならないように、/etc/smsd.conf のログレベルを 1 にします。
**2.** システムが再起動したときに smsd が自動起動するように設定(/etc/init.d/sms を /etc/rc2.d/S90sms または、/etc/rc.d/rc2.d/S90sms へリンク)しておきます。パッケージからインストールした場合は、おそらくすでに設定されていますので、確認してください。
===== Pandora FMS アラートの設定 =====
This steps reproduce the basic steps to create SMS alerts in Pandora FMS 3.x. For more information see "[[:en:documentation:04_using:01_alerts|Pandora FMS Alert System]]".
Pandora FMS で SMS アラーとを作成する基本的な手順を示します。より詳細は、"[[:ja:documentation:04_using:01_alerts|Pandora FMS アラートシステム]]" を参照してください。
コマンドを作成します。
{{ :wiki:smsalerts1.png?direct& }}
アクションを作成します。
{{ :wiki:smsalerts2.png?direct& }}
アクションをアラートテンプレートを使ってモジュールに割り当てます。この場合、モジュールが障害状態になったときに送信するアラートテンプレートです。
===== 一般的なハードウエアおよび Gnokii を使って SMS を送信するためのゲートウェイ =====
\\
It is recommended to keep your systems updated with the [[:en:documentation:08_technical_reference:10_versions|latest version of Pandora FMS]]. **This information is kept for historical purposes**.\\
\\
[[:ja:documentation:08_technical_reference:10_versions|Pandora FMS の最新バージョン]] にシステムをアップデートすることをお勧めします。**ここに記載の内容は、過去の情報を保持するためものです。**
This method for sending SMS was the one proposed in Pandora FMS versions 1.x and 2.x. in version 3.x [[:en:documentation:07_technical_annexes:02_pandorafms_sms_gateway#configure_smstools_to_use_the_new_device|smstools]] is used. The method based on **smstools** is better and it is not recommended to use **Gnokii** due to ist complexity and possibilities of failure. However it is referenced here to provide alternative methods to **smtools**.
SMS を送信するためのこの方法は、Pandora FMS バージョン 1.x および 2.x での方法です。バージョン 3.x では [[:ja:documentation:07_technical_annexes:02_pandorafms_sms_gateway#新たなデバイスを利用するための_smstools_の設定|smstools]] が使用されます。 **smstools** 利用する方法の方が優れており、複雑で失敗する可能性がある、**Gnokii** の使用はお勧めしません。 ただし、ここでは **smtools** の代替手法として示しています。
この項では、送信キューにもとづいた、SMS 送信ゲートウェイを構築する方法を説明しています。この方法では、携帯を接続し、Gnokii プロジェクトのソフトウエアを通して SMS を送信する SMS 送信サーバを実装します。また、SMS 送信には、別のリモートサーバを利用できます。これにより、異なる Pandora FMS サーバから、それぞれに携帯を接続することなく、メッセージを送信することができます。
最初に、SMS 送信ゲートウェイをインストールしたいマシンに sms ユーザを作成する必要があります。その後、//home/sms// および ///home/sms/incoming// ディレクトリを作成します。他のマシンから SMS 送信ゲートウェイを利用したい場合は、(NFS, SMB, SSH(scp), TCP や Tentacle 等の)何らかのファイル送信の仕組みで ///home/sms/incoming// ディレクトリにアクセスできる必要があります。
SMS 送信ゲートウェイの仕組みはとても簡単です。送信ファイルを ///home/sms/incoming// ディレクトリに置くだけで、SMS が処理されます。送信したファイルは削除されます。このファイルは特別なフォーマットになっており、以下の通りです。
Phonenumber|SMSText
==== Gnokii でのゲートウェイの実装 ====
\\
It is recommended to keep your systems updated with the [[:en:documentation:08_technical_reference:10_versions|latest version of Pandora FMS]]. **This information is kept for historical purposes**.\\
\\
[[:ja:documentation:08_technical_reference:10_versions|Pandora FMS の最新バージョン]] にシステムをアップデートすることをお勧めします。**ここに記載の内容は、過去の情報を保持するためものです。**
4つのスクリプトを作成する必要があります。
**SMS**: USBケーブルを通して Gnokii を使って SMS を送信するスクリプトです。スクリプトはゲートウェイとして送信するシステム(GSM携帯に接続したシステム)にのみ置きます。
**SMS_GATEWAY**: 送信待ちのファイルが置かれる入力ディレクトリ(///home/sms/incoming//)内のファイルを定期的に処理するスクリプトです。このスクリプトは、ゲートウェイとして送信するシステムにのみ設置します。
**SMS_GATEWAY_LAUNCHER**: SMS_GATEWAY スクリプトを起動するための(デーモンとして起動・停止する)スクリプトです。このスクリプトは、ゲートウェイとして送信するシステムにのみ設置します。
**COPY_SMS**: SMS を **scp** コマンドを使って、クライアントシステムからゲートウェイにコピーします。最初のパラメータとして、TELEPHONE を指定し、2番目に送信するテキストを指定します(各パラメータは、"" でくくります)。スクリプトは、転送のために sms ユーザでの ssh 無認証ログインを利用します。ローカルのシステムでは、scp を cp に置き換えたり、Tentacle などの転送プログラムを利用することもできます。
=== sms ===
\\
It is recommended to keep your systems updated with the [[:en:documentation:08_technical_reference:10_versions|latest version of Pandora FMS]]. **This information is kept for historical purposes**.\\
\\
[[:ja:documentation:08_technical_reference:10_versions|Pandora FMS の最新バージョン]] にシステムをアップデートすることをお勧めします。**ここに記載の内容は、過去の情報を保持するためものです。**
これは、Gnokii を使って SMS を送信するスクリプトです。(///etc/gnokii.conf// にて)設定済みの Gnokii が必要です。スクリプトは、//root// 権限で起動する必要がまります。または、gnokii バイナリで //SETUID// します。
#!/bin/bash
texto=$1
number=$2
if [ $# != 2 ]; then
echo "I need more parameters"
exit 1;
fi
/bin/echo $1 | /usr/local/bin/gnokii --sendsms $2
=== sms_gateway ===
\\
It is recommended to keep your systems updated with the [[:en:documentation:08_technical_reference:10_versions|latest version of Pandora FMS]]. **This information is kept for historical purposes**.\\
\\
[[:ja:documentation:08_technical_reference:10_versions|Pandora FMS の最新バージョン]] にシステムをアップデートすることをお勧めします。**ここに記載の内容は、過去の情報を保持するためものです。**
これはゲートウェイデーモンのスクリプトです。
#!/bin/bash
INCOMING_DIR=/home/sms/incoming
HOME_DIR=/home/sms
while [ 1 ]
do
for a in `ls $INCOMING_DIR`
do
if [ ! -z "$a" ]
then
NUMBER=`cat $INCOMING_DIR/$a | cut -d "|" -f 1`
MESSAGE=`cat $INCOMING_DIR/$a | cut -d "|" -f 2`
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
echo "$TIMESTAMP Sending to $NUMBER the message $MESSAGE" >> $HOME_DIR/sms_gateway.log
$HOME_DIR/sms "$MESSAGE" "$NUMBER"
echo "$TIMESTAMP Deleting $a" >> $HOME_DIR/sms_gateway.log
rm -Rf $INCOMING_DIR/$a
sleep 1
fi
done
sleep 5
done
=== sms_gateway_launcher ===
\\
It is recommended to keep your systems updated with the [[:en:documentation:08_technical_reference:10_versions|latest version of Pandora FMS]]. **This information is kept for historical purposes**.\\
\\
[[:ja:documentation:08_technical_reference:10_versions|Pandora FMS の最新バージョン]] にシステムをアップデートすることをお勧めします。**ここに記載の内容は、過去の情報を保持するためものです。**
This is the launching script form the ''sms_gateway'':
これは、''sms_gateway'' を起動するスクリプトです。
#!/bin/bash
# SMS Gateway, startup script
# Sancho Lerena,
# Linux Version (generic)
# Configurable path and filenames
SMS_GATEWAY_HOME=/home/sms
SMS_PID_DIR=/var/run
SMS_PID=/var/run/sms.pid
# Main script
if [ ! -d "$SMS_PID_DIR" ]
then
echo "SMS Gateway cannot write it's PID file in $SMS_PID_DIR. Please create directory or assign appropiate perms"
exit
fi
if [ ! -f $SMS_GATEWAY_HOME/sms_gateway ]
then
echo "SMS Gateway not found, please check setup and read manual"
exit
fi
case "$1" in
start)
OLD_PATH="`pwd`"
if [ -f $SMS_PID ]
then
CHECK_PID=`cat $SMS_PID`
CHECK_PID_RESULT=`ps aux | grep -v grep | grep "$CHECK_PID" | grep "sms_gateway" | wc -l`
if [ $CHECK_PID_RESULT == 1 ]
then
echo "SMS Gateway is currently running on this machine with PID ($CHECK_PID). Aborting now..."
exit
fi
fi
nohup $SMS_GATEWAY_HOME/sms_gateway > /dev/null 2> /dev/null & 2> /dev/null > /dev/null
sleep 1
MYPID=`ps aux | grep "$SMS_GATEWAY_HOME/sms_gateway" | grep -v grep | tail -1 | awk '{ print $2 }'`
if [ ! -z "$MYPID" ]
then
echo $MYPID > $SMS_PID
echo "SMS Gateway is now running with PID $MYPID"
else
echo "Cannot start SMS Gateway. Aborted."
fi
cd "$OLD_PATH"
;;
stop)
if [ -f $SMS_PID ]
then
echo "Stopping SMS Gateway"
PID_2=`cat $SMS_PID`
if [ ! -z "`ps -F -p $PID_2 | grep -v grep | grep 'sms_gateway' `" ]
then
kill `cat $SMS_PID` 2> /dev/null > /dev/null
else
echo "SMS Gateway is not executing with PID $PID_2, skip Killing step"
fi
rm -f $SMS_PID
else
echo "SMS Gateway is not running, cannot stop it."
fi
;;
force-reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: sms_gateway {start|stop|restart}"
exit 1
esac
=== copy_sms ===
\\
[[:ja:documentation:08_technical_reference:10_versions|Pandora FMS の最新バージョン]] にシステムをアップデートすることをお勧めします。**ここに記載の内容は、過去の情報を保持するためものです。**
これは、クライアントマシンで送信する SMS を作成し、SMS ゲートウェイへ scp を用いてコピーするスクリプトです。
#!/bin/bash
SERIAL=`date +"%j%M%s"`
SERIAL=`hostname`_$SERIAL
TEL=$1
TEXT=$2
echo $TEL\|$TEXT >> /tmp/$SERIAL
scp /tmp/$SERIAL sms@192.168.1.1:/home/sms/incoming
rm -Rf /tmp/$SERIAL1
===== OBSOLETE =====
==== Debian / Ubuntu ====
Debian/Ubuntu では、Pandora FMS が利用する sendsms スクリプトをカスタマイズする必要があります。
最初に APT リポジトリからパッケージをインストールします。
$ sudo apt-get install smstools
次に、コマンドラインから sms を送信するためのサンプルスクリプトをカスタマイズします。
cp /usr/share/doc/smstools/examples/scripts/sendsms /usr/bin
chmod 750 /usr/bin/sendsms
/usr/bin/sendsms を編集し、次の行をスクリプトの最後に追加します。
chmod 666 $FILE