こんにちは! JQです。
前回は『 OSS編~Sensuを試してみる⑤~ 』と題して、Monitoring FrameworkであるSensuのsensu-admin(WEBUI)を試してみました。
今回は『OSS編~Sensuを試してみる⑥~』と題して、Monitoring FrameworkであるSensuのsensu-apiを試してみたいと思います。
sensu-api
1.前提
先ずはsensu-apiが稼働していることを確認します。
1$ sudo /etc/rc.d/init.d/sensu-api status2sensu-api (pid 3559) is running...次にポート等を確認します。
1$ sudo vim /etc/sensu/config.json2 "api": {3 "host": "localhost",4 "bind": "0.0.0.0",5 "port": 45676 },結果はJsonで来るため、見やすいようにjqをインストールしておきます。
1$ sudo yum -y install jq2.試してみる
公式ドキュメント を参考にcurlで試してみます。
※記述時はver0.12
・aggregates
1$ curl -s http://localhost:4567/aggregates | jq .・checks
1$ curl -s http://localhost:4567/checks | jq .2[3 {4 "name": "cron_process",5 "occurrences": 5,6 "notification": "Cron is not running",7 "interval": 30,8 "subscribers": [9 "cron"10 ],11 "handlers": [12 "mailer"13 ],14 "command": "check-procs.rb -p cron -C 1"15 }16]・clients
1$ curl -s http://localhost:4567/clients | jq .2[3 {4 "timestamp": 1402461331,5 "subscriptions": [6 "cron",7 "all"8 ],9 "address": "xx.xxx.xx.xxx",10 "name": "ip-xx.xxx.xx.xxx.ec2.internal"11 }12]・client name
1$ curl -s http://localhost:4567/clients/ip-xx.xxx.xx.xxx.ec2.internal | jq .2{3 "timestamp": 1402461633,4 "subscriptions": [5 "cron",6 "all"7 ],8 "address": "xx.xxx.xx.xxx",9 "name": "ip-xx.xxx.xx.xxx.ec2.internal"10}・client history
1$ curl -s http://localhost:4567/clients/ip-xx.xxx.xx.xxx.ec2.internal/history | jq .2[3 {4 "last_status": 0,5 "last_execution": 1402461673,6 "history": [7 0,8 0,9 0,10 0,11 0,12 0,13 0,14 0,15 0,16 0,17 0,18 0,19 0,20 0,21 0,22 0,23 0,24 0,25 0,26 0,27 028 ],29 "check": "keepalive"30 },31 {32 "last_status": 0,33 "last_execution": 1402461676,34 "history": [35 0,36 0,37 0,38 0,39 0,40 0,41 0,42 0,43 0,44 0,45 0,46 0,47 0,48 0,49 0,50 0,51 0,52 0,53 0,54 0,55 056 ],57 "check": "cron_process"58 }59]・info
1$ curl -s http://localhost:4567/info | jq .2{3 "redis": {4 "connected": true5 },6 "rabbitmq": {7 "connected": true,8 "results": {9 "consumers": 1,10 "messages": 011 },12 "keepalives": {13 "consumers": 1,14 "messages": 015 }16 },17 "sensu": {18 "version": "0.12.6"19 }20}・events
1$ curl -s http://localhost:4567/events | jq .・health(success: 204)
1$ curl -s -w "%{http_code}" http://localhost:4567/health・stashes
1$ curl -s http://localhost:4567/stashes | jq .その他の詳細はドキュメントをご参照ください。
3.パスワードを掛けてみる
Basic認証によるパスワードを掛けてみます。
userとpasswordを以下に追記します。
1$ sudo vim /etc/sensu/config.json2 "api": {3 "host": "localhost",4 "bind": "0.0.0.0",5 "port": 4567,6 "user": "admin",7 "password": "secret"8 },反映します。
1$ sudo /etc/rc.d/init.d/sensu-api restart401 Unauthorizedになるのが確認できます。
1$ curl -v http://localhost:4567/checks2* Hostname was NOT found in DNS cache3* Trying 127.0.0.1...4* Connected to localhost (127.0.0.1) port 4567 (#0)5> GET /checks HTTP/1.16> User-Agent: curl/7.36.07> Host: localhost:45678> Accept: */*9>10< HTTP/1.1 401 Unauthorized11< Content-Type: text/plain12< Content-Length: 013< WWW-Authenticate: Basic realm=""14< Connection: keep-alive15* Server thin 1.5.0 codename Knife is not blacklisted16< Server: thin 1.5.0 codename Knife認証をすれば正しく取得出来ます。
1$ curl -s http://localhost:4567/checks --user admin:secret | jq .2[3 {4 "name": "cron_process",5 "occurrences": 5,6 "notification": "Cron is not running",7 "interval": 30,8 "subscribers": [9 "cron"10 ],11 "handlers": [12 "mailer"13 ],14 "command": "check-procs.rb -p cron -C 1"15 }16]いかがでしたでしょうか?
次回もお楽しみに!!!