Move to version 1.6.1
[sdc.git] / sdc-os-chef / sdc-init-elasticsearch / chef-repo / cookbooks / init-sdc-elasticsearch / recipes / ES_4_create_kibana_dashboard_virtualization.rb
1 # Get the first es node in the list
2 es_node =  node['Nodes']['ES'].first
3
4 ruby_block "check_ElasticSearch_Cluster_Health" do
5     block do
6       #tricky way to load this Chef::Mixin::ShellOut utilities
7       Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
8       curl_command = "http://#{es_node}:9200/_cluster/health?pretty=true"
9       resp = Net::HTTP.get_response URI.parse(curl_command)
10       stat = JSON.parse(resp.read_body)['status']
11
12       case stat
13          when "green"
14             printf("\033[32m%s\n\033[0m", "  ElasticSearch Cluster status is green.")
15          when "yellow"
16             printf("\033[33m%s\n\033[0m", "  ElasticSearch Cluster status is yellow...")
17          when "red"
18             printf("\033[31m%s\n\033[0m", "  ElasticSearch Cluster status is red!")
19             break;
20       end
21    end
22    retries 10
23    retry_delay 2
24 end
25
26 bash "create Kibana dashboard" do
27     code <<-EOH
28         for file in /root/chef-solo/cookbooks/sdc-init-elasticsearch/files/default/dashboard_*.json; do 
29             name=`basename $file .json | awk -F"_" '{print $2}'` 
30             echo "Loading dashboard $name:" 
31             curl -XPUT http://#{es_node}:9200/.kibana/dashboard/$name -d @$file || exit 1
32             echo 
33         done 
34     EOH
35 end
36
37 bash "create Kibana visualization" do
38     code <<-EOH
39         for file in /root/chef-solo/cookbooks/sdc-init-elasticsearch/files/default/visualization_*.json; do 
40             name=`basename $file .json | awk -F"_" '{print $2}'` 
41             echo "Loading visualization $name:" 
42             curl -XPUT http://#{es_node}:9200/.kibana/visualization/$name -d @$file || exit 1
43             echo 
44         done 
45     EOH
46 end
47
48 bash "echo status" do
49    code <<-EOH
50      echo "DOCKER STARTED"
51    EOH
52 end