4dc264153d55219502bb0d43c21a63d86cf646b0
[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['ipaddress']}:9200/_cluster/health?pretty=true"
6       curl_command = "http://localhost:9200/_cluster/health?pretty=true"
7       resp = Net::HTTP.get_response URI.parse(curl_command)
8       stat = JSON.parse(resp.read_body)['status']
9
10       case stat
11          when "green"
12             printf("\033[32m%s\n\033[0m", "  ElasticSearch Cluster status is green.")
13          when "yellow"
14             printf("\033[33m%s\n\033[0m", "  ElasticSearch Cluster status is yellow...")
15          when "red"
16             printf("\033[31m%s\n\033[0m", "  ElasticSearch Cluster status is red!")
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://localhost:9200/_template/resources_template
36         EOH
37 end