mruby-zabbixとmruby-growthforecastでデバイスやアプリケーションの監視並びに情報の可視化を実現

僕は実はZABBIX-JPのスタッフでもあるので、mrubyでも優先度高めでZabbixのAPIをつつけるClassを作ってみました。

これで、mruby-grothforecastで簡単に組み込みデバイスやアプリケーションの内部情報を簡単に可視化できたり、Zabbixに対してAPI経由で監視の操作ができたり、かなり夢が広がったのではないでしょうか。

ということで、mrbgemsの使い方も兼ねて、mruby-zabbixの使い方を説明します。

インストール

まずはmrubyをダウンロードします。

git clone git://github.com/mruby/mruby.git

そして、mrbgemsのgemsディレクトリに移動して、必要なgemsファイルをダウンロードします。

cd mruby/mrbgems/g/
git clone git://github.com/mattn/mruby-uv.git
git clone git://github.com/mattn/mruby-http.git
git clone git://github.com/mattn/mruby-json.git
git clone git://github.com/matsumoto-r/mruby-redis.git
git clone git://github.com/matsumoto-r/mruby-simplehttp.git
git clone git://github.com/matsumoto-r/mruby-httprequest.git
git clone git://github.com/matsumoto-r/mruby-growthforecast.git
git clone git://github.com/matsumoto-r/mruby-zabbix.git

上記のgemを有効にするために、依存関係も含めて以下のようにGEMS.activeに登録します。

cd mruby
cat > mrbgems/GEMS.active << EOF
mruby-json
mruby-uv
mruby-http
mruby-redis
mruby-simplehttp
mruby-httprequest
mruby-growthforecast
mruby-zabbix
EOF

そして、rakeすると無事ビルドが完了するはずです。

rake ENABLE_GEMS='true' LIBS='-luv -lpthread -ldl -lrt -lhiredis -lm'

mrubyからZabbix2.0のAPIをつついてみる

以下のように、ZabbixのAPIをRubyで書きます。非常に簡単です。

config = {
  :url  => "http://127.0.0.1/zabbix/api_jsonrpc.php",
  :ua   => "mruby-zabbix",
  :user => "api-admin",
  :pass => "api-admin",
}

z = Zabbix::Client.new(config)

data = {
  :method => "get",
  :object => "host",
  :params => {
               :output => "extend",
               :filter => {
                            :host    =>  "example.com",
                          },
             },
}

puts "request:  #{JSON::stringify(data)}"
puts "response: #{z.post(data)["body"]}"

ユーザ名やパスワード、URLが間違っていない事を確認して、以下のように実行してみましょう。

./bin/mruby zabbix-api-client.rb

すると、以下のようにきちんとZabbixから結果が帰ってきていると思います。


GeSHi Error: GeSHi could not find the language json (using path /home/users/0/pupu.jp-matsumotory/web/blog/wp-content/plugins/codecolorer/lib/geshi/) (code 2)

素晴らしいですね!簡単です!

さいごに

このように、ZabbixとGrowthForecastにmrubyからアクセスできるようになったので、もはやmruby組み込みデバイスやアプリケーションからの情報の可視化は十分なのではないかと思っていたりします。

後は、ログ周りを連携できるようにFluentとの連携を少し考えてみようかなぁと思っています。

高機能mrubyウォシュレットも夢では無くなって来ました。

A-EInHqCYAEJlfo

Leave a Comment