★まずはお勉強
●SNMPの大きな機能
①情報の要求と応答(get-request)
マネージャからエージェントに監視対象機器の情報を要求します。
エージェントは要求された情報を取得してマネージャに応答します。
②情報の設定要求と応答(set-request)
マネージャからエージェントに監視対象機器の設定変更を要求します。
エージェントは要求された設定変更を実行し、結果をマネージャに応答します。
③状態変化の通知(Trap)
※今回は、get-requestが実装できればいいわなと
★やってみる
①net-snmpのインストール
yum -y install net-snmp
※落とす場合はここから
http://www.net-snmp.org/
net-snmp-5.5.tar.gz
②SNMPDデーモンの起動
③/usr/src/net-snmp-5.5/perl/SNMP/examples
を実行しようとしたら、SNMP.pmがないとのことなので
※参考http://hata.cc/msql/index.htm
②CPANからSNMPを導入
SNMP-5.0401.tar.gz
こちらのMAKEでもmake: net-snmp-config: コマンドが見つかりませんでしたがでるので
③yum install net-snmp-devel
※参考:http://d.hatena.ne.jp/taslam/20080422/1208834598
④もういっかい
エラー
# perl Makefile.PL
Writing Makefile for SNMP
ERROR:
Net-SNMP installed version: 5.3.2.2 => 5.03022
Perl Module Version: 5.0401
These versions must match for perfect support of the module. It is possible
that different versions may work together, but it is strongly recommended
that you make these two versions identical. You can get the Net-SNMP
source code and the associated perl modules directly from
http://www.net-snmp.org/
If you want to continue anyway please set the NETSNMP_DONT_CHECK_VERSION
environmental variable to 1 and re-run the Makefile.PL script.
バージョンがおかしい?
# rpm -qa | grep snmp
net-snmp-libs-5.3.2.2-7.el5_4.2
net-snmp-devel-5.3.2.2-7.el5_4.2
net-snmp-5.3.2.2-7.el5_4.2
⑤こいつがないからっぽい?
yum install net-snmp-perl
ついでに、こいつも
yum -y install net-snmp-utils
# rpm -qa | grep snmp
net-snmp-utils-5.3.2.2-7.el5_4.2
net-snmp-perl-5.3.2.2-7.el5_4.2
net-snmp-libs-5.3.2.2-7.el5_4.2
net-snmp-devel-5.3.2.2-7.el5_4.2
net-snmp-5.3.2.2-7.el5_4.2
参考:http://fedorasrv.com/bbshtml/webpatio/3353.shtml
参考:http://blog.goo.ne.jp/oracool/e/7c5b78dc8ba4ec092c3dbc0f72e8853e
⑥もういっかいサンプル実行。いったっぽい
/usr/src/net-snmp-5.5/perl/SNMP/examples
perl mibwalk.pl localhost public
※、SNMPは個別にCPANからインストールする必要はないっぽい?
⑦snmpd.conf ・・・ エージェント側の設定ファイルの設定
※今回はエージェントも同じホスト。
snmpd.conf ファイルは:snmpd デーモンが参照するファイル
・マネージャの定義
・マネージャに対し参照できるMIBの範囲を定義
・およびMIBによるTrapのエージェント先を定義
ファイルのパスはこちら
/usr/share/snmp/snmpd.conf
⑧マネージャとして動作確認
snmppgetで情報取得 → OK
$ snmpget -v 1 -c localcom 127.0.0.1 .1.3.6.1.2.1.1.5.0
SNMPv2-MIB::sysName.0 = STRING: ホスト名
localcom・・・エージェント側で定義したコミュニティ名
localhost ・・・ エージェント側のホスト名IPアドレス
1.3.6.1.2.1.2.2.1.10.2 ・・・OID
参考:
http://www.atmarkit.co.jp/flinux/rensai/root08/root08b.html
OIDくわしい
http://journal.mycom.co.jp/column/yetanother/081/index.html
Net::SNMPについてモジュール説明
http://fleur.hio.jp/perldoc/mix/lib/Net/SNMP.html
http://fleur.hio.jp/perldoc/mix/lib/Net/SNMP.pod
Net::SNMPTIPS(TRAPだけど)
http://www.arbolbell.jp/perl/2007/12/netsnmp-trap-perlsnmptrap.html
●サンプル実行
エラー
Net::SNMPがひつようらしい
●Net::SNMPをインストール
# perl Makefile.PL
Checking if your kit is complete...
Looks good
Warning: prerequisite Crypt::DES 2.03 not found.
Writing Makefile for Net::SNMP
とりあえずむしで。 ※あとで確認
●サンプル実行 → できた!!
#!/usr/bin/perl
use Net::SNMP;
my ( $session, $error ) = Net::SNMP->session(
-hostname => "localhost",
-community => "localcom",
-port => 161
);
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit 1;
}
my $oid = ".1.3.6.1.2.1.1.5.0";
my $result = $session->get_request(
-varbindlist => [$oid]
);
if (!defined($result)) {
printf("ERROR: %s.\n", $session->error);
$session->close;
exit 1;
}
printf("hostname for host '%s' is %s\n",
$session->hostname, $result->{$oid}
);
$session->close;
結果
hostname for host 'localhost' is ホスト名
これでSNMPまわりはのりきれそう。
0 件のコメント:
コメントを投稿