はじめに
OpenBlocks A6
監視アプリにはNagiosを使用し、

A6のGPIOについて
GPIOとはGeneral Purpose Input/
次項より、
Marvell 88F6283のGPIO
A6のCPUは、
GPIOコネクタのピン配置
A6は背面

番号 | ピン名 | 番号 | ピン名 |
---|---|---|---|
1 | +3. | 2 | +3. |
3 | GND | 4 | GND |
5 | GPIO24 | 6 | GPIO25 |
7 | GPIO26 | 8 | GPIO27 |
9 | GPIO28 | 10 | GPIO29 |
11 | GPIO30 | 12 | GPIO31 |
13 | +3. | 14 | - |
15 | GND | 16 | - |
GPIOの操作方法
Linuxでは、

A6におけるGPIOへの操作手順を説明しましょう。まず、
# cd /sys/class/gpio/ # ls -F export gpiochip0@ unexport
exportファイルに、
# echo 24 > export # ls -F export gpio24@ gpiochip0@ unexport # cd gpio24 # ls -F direction subsystem@ uevent value
directionファイルでは入力/
# cd gpio24 # cat direction in # echo out > direction # cat direction out # cat value 1 # echo 0 > value # cat value 0
監視システムの構築
今回の監視システムでは、
監視システムの構成
システムの構成を図5に示します。NagiosがHTTPサーバの停止を検知した場合、

パトランプ基板の説明
パトランプ基板は、

番号 | ピン名 | 機能 | 出力方向 | valueファイルの値 |
---|---|---|---|---|
5 | GPIO24 | パトランプ、 | out | ON=0、 |
8 | GPIO27 | パトランプの光り方 | out | 点滅=0、 |
9 | GPIO28 | プッシュスイッチ | in | ON=1、 |
A6の設定
A6のOSはDebian 6.
SSDをext3でフォーマットして、
# fdisk /dev/sda # mke2fs -j -b 4096 -L DEBIAN /dev/sda1 # reboot
OpenBlocksシリーズは、
# e2label /dev/sda1 DEBIAN # df -h Filesystem Size Used Avail Use% Mounted on /dev/ram0 124M 90M 29M 76% / udev 10M 88K 10M 1% /dev tmpfs 64M 4.0K 64M 1% /dev/shm /dev/sda1 14G 455M 13G 4% /.rw unionfs 14G 455M 13G 4% /etc unionfs 14G 455M 13G 4% /bin unionfs 14G 455M 13G 4% /home unionfs 14G 455M 13G 4% /lib unionfs 14G 455M 13G 4% /sbin unionfs 14G 455M 13G 4% /usr unionfs 14G 455M 13G 4% /var unionfs 14G 455M 13G 4% /root unionfs 14G 455M 13G 4% /opt unionfs 14G 455M 13G 4% /srv unionfs 14G 455M 13G 4% /media
# aptittude install nagios3
Nagiosの設定
HTTPサーバの追加とパトランプを点灯する設定を行います。その他はデフォルトの設定を使用します。
ホストの登録
/etc/
define host{
use generic-host ; Name of host template to use
host_name obs600web
alias obs600web
address 172.16.12.101
}
HTTPサービスの追加
/etc/
define hostgroup {
hostgroup_name http-servers
alias HTTP servers
members localhost*,obs600web*
}
パトランプ制御スクリプトの登録
/etc/
define command{
command_name notify-service-by-beacon
command_line /usr/local/bin/obsa6_beacon.sh $SERVICESTATE$
}
通知コマンドの追加
/etc/
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*,notify-service-by-beacon*
host_notification_commands notify-host-by-email
email root@localhost
}
制御スクリプトの説明
制御スクリプトはNagiosから起動され、
パトランプ制御スクリプト
引数のHTTPサーバのステータス
#!/bin/sh
SYSFS_GPIO=/sys/class/gpio
if [ ! -f $SYSFS_GPIO/gpio27 ]; then ……(1)
echo 27 > $SYSFS_GPIO/export
echo out > $SYSFS_GPIO/gpio27/direction
fi
if [ ! -f $SYSFS_GPIO/gpio24 ]; then ……(2)
echo 24 > $SYSFS_GPIO/export
echo out > $SYSFS_GPIO/gpio24/direction
fi
# Patlamp ON
if [ "$1" = "CRITICAL" ]; then
echo 0 > $SYSFS_GPIO/gpio27/value ……(3)
echo 0 > $SYSFS_GPIO/gpio24/value ……(4)
# Patlamp OFF
elif [ "$1" = "OK" ]; then
echo 1 > $SYSFS_GPIO/gpio24/value ……(5)
else
echo parameter error
fi
リスト5の
プッシュスイッチ検出スクリプト
1秒ごとにプッシュボタンをチェックして、
#! /bin/sh
SYSFS_GPIO=/sys/class/gpio
while :
do
# initialize
if [ ! -f $SYSFS_GPIO/gpio28 ]; then ……(1)
echo 28 > $SYSFS_GPIO/export
echo in > $SYSFS_GPIO/gpio28/direction
fi
var=`tr -d '\n' < $SYSFS_GPIO/gpio28/value` ……(2)
if [ "$var" != "0" ]; then ……(3)
if [ ! -f $SYSFS_GPIO/gpio24 ]; then ……(4)
echo 24 > $SYSFS_GPIO/export
echo out > $SYSFS_GPIO/gpio24/direction
fi
echo 1 > $SYSFS_GPIO/gpio24/value ……(5)
fi
sleep 1
done
リスト6の
動作確認
動作確認はHTTPサーバのHTTPサービスを手動で停止して確認します。HTTPサーバのマシンは起動しているが、
HTTPサーバの停止
HTTPサーバを停止する前に、
# /etc/init.d/nagios3 restart # /usr/local/bin/obsa6_pushsw.sh &
そのあと、
# /etc/init.d/apache2 stop
HTTPサーバの異常検出
Nagiosはデフォルト設定で5分間隔で状態のチェックを行います。異常を確認すると1分間隔でチェックを行い、
図12はNagiosのログです。5行目でnotify-service-by-beaconが通知されています。パトランプが点灯した瞬間が写真3です。Nagiosのデフォルトの設定では、
[1346303726] SERVICE ALERT: obs600web;HTTP;CRITICAL;SOFT;1;Connection refused [1346303786] SERVICE ALERT: obs600web;HTTP;CRITICAL;SOFT;2;Connection refused [1346303846] SERVICE ALERT: obs600web;HTTP;CRITICAL;SOFT;3;Connection refused [1346303906] SERVICE ALERT: obs600web;HTTP;CRITICAL;HARD;4;Connection refused [1346303906] SERVICE NOTIFICATION: root;obs600web;HTTP;CRITICAL;notify-service-by-beacon;Connection refused [1346303906] SERVICE NOTIFICATION: root;obs600web;HTTP;CRITICAL;notify-service-by-email;Connection refused

おわりに
A6のGPIOは、
- 参考文献
- Nagios 3翻訳プロジェクト
URL:http://nagios. x-trans. jp/ nagios/ index. php
The Linux Kernel Archives
URL:http://www.kernel.org/doc/Documentation/gpio.txt