d35b81293e3890376fa905e4c22a705d5532a65f
[sdc.git] /
1 ruby_block "check_ElasticSearch_Cluster_Health" do
2     block do
3       #tricky way to load this Chef::Mixin::ShellOut utilities
4       Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
5       curl_command = "http://#{node['Nodes']['ES']}:9200/_cluster/health?pretty=true"
6       resp = Net::HTTP.get_response URI.parse(curl_command)
7       stat = JSON.parse(resp.read_body)['status']
8
9       case stat
10          when "green"
11             printf("\033[32m%s\n\033[0m", "  ElasticSearch Cluster status is green.")
12          when "yellow"
13             printf("\033[33m%s\n\033[0m", "  ElasticSearch Cluster status is yellow...")
14          when "red"
15             printf("\033[31m%s\n\033[0m", "  ElasticSearch Cluster status is red!")
16             break;
17       end
18    end
19    retries 10
20    retry_delay 2
21 end
22
23 bash "create resources mapping" do
24         code <<-EOH     
25                 curl -i -X PUT -d '{ "order": 1, "template": "resources", "settings": {}, "mappings":
26                         {
27                                 "esartifactdata": {
28                                         "properties": {
29                                                 "id": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
30                                                 "data": { "include_in_all": false, "type": "string" }
31                                         },
32                                         "_all": { "enabled": true } 
33                                 }
34                         }
35                 }' http://#{node['Nodes']['ES']}:9200/_template/resources_template
36         EOH
37 end