sorta kinda...

主にAWS関連ですが、これに限らずいろいろ勉強したことや思ったことを書いていきます。

Nagios で Ubuntu を監視しようとしたらハマった [cloudpack OSAKA blog]

ナスです。

Nagios を使って Ubuntu Server を何台か監視しようとしたんですが、その時にツラい目に遭ったのでみなさんに共有します。

 

やりたかったこと

Nagios サーバから、Ubuntu Server に入れた NRPE に対して引数をつけてメトリクスを収集したい。ただそれだけ。

 

NRPE の設定

他にもいっぱいコマンド定義しましたが、とりあえず簡単に説明できる tcp ポートのチェックを例に。
設定ファイル:/etc/nagios/nrpe.cfg

allowed_hosts=127.0.0.1,<ip_address>
dont_blame_nrpe=1
command[check_tcp]=/usr/lib/nagios/plugins/check_tcp -p $ARG1$

 

Nagios サーバから確認してみると

# /usr/lib64/nagios/plugins/check_nrpe -H <ip_address>
NRPE v2.15

よし、通るな。

# /usr/lib64/nagios/plugins/check_nrpe -H <ip_address> -c check_tcp -a 80
CHECK_NRPE: Received 0 bytes from daemon.  Check the remote server logs for error messages.

え、え? なんで??

 

Google で検索しまくった結果

なんかバグレポートが見つかりました。
#756479 - nagios-nrpe-server: Ignores dont_blame_nrpe=1 - Debian Bug report logs

NRPE が引数つきの問い合わせに対応できなくなったようです。 詳細な経緯までは追ってませんが、-enable-command-args オプションを外してパッケージングするようになったみたいで、今後も復活することはないようです。

 

対処内容

引数を使わずに、NRPE 側で固定値を書きました…

allowed_hosts=127.0.0.1,<ip_address>
dont_blame_nrpe=1
command[check_tcp]=/usr/lib/nagios/plugins/check_tcp -p 80

たまたま Ubuntu Server は数台だけだったのでよかったですが、これがたくさんあったらもう最悪でした。 -enable-command-args オプションをつけてパッケージを作ればいいのですが、できればそんなことはしたくなかったので、今回はこれで落ち着きました。

 

普段 Amazon Linux とか CentOS しか触らないのでレアケースなんですが、もしかしたら Ubuntu 使うケースが増えてくるかもしれないので、誰かのお役に立てれば嬉しいです。

Zabbix とかならこんなことにはならなかったのかなぁ…

Curator を使って elasticsearch に何かする [cloudpack OSAKA blog]

ナスです。

先日、こんな記事を書きました。
nasrinjp1.hatenablog.com

この中で、Curator の Amazon ES のサポートが微妙って書いたんですが、でもやっぱり楽したいですし、あるものはパクろうの精神で実際に試してみました。

 

インストール

今回は自分の mac に入れてみました。pip で入れるので、環境が変わっても手順は同じです。バージョン4は Amazon ES のサポートが No となっていたので、3 の最新を入れました。

$ pip install 'elasticsearch-curator<4.0'
Collecting elasticsearch-curator<4.0
  Downloading elasticsearch_curator-3.5.1-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 1.5MB/s
Collecting elasticsearch<3.0.0,>=2.3.0 (from elasticsearch-curator<4.0)
  Downloading elasticsearch-2.4.1-py2.py3-none-any.whl (55kB)
    100% |████████████████████████████████| 61kB 2.8MB/s
Collecting click>=3.3 (from elasticsearch-curator<4.0)
  Downloading click-6.7-py2.py3-none-any.whl (71kB)
    100% |████████████████████████████████| 71kB 2.0MB/s
Requirement already satisfied: urllib3<2.0,>=1.8 in /Library/Python/2.7/site-packages (from elasticsearch<3.0.0,>=2.3.0->elasticsearch-curator<4.0)
Installing collected packages: elasticsearch, click, elasticsearch-curator
  Found existing installation: elasticsearch 5.3.0
    Uninstalling elasticsearch-5.3.0:
      Successfully uninstalled elasticsearch-5.3.0
Successfully installed click-6.7 elasticsearch-2.4.1 elasticsearch-curator-3.5.1

$ curator --version
curator, version 3.5.1

 

インデックス一覧取得

インデックス一覧を取ってみました。この例は、作成されてから 1 日以上経過したインデックスだけを取ります。1 個しか作ってないので、一覧と言っても 1 個だけ表示されてます。

$ curator --host search-domainname-hogehoge.ap-northeast-1.es.amazonaws.com --port 80 --debug show indices --older-than 1 --time-unit days --timestring %Y.%m.%d
2017-04-05 10:11:04,901 INFO      Job starting: show indices
2017-04-05 10:11:05,046 INFO      Action show will be performed on the following indices: [u'cwl-test-2017.04.01']
2017-04-05 10:11:05,046 INFO      Matching indices:
cwl-test-2017.04.01

–debug をつけると詳細が見れます。なんか WARNING が出てますが、/cluster/state/metadata へのアクセスは AWS から許可されていないので、これが出ています。いろいろやってみてわかったんですが、どんな操作をしても、Curator は /cluster/state/metadata にアクセスしています。たぶんどうにもなりません。

2017-04-05 10:52:45,008 WARNING            elasticsearch       log_request_fail:88   GET /_cluster/state/metadata/cwl-test-2017.04.01 [status:401 request:0.030s]

■サポートされるオペレーション docs.aws.amazon.com

 

インデックスの close

closeは、削除はしないけど検索対象から外す(隠す)ってことっぽいです。
www.elastic.co

で、試してみたんですが、なんかエラー出ました。

$ curator --host search-domainname-hogehoge.ap-northeast-1.es.amazonaws.com --port 80 close indices --older-than 1 --time-unit days --timestring %Y.%m.%d
Error closing indices.  Run with --debug flag and/or check Elasticsearch logs for more information.

–debug つけてやってみると、エラーの原因が出ました。単に AWS が /_close に対するアクセスを許可してなかっただけでした。サポートされるオペレーションの中にも確かになかったです。

2017-04-05 10:15:41,716 WARNING            elasticsearch       log_request_fail:88   POST /cwl-test-2017.04.01/_close?ignore_unavailable=true [status:401 request:0.030s]
2017-04-05 10:15:41,716 DEBUG              elasticsearch       log_request_fail:99   < {"Message":"Your request: '/cwl-test-2017.04.01/_close' is not allowed by Amazon Elasticsearch Service."}

 

インデックス削除

インデックスの削除は問題なくできました。

$ curator --host search-domainname-hogehoge.ap-northeast-1.es.amazonaws.com --port 80 --debug delete indices --older-than 1 --time-unit days --timestring %Y.%m.%d
2017-04-05 10:20:41,340 INFO      Job starting: delete indices
2017-04-05 10:20:41,451 INFO      Pruning Kibana-related indices to prevent accidental deletion.
2017-04-05 10:20:41,451 INFO      Action delete will be performed on the following indices: [u'cwl-test-2017.04.01']
2017-04-05 10:20:41,520 INFO      Deleting indices as a batch operation:
2017-04-05 10:20:41,520 INFO      ---deleting index cwl-test-2017.04.01
2017-04-05 10:20:41,600 INFO      Job completed successfully.

 

というわけで、インデックスのハウスキープ処理をするだけなら Curator を使えば ok ってことですね。次に機会があったら使ってみようと思います。