LoginSignup
26
48

More than 3 years have passed since last update.

WindowsでのSNMPお勉強メモ

Last updated at Posted at 2019-04-24

はじめに

WindowsでのSNMPについてのお勉強メモです。

:o:以下のことが書いてあります:o:

  • Net-SNMPのインストール方法
  • サービス(SNMPエージェントサービス、SNMPトラップハンドラサービス)のこと
  • コマンド(snmpget、snmpwalk、snmptrap)のこと
  • TWSNMPのこと

:x:以下のことは書いていません:x:

  • SNMP v3 のこと
  • パケット構造

環境

環境を用意するのが面倒なので1台のPCでお勉強しています。

  • OS=Windows10 Pro 1809 (64bit)
  • Tool
    • Net-SNMP(5.6.1.1-1.x86)
    • TWSNMP(Ver 4.11.7)

◆SNMPとは

Simple Network Management Protocol
ルータ、スイッチ、サーバなどTCP/IPネットワークに接続された通信機器に対し、ネットワーク経由で監視、制御するためのアプリケーション層プロトコル。

  • UDPで通信する。
  • 機器の状態を管理・表示する側を「SNMPマネージャ」
  • 機器の状態をSNMPマネージャに送信する側を「SNMPエージェント」
  • SNMPマネージャからSNMPエージェントに状態問合せする通信と、SNMPエージェントから発報(トラップ)する通信がある。

◆Net-SNMPとは

  • http://www.net-snmp.org/
  • SNMPプロトコルを実装したOSS。
  • SNMPエージェント、SNMPトラップ送信・受信の機能がある。
  • CLIコマンドで問い合わせ、送信・受信を行う。
  • SNMPエージェントはWindowsサービス、実行しているPCの状態を監視することができる。
  • SNMPトラップはWindowsサービス、SNMPエージェントからの通知(トラップ)を受け取る。
  • 上記サービスとお話するための問合せ、トラップ送信コマンドが用意されている。

◆Net-SNMPのインストール

1)ダウンロード

net-snmp-5.6.1.1-1.x86.exeココのSourceっていうリンクからDLします。
※Windowsのx64インストーラーはあまり更新されていないらしく、ココからDLできます。
※今回の環境はPCは64ビットですが、x86版のNet-SNMPを使っています。インストール時に警告がでるだけで、普通に動いています。

Memo
こんなことが書いてありました。どんな風に失敗するのかは未確認。

IMPORTANT NOTE FOR WINDOWS USERS: the Net-SNMP Windows binaries have been built >with OpenSSL version 0.9.8r. Since the OpenSSL 0.9 and 1.0 DLLs are incompatible, >any attempt to install Net-SNMP on a system where OpenSSL 1.0 has been installed >will fail.

Windowsユーザへの重要な注意:Net-SNMP WindowsバイナリはOpenSSLバージョン0.9.8rで構築されています。 OpenSSL 0.9と1.0のDLLは互換性がないため、OpenSSL 1.0がインストールされているシステムにNet-SNMPをインストールしようとしても失敗します。

image.png

2)インストール

net-snmp-5.6.1.1-1.x86.exe をダブルクリックしてインストールします。
「x64のインストーラを使ったほうがいいぞ」的なワーニングが出ますが、そのままOKで閉じて、Next->Nextでインストールしてしまいます。
インストールフォルダがc:\usrっていうところが気に入らないのですが、仕方ない(変えないほうがいい)です。

3)snmpd.confファイルを作成

設定ファイルは自分で作らないといけないです。ヘルプにサンプルがあるのですが、めんどくさいのでここに晒します。
このテキストをsnmpd.confというファイル名でC:\usr\etc\snmpフォルダに保存します。
注意:このフォルダにはsnmp.confというファイルが既にあると思います。これを上書きするのではなく、snmpd.confというファイル名で別のファイルを作成してください。snmp.confを上書きしないように注意しましょう

snmpd.confはココを開いて見てください
snmpd.conf
## Of the following Net-SNMP agent features
## NONE are supported on Net-SNMP-5.1.1 Win32 platforms
## Process checks "proc" config token
## Executable scripts "exec" config token
## Disk checks "disk" config token
## Load average checks "load" config token
## Extensible sections "exec" config token with shelltest
## Pass-through control "pass" config token


###############################################################################
#
# EXAMPLE.conf:
# An example configuration file for configuring the ucd-snmp snmpd agent.
#
###############################################################################
#
# This file is intended to only be an example. If, however, you want
# to use it, it should be placed in c:/usr-mingw/etc/share/snmp/snmpd.conf.
# When the snmpd agent starts up, this is where it will look for it.
#
# You might be interested in generating your own snmpd.conf file using
# the "snmpconf" program (perl script) instead. It's a nice menu
# based interface to writing well commented configuration files. Try it!
#
# Note: This file is automatically generated from EXAMPLE.conf.def.
# Do NOT read the EXAMPLE.conf.def file! Instead, after you have run
# configure & make, and then make sure you read the EXAMPLE.conf file
# instead, as it will tailor itself to your configuration.


# All lines beginning with a '#' are comments and are intended for you
# to read. All other lines are configuration commands for the agent.


#
# PLEASE: read the snmpd.conf(5) manual page as well!
#


###############################################################################
# Access Control
###############################################################################


# YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
# KNOWN AT YOUR SITE. YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO
# SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.


# By far, the most common question I get about the agent is "why won't
# it work?", when really it should be "how do I configure the agent to
# allow me to access it?"
#
# By default, the agent responds to the "public" community for read
# only access, if run out of the box without any configuration file in
# place. The following examples show you other ways of configuring
# the agent so that you can change the community names, and give
# yourself write access as well.
#
# The following lines change the access permissions of the agent so
# that the COMMUNITY string provides read-only access to your entire
# NETWORK (EG: 10.10.10.0/24), and read/write access to only the
# localhost (127.0.0.1, not its real ipaddress).
#
# For more information, read the FAQ as well as the snmpd.conf(5)
# manual page.


####
# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):


# sec.name source community
com2sec local localhost public
#com2sec mynetwork 0.0.0.0/0 public この書き方じゃダメ
com2sec mynetwork default public


####
# Second, map the security names into group names:


# sec.model sec.name
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork


####
# Third, create a view for us to let the groups have rights to:


# incl/excl subtree mask
view all included .1 80


####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:


# context sec.model sec.level match read write notif
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none


# -----------------------------------------------------------------------------


###############################################################################
# System contact information
#


# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file. **PLEASE NOTE** that setting
# the value of these objects here makes these objects READ-ONLY
# (regardless of any access control settings). Any attempt to set the
# value of an object whose value is given here will fail with an error
# status of notWritable.


syslocation Right here, right now.
syscontact Me <me@somewhere.org>


# Example output of snmpwalk:
# % snmpwalk -v 1 -c public localhost system
# system.sysDescr.0 = "Windows NT 2000 SP4"
# system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.win32
# system.sysUpTime.0 = Timeticks: (595637548) 68 days, 22:32:55
# system.sysContact.0 = "Me <me@somewhere.org>"
# system.sysName.0 = "name"
# system.sysLocation.0 = "Right here, right now."
# system.sysServices.0 = 72


# -----------------------------------------------------------------------------


###############################################################################
# Subagent control
#


# The agent can support subagents using a number of extension mechanisms.
# From the 4.2.1 release, AgentX support is being compiled in by default.
# However, this is still experimental code, so should not be used on
# critical production systems.
# Please see the file README.agentx for more details.
#
# If having read, marked, learnt and inwardly digested this information,
# you decide that you do wish to make use of this mechanism, simply
# uncomment the following directive.
#
# master agentx
#
# I repeat - this is *NOT* regarded as suitable for front-line production
# systems, though it is probably stable enough for day-to-day use.
# Probably.
#
# No refunds will be given.


###############################################################################
# Further Information
#
# See the snmpd.conf manual page, and the output of "snmpd -H".
# MUCH more can be done with the snmpd.conf than is shown as an
# example here.

4)SNMPエージェントのアクティベーション

インストーラでインストールするのにアクティベーションは手動なのね。
(Windowsサービスとして登録して起動する手順です)

C:\usr\registeragent.bat
管理者として実行すればおk

そのままサービスも起動してしまいましょう。
[コントロールパネル]->[すべてのコントロール パネル項目]->[管理ツール]->[サービス]
Net-SNMP Agentを右クリックで「開始!」します。

image.png

※ちなみにC:\usr\logにログが出力されているのでなんかおかしい時は見てみましょう。

5)SNMPエージェントサービスが起動しないとき

私はここでハマったのですが、なんかエラーが出てNet-SNMPエージェントサービスが起動しませんでした。
よく見ると、自分のPCですでにWindows標準のSNMPエージェントが動いていました。
Windows標準のSNMPエージェントを止めたらNet-SNMPエージェントサービスが無事起動するようになりました。

  • [設定]->[アプリ]->[アプリと機能]にある[オプション機能の管理]->[オプション機能]にある[機能の追加]->[簡易ネットワーク管理プロトコル (SNMP)]でWindows標準のヤツがいる場合は無効化します。
  • サービスでSNMPサービス,SNMPトラップが実行中であれば、STOP&無効化してください。
  • これらの設定を変えた場合Windowsの再起動をしておいた方がいいです。

image.png

6)SNMPエージェントの動作確認

コマンドプロンプトから以下のsnmpgetを実行してホスト名が返ってくればOK

動作確認
C:\work>snmpget -v 2c -c public 127.0.0.1 .1.3.6.1.2.1.1.5.0
SNMPv2-MIB::sysName.0 = STRING: gebo-pc

◆問合せコマンド

Net-SNMPエージェントが無事起動したらコマンドプロンプトからコマンドを実行してエージェントさんとお話することができます。
エージェントさんは実行しているPCのステータスを監視していて、コマンドで問い合わせすると答えてくれます。

コマンド - snmpget

SNMPエージェントに問い合わせして、値をGETする。

snmpget -v SNMPバージョン -c コミュニティ名 AGENT OID ...

USAGE詳細
snmpget_usage
USAGE: snmpget [OPTIONS] AGENT OID [OID]...

  Version:  5.6.1.1
  Web:      http://www.net-snmp.org/
  Email:    net-snmp-coders@lists.sourceforge.net

OPTIONS:
  -h, --help            display this help message
  -H                    display configuration file directives understood
  -v 1|2c|3             specifies SNMP version to use
  -V, --version         display package version number
SNMP Version 1 or 2c specific
  -c COMMUNITY          set the community string
SNMP Version 3 specific
  -a PROTOCOL           set authentication protocol (MD5|SHA)
  -A PASSPHRASE         set authentication protocol pass phrase
  -e ENGINE-ID          set security engine ID (e.g. 800000020109840301)
  -E ENGINE-ID          set context engine ID (e.g. 800000020109840301)
  -l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)
  -n CONTEXT            set context name (e.g. bridge1)
  -u USER-NAME          set security name (e.g. bert)
  -x PROTOCOL           set privacy protocol (DES)
  -X PASSPHRASE         set privacy protocol pass phrase
  -Z BOOTS,TIME         set destination engine boots/time
General communication options
  -r RETRIES            set the number of retries
  -t TIMEOUT            set the request timeout (in seconds)
Debugging
  -d                    dump input/output packets in hexadecimal
  -D[TOKEN[,...]]       turn on debugging output for the specified TOKENs
                           (ALL gives extremely verbose debugging output)
General options
  -m MIB[:...]          load given list of MIBs (ALL loads everything)
  -M DIR[:...]          look in given list of directories for MIBs
    (default: C:/usr/share/snmp/mibs)
  -P MIBOPTS            Toggle various defaults controlling MIB parsing:
                          u:  allow the use of underlines in MIB symbols
                          c:  disallow the use of "--" to terminate comments
                          d:  save the DESCRIPTIONs of the MIB objects
                          e:  disable errors when MIB symbols conflict
                          w:  enable warnings when MIB symbols conflict
                          W:  enable detailed warnings when MIB symbols conflict
                          R:  replace MIB symbols from latest module
  -O OUTOPTS            Toggle various defaults controlling output display:
                          0:  print leading 0 for single-digit hex characters
                          a:  print all strings in ascii format
                          b:  do not break OID indexes down
                          e:  print enums numerically
                          E:  escape quotes in string indices
                          f:  print full OIDs on output
                          n:  print OIDs numerically
                          q:  quick print for easier parsing
                          Q:  quick print with equal-signs
                          s:  print only last symbolic element of OID
                          S:  print MIB module-id plus last element
                          t:  print timeticks unparsed as numeric integers
                          T:  print human-readable text along with hex strings
                          u:  print OIDs using UCD-style prefix suppression
                          U:  don't print units
                          v:  print values only (not OID = value)
                          x:  print all strings in hex format
                          X:  extended index format
  -I INOPTS             Toggle various defaults controlling input parsing:
                          b:  do best/regex matching to find a MIB node
                          h:  don't apply DISPLAY-HINTs
                          r:  do not check values for range/type legality
                          R:  do random access to OID labels
                          u:  top-level OIDs must have '.' prefix (UCD-style)
                          s SUFFIX:  Append all textual OIDs with SUFFIX before parsing
                          S PREFIX:  Prepend all textual OIDs with PREFIX before parsing
  -L LOGOPTS            Toggle various defaults controlling logging:
                          e:           log to standard error
                          o:           log to standard output
                          n:           don't log at all
                          f file:      log to the specified file
                          s facility:  log to syslog (via the specified facility)

                          (variants)
                          [EON] pri:   log to standard error, output or /dev/null for level 'pri' and above
                          [EON] p1-p2: log to standard error, output or /dev/null for levels 'p1' to 'p2'
                          [FS] pri token:    log to file/syslog for level 'pri' and above
                          [FS] p1-p2 token:  log to file/syslog for levels 'p1' to 'p2'
  -C APPOPTS            Set various application specific behaviours:
                          f:  do not fix errors and retry the request

引数 説明
-v SNMPプロトコルバージョン 1,2c,3のいずれかを指定する
-c コミュニティ名 とりあえず public と指定しとけばOk
AGENT 問い合わせ先エージェントのIPアドレス
OID 問い合わせ取得したいOID .1.3.6...のような数値指定とsysNameのような文字列指定が可能
snmpget
// 自分自身(127.0.0.1)のSNMPエージェントに対して問い合わせする。
// OIDは .1.3.6.1.2.1.1.5.0 で sysName(ホスト名) という意味。
C:\work>snmpget -v 2c -c public 127.0.0.1 .1.3.6.1.2.1.1.5.0

// hostnameが返ってくる
SNMPv2-MIB::sysName.0 = STRING: gebo-pc


// 自分自身(127.0.0.1)のSNMPエージェントに対して問い合わせする。
// OIDは .1.3.6.1.2.1.1.1.0 で sysDescr(機種情報) という意味。
C:\work>snmpget -v 2c -c public 127.0.0.1 sysDescr

// 機種情報が返ってくる
SNMPv2-MIB::sysDescr.0 = STRING: Windows gebo-pc 6.2.9200   Professional Intel64 Family 6 Model 69 Stepping 1

コマンド - snmpwalk

SNMPエージェントに問い合わせして、監視対象で利用できるOIDの一覧を取得するコマンド。
snmpgetだとOIDを指定して一つの項目の値をGETするのですが、このコマンドだと取得可能な値をすべて一気にGETできる便利コマンドです。

snmpwalk -v SNMPバージョン -c コミュニティ名 AGENT

USAGE
snmpwalk_usage
USAGE: snmpwalk [OPTIONS] AGENT [OID]

  Version:  5.6.1.1
  Web:      http://www.net-snmp.org/
  Email:    net-snmp-coders@lists.sourceforge.net

OPTIONS:
  -h, --help            display this help message
  -H                    display configuration file directives understood
  -v 1|2c|3             specifies SNMP version to use
  -V, --version         display package version number
SNMP Version 1 or 2c specific
  -c COMMUNITY          set the community string
SNMP Version 3 specific
  -a PROTOCOL           set authentication protocol (MD5|SHA)
  -A PASSPHRASE         set authentication protocol pass phrase
  -e ENGINE-ID          set security engine ID (e.g. 800000020109840301)
  -E ENGINE-ID          set context engine ID (e.g. 800000020109840301)
  -l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)
  -n CONTEXT            set context name (e.g. bridge1)
  -u USER-NAME          set security name (e.g. bert)
  -x PROTOCOL           set privacy protocol (DES)
  -X PASSPHRASE         set privacy protocol pass phrase
  -Z BOOTS,TIME         set destination engine boots/time
General communication options
  -r RETRIES            set the number of retries
  -t TIMEOUT            set the request timeout (in seconds)
Debugging
  -d                    dump input/output packets in hexadecimal
  -D[TOKEN[,...]]       turn on debugging output for the specified TOKENs
                           (ALL gives extremely verbose debugging output)
General options
  -m MIB[:...]          load given list of MIBs (ALL loads everything)
  -M DIR[:...]          look in given list of directories for MIBs
    (default: C:/usr/share/snmp/mibs)
  -P MIBOPTS            Toggle various defaults controlling MIB parsing:
                          u:  allow the use of underlines in MIB symbols
                          c:  disallow the use of "--" to terminate comments
                          d:  save the DESCRIPTIONs of the MIB objects
                          e:  disable errors when MIB symbols conflict
                          w:  enable warnings when MIB symbols conflict
                          W:  enable detailed warnings when MIB symbols conflict
                          R:  replace MIB symbols from latest module
  -O OUTOPTS            Toggle various defaults controlling output display:
                          0:  print leading 0 for single-digit hex characters
                          a:  print all strings in ascii format
                          b:  do not break OID indexes down
                          e:  print enums numerically
                          E:  escape quotes in string indices
                          f:  print full OIDs on output
                          n:  print OIDs numerically
                          q:  quick print for easier parsing
                          Q:  quick print with equal-signs
                          s:  print only last symbolic element of OID
                          S:  print MIB module-id plus last element
                          t:  print timeticks unparsed as numeric integers
                          T:  print human-readable text along with hex strings
                          u:  print OIDs using UCD-style prefix suppression
                          U:  don't print units
                          v:  print values only (not OID = value)
                          x:  print all strings in hex format
                          X:  extended index format
  -I INOPTS             Toggle various defaults controlling input parsing:
                          b:  do best/regex matching to find a MIB node
                          h:  don't apply DISPLAY-HINTs
                          r:  do not check values for range/type legality
                          R:  do random access to OID labels
                          u:  top-level OIDs must have '.' prefix (UCD-style)
                          s SUFFIX:  Append all textual OIDs with SUFFIX before parsing
                          S PREFIX:  Prepend all textual OIDs with PREFIX before parsing
  -L LOGOPTS            Toggle various defaults controlling logging:
                          e:           log to standard error
                          o:           log to standard output
                          n:           don't log at all
                          f file:      log to the specified file
                          s facility:  log to syslog (via the specified facility)

                          (variants)
                          [EON] pri:   log to standard error, output or /dev/null for level 'pri' and above
                          [EON] p1-p2: log to standard error, output or /dev/null for levels 'p1' to 'p2'
                          [FS] pri token:    log to file/syslog for level 'pri' and above
                          [FS] p1-p2 token:  log to file/syslog for levels 'p1' to 'p2'
  -C APPOPTS            Set various application specific behaviours:
                          p:  print the number of variables found
                          i:  include given OID in the search range
                          I:  don't include the given OID, even if no results are returned
                          c:  do not check returned OIDs are increasing
                          t:  Display wall-clock time to complete the request
                          E {OID}:  End the walk at the specified OID

指定値 説明
-v SNMPプロトコルバージョン 1,2c,3のいずれかを指定する
-c コミュニティ名 public と指定しとけばOk
AGENT 問い合わせ先エージェントのIPアドレス
snmpwalk
// 自分自身(127.0.0.1)のSNMPエージェントに対して問い合わせする。
// 結果をoidlist.txtにエクスポートする。
C:\work>snmpwalk -v 2c -c public 127.0.0.1 > oidlist.txt

◆Net-SNMP Trap Handlerのアクティベーション

トラップを受け取る機能も手動でアクティベーションしないといけません。
SNMPエージェントと大体同じでサービス登録して起動するだけです。

1)snmptrapd.confファイルを作成

例によって設定ファイルは自分で作らないといけません。
以下のテキストをsnmptrapd.confというファイル名でC:\usr\etc\snmpフォルダに保存します。

snmptrapd.conf
# 受信するUDPポート
snmpTrapdAddr udp:162
snmpTrapdAddr udp6:10162

# トラップ受信許可の設定
#  authCommunity   TYPES COMMUNITY  [SOURCE [OID | -v VIEW ]]
#   TYPES
#     log ログ出力を許可します。ファイル出力、標準出力、エラー出力、syslogなどが該当します。
#     execute プログラムの実行を許可します。例えば、メール転送を行うtraptoemailなどのperlスクリプト等が該当します。
#     net 他のsnmptrapdサーバへの転送を許可します。
authCommunity log,execute,net public

2)Net-SNMP Trap Handlerをサービス登録する

  • C:\usr\registertrapd.bat管理者として実行します。
  • [コントロールパネル]->[すべてのコントロール パネル項目]->[管理ツール]->[サービス] あたりからNet-SNMP Trap Handlerを右クリックで「開始!」します。

◆トラップ送信

トラップ=発報、とか、通知とかいう意味です。
snmptrapコマンドでTrapを送信し、Net-SNMP Trap Handlerサービスがそれを受信します。

注意-snmptrap.exeはWindows標準にも存在する

snmptrapコマンド(snmptrap.exe)はWindows標準にも存在します。
NetSNMPとは別のモノなので、注意しないとハマります。
C:\Windows\System32\snmptrap.exe
System32は標準PATHに含まれているんで、通常コマンドプロンプトからsnmptrapコマンド実行するとWindows標準のsnmptrap.exeが実行されてしまいます。
Net-SNMPのsnmptrapコマンドを実行する場合は、
C:\usr\bin\snmptrap.exe
とパス込みで指定して実行するようにしましょう。

コマンド - snmptrap

snmptrapはSNMPプロトコルv1とv2cでパケット構造がだいぶ異なっていて、実行するときに与える引数も変わっているのでそれぞれ説明します。
v3の説明はしません。

USAGE
snmptrap_usage

USAGE: snmptrap [OPTIONS] AGENT TRAP-PARAMETERS

  Version:  5.6.1.1
  Web:      http://www.net-snmp.org/
  Email:    net-snmp-coders@lists.sourceforge.net

OPTIONS:
  -h, --help            display this help message
  -H                    display configuration file directives understood
  -v 1|2c|3             specifies SNMP version to use
  -V, --version         display package version number
SNMP Version 1 or 2c specific
  -c COMMUNITY          set the community string
SNMP Version 3 specific
  -a PROTOCOL           set authentication protocol (MD5|SHA)
  -A PASSPHRASE         set authentication protocol pass phrase
  -e ENGINE-ID          set security engine ID (e.g. 800000020109840301)
  -E ENGINE-ID          set context engine ID (e.g. 800000020109840301)
  -l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)
  -n CONTEXT            set context name (e.g. bridge1)
  -u USER-NAME          set security name (e.g. bert)
  -x PROTOCOL           set privacy protocol (DES)
  -X PASSPHRASE         set privacy protocol pass phrase
  -Z BOOTS,TIME         set destination engine boots/time
General communication options
  -r RETRIES            set the number of retries
  -t TIMEOUT            set the request timeout (in seconds)
Debugging
  -d                    dump input/output packets in hexadecimal
  -D[TOKEN[,...]]       turn on debugging output for the specified TOKENs
                           (ALL gives extremely verbose debugging output)
General options
  -m MIB[:...]          load given list of MIBs (ALL loads everything)
  -M DIR[:...]          look in given list of directories for MIBs
    (default: C:/usr/share/snmp/mibs)
  -P MIBOPTS            Toggle various defaults controlling MIB parsing:
                          u:  allow the use of underlines in MIB symbols
                          c:  disallow the use of "--" to terminate comments
                          d:  save the DESCRIPTIONs of the MIB objects
                          e:  disable errors when MIB symbols conflict
                          w:  enable warnings when MIB symbols conflict
                          W:  enable detailed warnings when MIB symbols conflict
                          R:  replace MIB symbols from latest module
  -O OUTOPTS            Toggle various defaults controlling output display:
                          0:  print leading 0 for single-digit hex characters
                          a:  print all strings in ascii format
                          b:  do not break OID indexes down
                          e:  print enums numerically
                          E:  escape quotes in string indices
                          f:  print full OIDs on output
                          n:  print OIDs numerically
                          q:  quick print for easier parsing
                          Q:  quick print with equal-signs
                          s:  print only last symbolic element of OID
                          S:  print MIB module-id plus last element
                          t:  print timeticks unparsed as numeric integers
                          T:  print human-readable text along with hex strings
                          u:  print OIDs using UCD-style prefix suppression
                          U:  don't print units
                          v:  print values only (not OID = value)
                          x:  print all strings in hex format
                          X:  extended index format
  -I INOPTS             Toggle various defaults controlling input parsing:
                          b:  do best/regex matching to find a MIB node
                          h:  don't apply DISPLAY-HINTs
                          r:  do not check values for range/type legality
                          R:  do random access to OID labels
                          u:  top-level OIDs must have '.' prefix (UCD-style)
                          s SUFFIX:  Append all textual OIDs with SUFFIX before parsing
                          S PREFIX:  Prepend all textual OIDs with PREFIX before parsing
  -L LOGOPTS            Toggle various defaults controlling logging:
                          e:           log to standard error
                          o:           log to standard output
                          n:           don't log at all
                          f file:      log to the specified file
                          s facility:  log to syslog (via the specified facility)

                          (variants)
                          [EON] pri:   log to standard error, output or /dev/null for level 'pri' and above
                          [EON] p1-p2: log to standard error, output or /dev/null for levels 'p1' to 'p2'
                          [FS] pri token:    log to file/syslog for level 'pri' and above
                          [FS] p1-p2 token:  log to file/syslog for levels 'p1' to 'p2'
  -C APPOPTS            Set various application specific behaviour:
                          i:  send an INFORM instead of a TRAP

  -v 1 TRAP-PARAMETERS:
         enterprise-oid agent trap-type specific-type uptime [OID TYPE VALUE]...
  or
  -v 2 TRAP-PARAMETERS:
         uptime trapoid [OID TYPE VALUE] ...

snmptrap v1 の場合

引数がやたら多いです。送信元のOIDとかIPを指定できるのが便利なところかもしれません。

snmptrap -v 1 -c コミュニティ名 AGENT 
enterprise-oid agent trap-type specific-type uptime [OID TYPE VALUE]...
指定値 説明
-c コミュニティ名 public と指定しとけばOk
AGENT トラップ送信先のIPアドレス
enterprise-oid トラップ送信元の識別情報。送信元のsysObjectIDの値を指定すればOK
agent ※↑のAGENTとは異なる※ トラップ送信元のIPアドレス
trap-type トラップの種類を指定する(0~6) ※trap-type参照
specific-type トラップ詳細タイプコード
uptime 時刻. ""とすると省略(時刻未設定)
[OID TYPE VALUE] トラップデータ ※TYPE参照

※trap-type

trap-type name 意味
0 ColdStart 再起動が発生した発報
1 WarmStart 初期化が発生した発報
2 LinkDown 機器がダウンした発報
3 LinkUp 機器がアップ(?)した発報
4 AuthenticationFailure 認証エラー(?)発報
5 EgpNeighborLoss 近接ルータダウン発報
6 EnterpriseSpecific 固有定義の発報

※TYPE

TYPE 説明
u UNSIGNED
s STRING
x HEX STRING
d DECIMAL STRING
n NULLOBJ
o OBJID
t TIMETICKS
a IPADDRESS
b BITS
snmptrap
// 自分自身にトラップを発報する
// enterprise-oid=netSnmpAgentOIDs.13
// trap-type=6(EnterpriseSpecific)
// specific-type=99
// [OID TYPE VALUE] = netSnmpExperimental.1 s "hogehoge1"
// [OID TYPE VALUE] = netSnmpExperimental.2 s "hogehoge2"
C:\usr\bin>snmptrap -v 1 -c public 192.168.1.101 netSnmpAgentOIDs.13 192.168.1.100 6 99 '' netSnmpExperimental.1 s "hogehoge1" netSnmpExperimental.2 s "hogehoge2"

C:\usr\bin>type C:\usr\log\snmptrapd.log
NET-SNMP version 5.6.1.1
2019-04-23 12:27:58 192.168.1.100(via UDP: [192.168.1.101]:64713->[0.0.0.0]:0) TRAP, SNMP v1, community public
    NET-SNMP-MIB::netSnmpAgentOIDs.13 Enterprise Specific Trap (99) Uptime: 0:00:00.00
    NET-SNMP-MIB::netSnmpExperimental.1 = STRING: "hogehoge1"   NET-SNMP-MIB::netSnmpExperimental.2 = STRING: "hogehoge2"

snmptrap v2c の場合

snmptrap -v 2c -c コミュニティ名 AGENT uptime trapoid [OID TYPE VALUE] ...
指定値 説明
-c コミュニティ名 public と指定しとけばOk
AGENT Trap送信先のIPアドレス
uptime 時刻. ""とすると現在時刻?
trapoid トラップのOID
[OID TYPE VALUE] トラップデータ. 書き方はsnmptrap v1と同じ
snmptrap
// 自分自身にトラップを発報する
// trapoid = netSnmpExperimental
// [OID TYPE VALUE] = netSnmpExperimental.1 s "hogehoge1"
// [OID TYPE VALUE] = netSnmpExperimental.2 s "hogehoge2"
C:\usr\bin>snmptrap -v 2c -c public 127.0.0.1 '' netSnmpExperimental netSnmpExperimental.1 s "hogehoge1" netSnmpExperimental.2 s "hogehoge2"

C:\usr\bin>type C:\usr\log\snmptrapd.log
NET-SNMP version 5.6.1.1
2019-04-23 12:52:34 gebo-pc [UDP: [127.0.0.1]:53988->[0.0.0.0]:0]:
SNMPv2-MIB::snmpTrapOID.0 = OID: NET-SNMP-MIB::netSnmpExperimental  NET-SNMP-MIB::netSnmpExperimental.1 = STRING: "hogehoge1"   NET-SNMP-MIB::netSnmpExperimental.2 = STRING: "hogehoge2"

◆SNMPマネージャツールを使ってみる

Net-SNMP Trap Handlerサービスでトラップを受信してみましたが、なんかつまらないですね。
TWSNMPというSNMPマネージャツールを使うとGUIで確認することができます。

ここではざっくり手順を説明します。

1)Net-SNMP Trap Handlerサービスを止める

これからインストールするTWSNMPでトラップするので、今動いているNet-SNMP Trap Handlerサービスは停止しときましょう。

2)TWSNMPをインストール

http://www.twise.co.jp/twsnmp.htmlからTWSNMPV4.msiをDLします。
image.png

DLしたMSIファイルを実行してインストールします。

3)TWSNMPを起動

「管理MAP」というアイコンがスタートメニューに増えると思うので、それがTWSNMPです。起動します。

4)自動登録

[メニュー] -> [管理ツール(T)] -> [自動発見]で監視可能なものを勝手に検索します。
(PING応答があるものを全て監視対象にするようです)

5)MAPプロパティ設定

[メニュー] -> [編集(E)] -> [MAPプロパティ]を設定します。
- [SNMPモード]をお好みで設定します。
- [TRAPポート]を162にします。(必須)
image.png

6)TRAP受信

snmptrap コマンドでTRAP送信すると、TWSNMPで受信してログにでます。
これでも地味・・・
image.png

おつかれさまでした

trapコマンド複雑すぎる・・・

参考

26
48
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
48