08c3fac613e7ed83fc1aa23423146f63938cfb71
[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 Kibana dashboard" do
24     code <<-EOH
25         for file in /root/chef-solo/cookbooks/sdc-init-elasticsearch/files/default/dashboard_*.json; do 
26             name=`basename $file .json | awk -F"_" '{print $2}'` 
27             echo "Loading dashboard $name:" 
28             curl -XPUT http://#{node['Nodes']['ES']}:9200/.kibana/dashboard/$name -d @$file || exit 1 
29             echo 
30         done 
31     EOH
32 end
33
34 bash "create Kibana visualization" do
35     code <<-EOH
36         for file in /root/chef-solo/cookbooks/sdc-init-elasticsearch/files/default/visualization_*.json; do 
37             name=`basename $file .json | awk -F"_" '{print $2}'` 
38             echo "Loading visualization $name:" 
39             curl -XPUT http://#{node['Nodes']['ES']}:9200/.kibana/visualization/$name -d @$file || exit 1 
40             echo 
41         done 
42     EOH
43 end
44
45 bash "echo status" do
46    code <<-EOH
47      echo "DOCKER STARTED"
48    EOH
49 end