14
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

snmp使ってみた

Last updated at Posted at 2015-12-13

参考

インストール

Ubuntuの場合
apt-get install -y snmpd
apt-get install -y snmp snmp-mibs-downloader
CentOSの場合
sudo yum install net-snmp-utils

SNMP値取得

/etc/snmp/snmpd.conf
- rocommunity public  default    -V systemonly
+ rocommunity public  default
SNMP値全取得
snmpwalk -v1 localhost -c public
結果
iso.3.6.1.2.1.1.1.0 = STRING: "Linux debsrv1 4.2.3-2-pve #1 SMP Sun Nov 15 16:08:19 CET 2015 x86_64"
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: (48332) 0:08:03.32
iso.3.6.1.2.1.1.4.0 = STRING: "Me <me@example.org>"
iso.3.6.1.2.1.1.5.0 = STRING: "debsrv1"
iso.3.6.1.2.1.1.6.0 = STRING: "Sitting on the Dock of the Bay"
iso.3.6.1.2.1.1.7.0 = INTEGER: 72
iso.3.6.1.2.1.1.8.0 = Timeticks: (0) 0:00:00.00
...()
特定のMIB値だけ取得
$ snmpwalk -v1 localhost -c public iso.3.6.1.2.1.25.1.1.0 
iso.3.6.1.2.1.25.1.1.0 = Timeticks: (51977649) 6 days, 0:22:56.49
snmpstatus
$ snmpstatus -v 1 -c public localhost
[UDP: [127.0.0.1]:161->[0.0.0.0]:40345]=>[Linux debsrv1 4.2.3-2-pve #1 SMP Sun Nov 15 16:08:19 CET 2015 x86_64] Up: 1:18:36.91
Interfaces: 3, Recv/Trans packets: 14747404/9752459 | IP: 8961633/9364840
1 interface is down!

他のサーバから取得可能にする

/etc/snmp/snmpd.conf
- agentAddress  udp:127.0.0.1:161
+ agentAddress  udp:161
他のサーバから取得
snmpwalk -v1 debsrv1 -c public UCD-SNMP-MIB::laTable
snmpwalk -v1 debsrv1 -c public UCD-SNMP-MIB::memory
snmpwalk -v1 debsrv1 -c public UCD-SNMP-MIB::dskTable

.をつけると全取得できる

$ snmpwalk -v1 windesk1 -c public | wc -l 
3320
$ snmpwalk -v1 windesk1 -c public .| wc -l
3673

windowsのSNMP値を取得

snmp1.png

Ubuntuから実施
snmpwalk -v1 192.168.0.64 -c public
結果
iso.3.6.1.2.1.1.1.0 = STRING: "Hardware: x86 Family 15 Model 6 Stepping 1 AT/AT COMPATIBLE 
- Software: Windows Version 6.1 (Build 7601 Multiprocessor Free)"
iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.311.1.1.3.1.1
iso.3.6.1.2.1.1.3.0 = Timeticks: (78696420) 9 days, 2:36:04.20
iso.3.6.1.2.1.1.4.0 = ""
iso.3.6.1.2.1.1.5.0 = STRING: "windesk1"
iso.3.6.1.2.1.1.6.0 = ""
iso.3.6.1.2.1.1.7.0 = INTEGER: 76
iso.3.6.1.2.1.2.1.0 = INTEGER: 21
...()
  • DISKの空き容量や、uptimeもこれで取得できますね。

YamahaルータのSNMP

Yamahaルータで実施
snmp host 192.168.0.64 public
192.168.0.64から実施
snmpwalk -v1 192.168.0.1 -c public
config取得
snmpwalk -v1 192.168.0.1 -c public \
  iso.3.6.1.4.1.1182.2.2.10.1.2
IP一覧取得(OIDで取得)
snmpwalk -On \
  -v1 192.168.0.1 -c public \
  .1.3.6.1.2.1.4.22.1.3.1

Mib browser


Mib

load average

1.3.6.1.4.1.2021.10.1.3
snmpwalk -v1 localhost -c public 1.3.6.1.4.1.2021.10.1.3
iso.3.6.1.4.1.2021.10.1.3.1 = STRING: "0.07" # 1分
iso.3.6.1.4.1.2021.10.1.3.2 = STRING: "0.21" # 5分
iso.3.6.1.4.1.2021.10.1.3.3 = STRING: "0.22" # 15分

プロセス数

  • .1.3.6.1.4.1.2021.2.1を参照する。
/etc/snmp/snmpd.conf
+ proc  apache2
成功例
$ snmpwalk -v1 -c public localhost .1.3.6.1.4.1.2021.2.1 | grep 4\ 
...
iso.3.6.1.4.1.2021.2.1.5.4 = INTEGER: 11
...
失敗例
$ snmpwalk -v1 -c public localhost .1.3.6.1.4.1.2021.2.1 | grep 4\ 
...
iso.3.6.1.4.1.2021.2.1.101.4 = STRING: "No httpd process running"
...
14
20
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
14
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?