SNMPTrapReceive - acromusashi/acromusashi-stream-example GitHub Wiki

SNMPTrap 受信

本ページではSNMPTrap受信機能の利用方法について説明します。

処理内容

本機能は以下のフローで動作します。

  1. SNMPTrapを受信します。
  2. 受信したSNMPTrapをSnmpParserを用いてXML形式に変換します。
  3. XML形式のSNMPTrapをJSON形式に変換します。
  4. JSON形式のSNMPTrapをKestrelに投入します。
  5. KestrelからKestrelSpoutを用いてJSON形式のSNMPTrapを取得します。
  6. ConsolePrintBoltを用いて結果をログに出力します。

準備

SNMPTrap受信を動作させるためには以下の準備が必要です。

  • Step1: 必要となるミドルウェアのインストール
  • Step2: SNMPTrap受信プロセスの展開
  • Step3: SNMPTrap受信プロセスの設定
  • Step4: SNMPTrap受信Topologyのデプロイ
  • Step5: SNMPTrap受信Topologyの設定

Step1: 必要となるミドルウェアのインストール

下記の手順を確認し、必要ミドルウェアのインストールを行います。

Step2: SNMPTrap受信プロセスの展開

/opt 配下にacromusashi-stream-example.zipを配置し、下記のコマンドを実行して展開します。

unzip acromusashi-stream-example.zip
mv acromusashi-stream-example-x.x.x acromusashi-stream-example

Step3: SNMPTrap受信プロセスの設定

/opt/acromusashi-stream-example/conf/camel-context-example-snmp_kestrel.xml を下記のように設定します。

<route>
	<!-- Set Host for CamelProcess -->
	<from uri="snmp:__CAMEL_HOST__:162?type=TRAP" />  <!-- __CAMEL_HOST__をSNMPTrapを受信しますホストの値に修正 -->
	<bean ref="SnmpParser" method="parseSNMP" />
	<marshal ref="xmljson" />
	<!-- Set Kestrel Host -->
	<to uri="kestrel://__KESTREL_HOST__:__KESTREL_PORT__/MessageQueue" />  <!-- Kestrelの投入先ホスト/ポートを指定 -->
</route>

Step4: SNMPTrap受信Topologyのデプロイ

Step2: acromusashi-stream-exampleのデプロイ を参照し、Topologyのデプロイを行います。

Step5: SNMPTrap受信Topologyの設定

Nimbusをインストールしたサーバの/opt/storm/conf 配下にLocalConsolePrintTopology.yamlを配置し、下記(★項目)の設定を行います。

## LocalConsolePrintTopology Sample Config
## NimbusHost
## Set StormCluster's Nimbus Host
nimbus.host        : __NIMBUS_HOST__  ## ★Nimbusのホストを(例:nimbushost)★  
## NimbusPort
nimbus.thrift.port : 6627
## WorkerProcess Number
topology.workers   : 2
## Storm Debug Flag
topology.debug     : false

## TopologyDefine
## Set Kestrel Host:Port List
Kestrel.Hosts              : 
  - __KESTREL_HOST1__:__KESTREL_PORT1__  ## ★Kestrelのホスト:Kestrelのポートを設定(例:kestrelserver1:2229)★  
  - __KESTREL_HOST2__:__KESTREL_PORT2__ ## ★Kestrelのホスト:Kestrelのポートを設定(例:kestrelserver2:2229)★  

Kestrel.QueueName          : MessageQueue  ## ★Kestrelのキュー名称(例:MessageQueue)★  
KestrelSpout.Parallelism   : 1
ConsolePrintBolt.Parallelism : 2

実行

SNMPTrap受信は下記の手順で起動します。

  • Step1: SNMPTrap受信プロセスの起動
  • Step2: SNMPTrap受信Topologyの起動
  • Step3: SNMPTrap受信Topologyの終了
  • Step4: SNMPTrap受信プロセスの終了

Step1: SNMPTrap受信プロセスの起動

SNMPTrap受信プロセスインストールサーバにログインし、下記のコマンドを実行してSNMPTrap受信プロセスを起動します。

cd /opt/acromusashi-stream-example
java -classpath conf:lib/* -Dlogfile.name=SnmpReceive.log -Dlogback.configurationFile=conf/logback-camel.xml org.apache.camel.spring.Main -fa "classpath:camel-context-example-snmp_kestrel.xml"

Step2: SNMPTrap受信Topologyの起動

Nimbusインストールサーバにログインし、下記のコマンドを実行してSNMPTrap受信Topologyを起動します。

cd /opt/storm  
bin/storm jar acromusashi-stream-example-x.x.x.jar acromusashi.stream.example.topology.LocalConsolePrintTopology conf/LocalConsolePrintTopology.yaml false  

SNMPTrap受信Topologyが動作しているWorkerのログ(/opt/storm/logs/LocalConsolePrintTopology-xx-xxxxxxxxworker-xxxx.log)に下記のようにJSON形式のSNMPが出力されることを確認します。

{"header":{"sender":"192.168.100.100","timestamp":"1349333576093","type":"snmp","version":"1.0"},"body":{"snmp":[{"oid":"1.3.6.1.2.1.1.3.0","value":"96468"},{"oid":"1.3.6.1.6.3.1.1.4.1.0","value":"1.3.6.1.6.3.1.1.5.3"},{"oid":"1.3.6.1.2.1.2.2.1.1.1","value":"abc"}]}}

Step3: SNMPTrap受信Topologyの終了

Nimbusインストールサーバにログインし、下記のコマンドを実行してSNMPTrap受信Topologyを終了します。

cd /opt/storm  
bin/storm kill LocalConsolePrintTopology

Step4: SNMPTrap受信プロセスの終了

起動中のウィンドウで「Ctrl+C」を入力し、SNMPTrap受信プロセスを終了します。

解説

ConsolePrintBoltではコンソールに結果を出力していますが、ClusterModeにおいてはコンソール出力はログファイルに出力されます。

⚠️ **GitHub.com Fallback** ⚠️