LoginSignup
11

More than 5 years have passed since last update.

Go言語でSensuのCLI「ohgi」を作った

Last updated at Posted at 2015-05-23

最近話題のGo言語の勉強も兼ねて,sensu-apiを叩くCLIを作ってみました.

名前の由来

sensu(扇子)に関連する単語ということで,kaname(要)やyoichi(与一)が候補でした.
GitHubに同名リポジトリが無いということで,ohgi(扇)にしました.

作ったきっかけ

既にRuby製のagent462/sensu-cliがあります.
ただ,表示の情報量が多く,見難いと感じていました.

sensu-cli.png

そこで,シンプルな表示で,高速に動作するものを作ることにしました.
表示形式やコマンドは,Uchiwaを参考にしています.

コマンド構成

Goでコマンドを作るために,spf13/cobraを使いました.
spf13/pflagでフラグが使えたり,helpを生成してくれたりして便利です.

文字列の結合は「Goの文字列結合のパフォーマンス - Qiita」を参考に,[]byteappendで行っています.

aggregates以外のsensu-apiは一通り叩けるようにしています.
stashessilenceコマンドとして,機能を制限して実装しました.

Sensu command-line tool by golang
https://github.com/hico-horiuchi/ohgi

Usage:
  ohgi [command]

Available Commands:
  checks [check]               Returns the list of checks
  request [check] [subscriber] Issues a check execution request
  clients [client]             Returns the list of clients
  history [client]             Returns the client history
  events [client] [check]      List and resolve current events
  resolve [client] [check]     Resolves an event (delayed action)
  health                       Returns the API info
  info                         Returns the API info
  silence [client] [check]     Returns a list of silences
  version                      Print git revision of ohgi
  help [command]               Help about any command

Use "ohgi help [command]" for more information about that command.

v0.1.0

ohgi.png

ソースコードとバイナリ(darwin,linux)はGitHubで公開しています.
Windowsでも動作しますが,CygwinやMingwが必要です.
(コマンドプロンプトでは,カラーコードを処理できない.)

ぜひ使って頂いて,IssueやPullRequestをお願いします!

これから

Sensuのメーリスで布教したり(もちろん英語),Sensuの勉強会があれば発表したりしたいです.
sensu-apiは仕様が変わったりするので追従したり,コマンドの追加を頑張りたいです.

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
11