Move to version 1.6.1
[sdc.git] / sdc-os-chef / sdc-init-elasticsearch / chef-repo / cookbooks / init-sdc-elasticsearch / recipes / ES_3_create_monitoring_template.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 "echo status" do
27    code <<-EOH
28      echo "DOCKER STARTED"
29    EOH
30 end
31
32 bash "create monitoring mapping" do
33         code <<-EOH     
34                 curl -i -X PUT -d '{ "order": 1, "template": "monitoring_events-*", "settings": {}, "mappings":
35                         {
36                                 "monitoringevent": {
37                                         "properties": {
38                                                 "hostid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
39                                                 "hostcpu": { "include_in_all": true,  "type": "long" },
40                                                 "hostmem": { "include_in_all": true,  "type": "double" },
41                                                 "hostdisk": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
42                                                 "jvmid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
43                                                 "jvmcpu": { "include_in_all": true,"type": "long" },
44                                                 "jvmmem": { "include_in_all": true, "type": "long" },
45                                                 "jvmtnum": { "include_in_all": true, "type": "integer" },
46                                                 "appid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
47                                                 "appstat": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
48                                                 "timestamp": { "include_in_all": true, "index": "not_analyzed", "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" }
49                                         },
50                                         "_all": { "enabled": true } 
51                                 }
52                         },
53                         "aliases": { "last_3_months": {} }
54                 }' http://#{es_node}:9200/_template/monitoring_template
55         EOH
56 end