snmpd.conf 設定方法 (拡張MIBファイルの導入方法)

スポンサーリンク

snmpの設定(snmp.conf)についてまとめます。snmp.confを適切に設定する事で、ベンダー固有のプライベートMIBを追加 (MIBをコンパイル) したり、コミュニティ名の指定など共通の設定を省略したりする事ができます。

混同しやい概念としてsnmpd, snmptrapdがありますが、これらとは異なる概念です。

net-snmp-utilsのインストール

snmp関連の動作確認を行うにはnet-snmp-utilsというパッケージが必要です。まずは、net-snmp-utilsをインストールします。このパッケージには、snmpwalk, snmptranslateなどのツール群が含まれています。

dnf install net-snmp-utils

プライベートMIBの追加 (MIBのコンパイル方法)

プライベートMIB追加の必要性

snmpは共通化された汎用的なOIDとベンダー固有のOIDが存在します。Cisco機器のCPU監視は、cpmCPUTotal5minRev (.1.3.6.1.4.1.9.9.109.1.1.1.1.8)を使用しますが、デフォルトの状態では名前を用いた監視ができません。

[root@sandbox03 ~]# snmpwalk -v 2c -c public 192.168.1.182 CISCO-PROCESS-MIB::cpmCPUTotal5minRev
MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs
Cannot find module (CISCO-PROCESS-MIB): At line 0 in (none)
CISCO-PROCESS-MIB::cpmCPUTotal5minRev: Unknown Object Identifier
[root@sandbox03 ~]# snmpwalk -v 2c -c public 192.168.1.182 .1.3.6.1.4.1.9.9.109.1.1.1.1.8
SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.8.1 = Gauge32: 4
[root@sandbox03 ~]# 

数値を指定して監視するのはメンテナンス性が下がりますので、名前で指定できるようにすると良いでしょう。

snmp.conf 設定

プライベートMIBを読み込めるようにするには、まずsnmp.confを編集する必要があります。snmp.confはSNMP関連のコマンドの共通設定を行うファイルで、システム全体に適用したいならば/etc/snmp/snmp.confを、ユーザ単位で適用したいならば~/.snmp/snmp.confを編集します。

今回はプライベートMIBの追加が目的ですので、システム全体に影響を与える/etc/snmp/snmp.confというファイルを以下のように新規作成します。(/etc/snmp/snmpd.confではない事に注意して下さい。)

# mkdir /etc/snmp/
# vi /etc/snmp/snmp.conf
MIBDIRS /usr/share/snmp/mibs:/usr/share/snmp/private-bims
MIBS all

MIBDIRSはMIB値を読み込むディレクトリの指定です。MIBDIRはデフォルトで/usr/share/snmp/mibs/を読み込む仕様になっており、MIBDIRSの設定変更は必須ではありません。もし、OSでデフォルトでインストールされているMIBと後から追加したMIBを区別できるようにしたいならば、MIBDIRSの設定を変更します。

MIBS allは読み込むMIBの指定です。デフォルトではOSでデフォルトでインストールされたMIB値しか読み込まないので、MIBS allと指定し全てのMIBを読み込むようにします。

プライベートMIBの追加例(1) Ciscoの場合

CiscoのプライベートMIBは「SNMP Object Navigator」というツールによって提供されています。以下のURLをブラウザに入力します。

 https://snmp.cloudapps.cisco.com/Support/SNMP/do/BrowseOID.do

cisco オブジェクトナビゲータ01

検索窓に名前解決したいOIDを入力して”Translate”ボタンを押下します。

cisco オブジェクトナビゲータ02

MIBと書かれた欄のリンクを押下します。

cisco オブジェクトナビゲータ03

お使いのsnmp versionのMIBファイルをダウンロードします。MIBファイルには依存関係が存在し、以下の場合は12個全てのMIBファイルが必要となります。なお、SNMPv2-SMIのようなOSにデフォルトでインストールされているMIBファイルはダウンロードを省略して差し支えございません。

cisco オブジェクトナビゲータ04

MIBファイルをダウンロードし、MIBDIRSで指定したディレクトリに配置します。このシナリオでは、デフォルトでインストールされたMIBファイルと区別するために、/usr/share/snmp/private-bims/にMIBファイルを配置します。

mkdir /usr/share/snmp/private-bims
cd /usr/share/snmp/private-bims
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-PROCESS-MIB.my
wget ftp://ftp.cisco.com/pub/mibs/v2/SNMP-FRAMEWORK-MIB.my
wget ftp://ftp.cisco.com/pub/mibs/v2/HCNUM-TC.my
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-TC.my
wget ftp://ftp.cisco.com/pub/mibs/v2/CISCO-SMI.my

snmptranslateコマンドを用いて名前解決ができるようになった事を確認します。

[root@sandbox03 ~]# snmptranslate .1.3.6.1.4.1.9.9.109.1.1.1.1.8
CISCO-PROCESS-MIB::cpmCPUTotal5minRev
[root@sandbox03 ~]# 

名前による監視ができるようになった事を確認します。

[root@sandbox03 ~]# snmpwalk -v 2c -c public 192.168.1.182 CISCO-PROCESS-MIB::cpmCPUTotal5minRev
CISCO-PROCESS-MIB::cpmCPUTotal5minRev.1 = Gauge32: 3 percent
[root@sandbox03 ~]# 

プライベートMIBの追加例(2) BIG-IPの場合

BIG-IPの場合は製品内にMIBファイルが梱包されています。トップページ(Statistics >> Welcom)の右下あたりにMIBファイルのダウンロードリンクがあります。「mibs_f5.tar」はF5独自の拡張mibで、「mibs_netsnmp.tar」は拡張mibが必要とする標準mibです。多くのLinuxディストリビューションの場合、「mibs_netsnmp.tar」に格納された標準mibはデフォルトでインストール済となっています。

F5 BIGファイルのダウンロード

「mibs_netsnmp.tar」をダウンロードし、MIBDIRSで指定したディレクトリに配置します。

tar xvf mibs_f5.tar
mv mibs_f5/* /usr/share/snmp/private-bims/

snmptranslateコマンドを用いて名前解決ができるようになった事を確認します。

[root@sandbox03 ~]# snmptranslate -On F5-BIGIP-LOCAL-MIB::ltmPools
.1.3.6.1.4.1.3375.2.2.5
[root@sandbox03 ~]# 

名前による監視ができるようになった事を確認します。

[root@sandbox03 ~]# snmpwalk -v 2c -c public 192.168.1.161 F5-BIGIP-LOCAL-MIB::ltmPools
F5-BIGIP-LOCAL-MIB::ltmPoolNumber.0 = INTEGER: 0
F5-BIGIP-LOCAL-MIB::ltmPoolStatResetStats.0 = INTEGER: 0
F5-BIGIP-LOCAL-MIB::ltmPoolStatNumber.0 = INTEGER: 0
F5-BIGIP-LOCAL-MIB::ltmPoolMemberNumber.0 = INTEGER: 0
F5-BIGIP-LOCAL-MIB::ltmPoolMemberStatResetStats.0 = INTEGER: 0
F5-BIGIP-LOCAL-MIB::ltmPoolMemberStatNumber.0 = INTEGER: 0
F5-BIGIP-LOCAL-MIB::ltmPoolStatusNumber.0 = INTEGER: 0
F5-BIGIP-LOCAL-MIB::ltmPoolMbrStatusNumber.0 = INTEGER: 0
[root@sandbox03 ~]#

Tips

snmp.conf(5), snmpcmd(1)

snmp.confのマニュアルの読み方を説明します。

/etc/snmp/snmp.confの仕様を調べるために、”man 5 snmp.conf”を読んでみましょう。システム全体に対する設定は/etc/snmp/snmp.confに記述し、ユーザ固有の設定は~/.snmp/snmp.confに記述する必要がある事が分かりました。MIBの取扱については、mibdirs, mibsなどの指定が可能である事が分かります。mibsの仕様に関しては、snmpcmd(1)の-mオプションを参照しろとの事です。

# man 5 snmp.conf

SNMP.CONF(5)                       Net-SNMP                       SNMP.CONF(5)

NAME
       snmp.conf - configuration files for the Net-SNMP applications

DESCRIPTION
       Applications  built  using  the Net-SNMP libraries typically use one or
       more configuration files to control various aspects of their operation.
       These  files  (snmp.conf  and snmp.local.conf) can be located in one of
       several locations, as described in the snmp_config(5) manual page.

       In particular, /etc/snmp/snmp.conf is a  common  file,  containing  the
       settings  shared  by  all  users of the system.  ~/.snmp/snmp.conf is a
       personal file, with the settings specific to a particular user.

 <omitted>

MIB HANDLING
       mibdirs DIRLIST
              specifies a list of directories to search for MIB  files.   This
              operates  in  the same way as the -M option - see snmpcmd(1) for
              details.  Note that this value can be overridden by the  MIBDIRS
              environment variable, and the -M option.

       mibs MIBLIST
              specifies  a  list  of  MIB  modules  (not files) that should be
              loaded.  This operates in the same way as the -m  option  -  see
              snmpcmd(1)  for  details.  Note that this list can be overridden
              by the MIBS environment variable, and the -m option.

”man 1 snmpcmf”を読んでみましょう。snmpcmdはsnmpwalk, snmptrapなどのSNMP関連コマンドのオプションの説明をするマニュアルです。-mオプションを見ると、MIBLISTを明示指定しない場合は、デフォルトのMIBリストが適用されるようです。MIBLISTにALLを指定すれば、全てのMIBモジュールが読み込まれるようになります。

# man 1 snmpcmf

SNMPCMD(1)                         Net-SNMP                         SNMPCMD(1)

NAME
       snmpcmd - options and behaviour common to most of the Net-SNMP command-line tools

SYNOPSIS
       snmpcmd [OPTIONS] AGENT [PARAMETERS]

DESCRIPTION
       This  manual  page  describes  the  common  options  for the SNMP commands: snmpbulkget, snmpbulkwalk, snmpdelta,
       snmpget, snmpgetnext, snmpnetstat, snmpset, snmpstatus, snmptable, snmptest, snmptrap,  snmpdf, snmpusm  ,  snmp-
       walk  .   The command line applications use the SNMP protocol to communicate with an SNMP capable network entity,
       an agent.  Individual applications typically (but not necessarily) take  additional  parameters  that  are  given
       after the agent specification.  These parameters are documented in the manual pages for each application.

OPTIONS

 <omitted>

       -m MIBLIST
              Specifies a colon separated list of MIB modules (not files) to load for this application.  This  overrides
              (or  augments) the environment variable MIBS, the snmp.conf directive mibs, and the list of MIBs hardcoded
              into the Net-SNMP library.

              If MIBLIST has a leading ’-’ or ’+’ character, then the MIB modules listed are loaded in addition  to  the
              default  list,  coming  before  or after this list respectively.  Otherwise, the specified MIBs are loaded
              instead of this default list.

              The special keyword ALL is used to load all MIB modules in the MIB  directory  search  list.   Every  file
              whose name does not begin with "." will be parsed as if it were a MIB file.

デフォルト設定 コミュニティ名 snmpバージョン

/etc/snmp/snmp.confはsnmpコマンドのデフォルト挙動を定義する事ができます。例えば、/etc/snmp/snmp.confに以下のようにコミュニティ名とバージョンを設定すると、snmpコマンド実行時のコミュニティ名, バージョン指定を省略する事ができます。

# vi /etc/snmp/snmp.conf

MIBDIRS /usr/share/snmp/mibs:/usr/share/snmp/private-bims
MIBS all
defCommunity public
defVersion 2c

コミュニティ名, バージョン指定を省略してsnmpコマンドを実行できる事を確認します。

[root@localhost ~]# snmpwalk localhost
SNMPv2-MIB::sysDescr.0 = STRING: Linux vps096.changineer.info 2.6.32-431.1.2.0.1.el6.x86_64 #1 SMP Fri Dec 13 13:06:13 UTC 2013 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-TC::linux
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2534433) 7:02:24.33
SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhos> (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: vps096.changineer.info
SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDMIBObjects.3.1.1
SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance</pre>

 <omitted>

タイトルとURLをコピーしました