0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

snmpsimを使用して環境構築 (1)

Last updated at Posted at 2025-05-01

はじめに

SNMP 入門のための環境構築」では、実際のSNMP環境を作りましたが、今回はテスト用にエミュレート環境を作ります。
SNMPデバイスをエミュレートするためにsnmpsimを使用します。

環境構築

1. SNMP関連アプリインストール

sudo apt install snmp

3. Python環境の準備

python --version

必要に応じて仮想環境を作成します。

python -m venv snmpsim-env
source snmpsim-env/bin/activate  # Windowsの場合は `snmpsim-env\Scripts\activate`

4. snmpsimのインストール

pip install snmpsim

参考に、現在のインストール状況を確認します

pip list
Package            Version
------------------ ---------
certifi            2025.4.26
cffi               1.17.1
charset-normalizer 3.4.1
cryptography       44.0.2
idna               3.10
Jinja2             3.1.6
MarkupSafe         3.0.2
pip                24.0
ply                3.11
pyasn1             0.6.1
pycparser          2.22
pysmi              1.6.1
pysnmp             6.2.6
pysnmpcrypto       0.0.4
requests           2.32.3
snmpsim            1.1.7
urllib3            2.4.0

5. サンプルデータ作成

5.1. SNMPSIMのデータディレクトリを作成

mkdir snmpsim-data

5.2. SNMPSIMのデータフォーマットに関して

サンプルデータのフォーマットは以下を参照して下さい。

5.3. snmprecファイルの作成

先程のページを参考にデータファイルを作成します。

snmpsim-data/public.snmprec
# sysDescr: A textual description of the entity.
1.3.6.1.2.1.1.1.0|4|Simulated SNMPv2-MIB::sysDescr
# sysObjectID: The vendor's authoritative identification of the network management subsystem.
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.8072.3.2.10
# sysUpTime: The time since the network management portion of the system was last re-initialized.
1.3.6.1.2.1.1.3.0|67|123456789
# sysContact: The contact information for the administrator.
1.3.6.1.2.1.1.4.0|4|admin@example.com
# sysName: An administratively-assigned name for this managed node.
1.3.6.1.2.1.1.5.0|4|SimulatedDevice
# sysLocation: The physical location of this node.
1.3.6.1.2.1.1.6.0|4|DataCenter
# ifIndex: A unique value for each interface.
1.3.6.1.2.1.2.2.1.1.1|2|1
#
# 5 - NULL
1.3.6.1.2.1.2.2.1.4.1|5|
# 64 - IpAddress
1.3.6.1.2.1.2.2.1.5.1|64|192.168.64.1
# 65 - Counter32
1.3.6.1.2.1.2.2.1.6.1|65|12345
# 66 - Gauge32
1.3.6.1.2.1.2.2.1.6.1|66|100000000
# 67 - TimeTicks
1.3.6.1.2.1.2.2.1.6.1|67|987654321
# 68 - Opaque
1.3.6.1.2.1.2.2.1.6.1|68|200000000
# 70 - Counter64
1.3.6.1.2.1.2.2.1.6.1|79|300000000

5.4. snmprecファイルの動作確認

SNMPを起動してみる

snmpsim-command-responder-lite --data-dir=./snmpsim-data --agent-udpv4-endpoint=0.0.0.0:10161

ポート番号161は管理者権限が必要

読み出してみる

snmpwalk -v2c -c public 127.0.0.1:10161 iso
$ snmpwalk -v2c  -c public 127.0.0.1:10161 iso
iso.3.6.1.2.1.1.1.0 = STRING: "Simulated SNMPv2-MIB::sysDescr"
iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.8072.3.2.10
iso.3.6.1.2.1.1.3.0 = Timeticks: (123456789) 14 days, 6:56:07.89
iso.3.6.1.2.1.1.4.0 = STRING: "admin@example.com"
iso.3.6.1.2.1.1.5.0 = STRING: "SimulatedDevice"
iso.3.6.1.2.1.1.6.0 = STRING: "DataCenter"
iso.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
iso.3.6.1.2.1.2.2.1.4.1 = NULL
iso.3.6.1.2.1.2.2.1.5.1 = IpAddress: 192.168.64.1
iso.3.6.1.2.1.2.2.1.6.1 = Counter32: 12345
iso.3.6.1.2.1.2.2.1.6.1 = No more variables left in this MIB View (It is past the end of the MIB tree)

固定値のみであれば、これでテストできるようになりました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?