12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sensuのclient.jsonをChefで管理する場合のsubscriptionの作成方法

Posted at

Sensuの管理をChefで行う場合、subscriptionsの設定をどうするか考えた結果
下記のようにtemplate側でまとめるという方法があるのかなと思ったのですが
(attributesはrole to roleのみmergeされる。その際にnodeのattributesは破棄されてしまうので)
他に何か良い方法ありますかね。

もしくはそもそも私の認識に誤りがある可能性が高いので、
ご指摘頂ければありがたいです。

  • roles/web_foo.json
  "sensu": {
      "node_subscriptions": [ 
          "web_foo"
      ]
  },
  "run_list": [ "role[web]" ]
  • /roles/web.json
{
  "name": "web",
  "description": "web",
  "json_class": "Chef::Role",
  "override_attributes": {
      "sensu": {
        "role_subscriptions": [ "web" ]
      }
  },
  "default_attributes": {
  },
  "chef_type": "role",
  "run_list": [
    "role[base]"
  ]
}
  • roles/base.json
{
  "name": "base",
  "description": "base",
  "json_class": "Chef::Role",
  "override_attributes": {
      "sensu": {
        "role_subscriptions": [ "all" ]
      }
  },
  "default_attributes": {
  },
  "chef_type": "role",
  "run_list": [
    "recipe[sensu-settings]"
  ]
}
  • sensu-settings/recipes/default.rb
template "/etc/sensu/conf.d/client.json" do
  owner "root"
  mode  0644
  source "client.json.erb"
end
  • client.json.erb
{
  "client": {
    "name": "<%= node[:hostname] %>",
    "address": "<%= node[:ipaddress] %>",
<% _subscription = Array.new %>
<% _subscription += node[:sensu][:node_subscriptions]  %>
<% _subscription += node[:sensu][:role_subscriptions]  %>
    "subscriptions": <%= _subscription %>
  }
}
  • client.json
{
  "client": {
    "name": "HOSTNAME",
    "address": "IPADDR",
    "subscriptions": ["web_foo", "all", "web"]
  }
}
12
11
0

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
12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?