ブログ

Armadillo-IoTでSNMPエージェントを使う

at_mangetsu
2015年9月29日 19時49分

Armadillo-IoTでSNMPを使いたい場合に、
SNMPエージェントをArmadillo-IoT上で動かす方法を紹介します。


1.ATDE5をダウンロード

開発環境ATDE5を以下からダウンロードします。

i386向け

http://armadillo.atmark-techno.com/files/downloads/atde/atde5-i386-20150727.tar.xz

amd64向け

http://armadillo.atmark-techno.com/files/downloads/atde/atde5-amd64-20150727.tar.xz

ATDE5のインストールや起動方法は以下を参照してください。

第2章 Windows上にATDEを構築する

2.ソースコードをダウンロード

2.1 ATDE5上でソースコードをダウンロードします。

atmark@atde5:~$ wget http://armadillo.atmark-techno.com/files/downloads/armadillo-iot/source/dist/atmark-dist-20150918.tar.gz
atmark@atde5:~$ wget http://armadillo.atmark-techno.com/files/downloads/armadillo-iot/source/kernel/linux-3.14-at3.tar.gz

2.2 ソースコードを展開します。

atmark@atde5:~$ tar zxf atmark-dist-20150918.tar.gz 
atmark@atde5:~$ tar zxf linux-3.14-at3.tar.gz 
atmark@atde5:~$ ln -s atmark-dist-20150918 atmark-dist
atmark@atde5:~$ cd atmark-dist
atmark@atde5:~/atmark-dist$ ln -s ../linux-3.14-at3 ./linux-3.x

3.Perl5ビルド準備

SNMPエージェントの動作にはPerlが必要となります。
Perlのインストールについては、以下ブログを参照いただければと思います。

Armadillo-420でPerl5を使う
https://users.atmark-techno.com/blog/1562/1595

※上記ブログではカーネル2.6を使っていますが、カーネル3.14でも手順は同じです。

4.SNMPエージェントの準備

SNMPエージェント(以下、実行ファイルであるsnmpdと表記します)を準備します。

4.1 一旦ホームディレクトリに戻ります。

atmark@atde5:~$ cd

4.2 snmpdディレクトリを作成し、カレントディレクトリをsnmpdディレクトリに移動します。

atmark@atde5:~$ mkdir snmpd
atmark@atde5:~$ cd snmpd

4.3 romfsディレクトリを作成します。

atmark@atde5:~/snmpd$ mkdir romfs

4.4 snmpdに必要なパッケージをダウンロードします。

必要なパッケージは以下となります。

snmpd (5.4.3~dfsg-2.8+deb7u1)
https://packages.debian.org/ja/wheezy/snmpd
http://ftp.jp.debian.org/debian/pool/main/n/net-snmp/snmpd_5.4.3~dfsg-2.8+deb7u1_armel.deb

libsnmp15 (5.4.3~dfsg-2.8+deb7u1)
https://packages.debian.org/ja/wheezy/libsnmp15
http://ftp.jp.debian.org/debian/pool/main/n/net-snmp/libsnmp15_5.4.3~dfsg-2.8+deb7u1_armel.deb

libsensors4 (1:3.3.2-2+deb7u1)
https://packages.debian.org/ja/wheezy/libsensors4
http://ftp.jp.debian.org/debian/pool/main/l/lm-sensors/libsensors4_3.3.2-2+deb7u1_armel.deb

libsnmp-base (5.4.3~dfsg-2.8+deb7u1)
https://packages.debian.org/ja/wheezy/libsnmp-base
http://ftp.jp.debian.org/debian/pool/main/n/net-snmp/libsnmp-base_5.4.3~dfsg-2.8+deb7u1_all.deb

libwrap0 (7.6.q-24)
https://packages.debian.org/ja/wheezy/libwrap0
http://ftp.jp.debian.org/debian/pool/main/t/tcp-wrappers/libwrap0_7.6.q-24_armel.deb
atmark@atde5:~/snmpd$ wget http://ftp.jp.debian.org/debian/pool/main/n/net-snmp/snmpd_5.4.3~dfsg-2.8+deb7u1_armel.deb
atmark@atde5:~/snmpd$ wget http://ftp.jp.debian.org/debian/pool/main/n/net-snmp/libsnmp15_5.4.3~dfsg-2.8+deb7u1_armel.deb
atmark@atde5:~/snmpd$ wget http://ftp.jp.debian.org/debian/pool/main/l/lm-sensors/libsensors4_3.3.2-2+deb7u1_armel.deb
atmark@atde5:~/snmpd$ wget http://ftp.jp.debian.org/debian/pool/main/n/net-snmp/libsnmp-base_5.4.3~dfsg-2.8+deb7u1_all.deb
atmark@atde5:~/snmpd$ wget http://ftp.jp.debian.org/debian/pool/main/t/tcp-wrappers/libwrap0_7.6.q-24_armel.deb

4.5 ダウンロードしたパッケージをromfsディレクトリに展開します。

atmark@atde5:~/snmpd$ dpkg-deb -x libsensors4_3.3.2-2+deb7u1_armel.deb ./romfs/
atmark@atde5:~/snmpd$ dpkg-deb -x libsnmp-base_5.4.3~dfsg-2.8+deb7u1_all.deb ./romfs/
atmark@atde5:~/snmpd$ dpkg-deb -x libsnmp15_5.4.3~dfsg-2.8+deb7u1_armel.deb ./romfs/
atmark@atde5:~/snmpd$ dpkg-deb -x snmpd_5.4.3~dfsg-2.8+deb7u1_armel.deb ./romfs/
atmark@atde5:~/snmpd$ dpkg-deb -x libwrap0_7.6.q-24_armel.deb ./romfs/

4.6 不要なファイルを削除します。

atmark@atde5:~/snmpd$ rm -rf romfs/usr/share/doc

4.7 romfs/etc/snmp/snmpd.confを以下のように編集します。

atmark@atde5:~/snmpd$ vi romfs/etc/snmp/snmpd.conf

snmpd.confの内容:

--------------------------------------------------
  1 ###############################################################################
  2 #
  3 # EXAMPLE.conf:
  4 #   An example configuration file for configuring the Net-SNMP agent ('snmpd')
  5 #   See the 'snmpd.conf(5)' man page for details
  6 #
  7 #  Some entries are deliberately commented out, and will need to be explicitly activate
  8 #
  9 ###############################################################################
 10 #
 11 #  AGENT BEHAVIOUR
 12 #
 13 
 14 #  Listen for connections from the local system only
 15 #agentAddress  udp:127.0.0.1:161     # この行をコメントアウトします
 16 #  Listen for connections on all interfaces (both IPv4 *and* IPv6)
 17 agentAddress udp:161,udp6:[::1]:161  # この行のコメントアウトを解除します。
--------------------------------------------------

4.8 romfsディレクトリを圧縮します。

atmark@atde5:~/snmpd$ tar zcf romfs-add-snmpd.tar.gz romfs

5 ユーザーランドにsnmpdを含める

5.1 カレントディレクトリをatmark-distに移動します。

atmark@atde5:~/snmpd$ cd ~/atmark-dist-20150918

5.2 4.8項で作成したromfs-add-snmpd.tar.gzをマージします。

atmark@atde5:~/atmark-dist-20150918$ tar zxf ../snmpd/romfs-add-snmpd.tar.gz

5.3 ビルドします。

atmark@atde5:~/atmark-dist-20150918$ make image

6 snmpd起動

Armadillo-IoT起動後に、以下のコマンドを実行します。

[root@armadillo-iotg (ttymxc1) ~]# /usr/sbin/snmpd

7 ATDE側から動作確認する

7.1 ATDEにSNMPマネージャーをインストールします。

atmark@atde5:~$ sudo apt-get install snmp snmp-mib-downloader

7.2 /etc/snmp/snmp.confを以下のように編集します。

atmark@atde5:~$ sudo vi /etc/snmp/snmp.conf

/etc/snmp/snmp.confの内容:

--------------------------------------------------
#
# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loaging them by commenting out the following line.
#mibs :  #この行をコメントアウトします。
--------------------------------------------------

7.3 MIBをダウンロードします。

atmark@atde5:~$ download-mibs

7.4 snmpgetでMIB情報を取得してみます。

atmark@atde5:~$ snmpget -v 1 -c public 192.168.11.118 system.sysName.0
SNMPv2-MIB::sysName.0 = STRING: armadillo-iotg
atmark@atde5:~$ snmpget -v 1 -c public 192.168.11.118 system.sysDescr.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux armadillo-iotg 3.14.36-at2 #5 PREEMPT Tue Sep 29 16:44:09 JST 2015 armv5tejl