dfb68c1dfa1481d72ebc78014123603996d21390
[sdc.git] / sdc-os-chef / sdc-elasticsearch / chef-repo / cookbooks / sdc-elasticsearch / recipes / ES_5_create_monitoring_template.rb
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 monitoring mapping" do
24         code <<-EOH     
25                 curl -i -X PUT -d '{ "order": 1, "template": "monitoring_events-*", "settings": {}, "mappings":
26                         {
27                                 "monitoringevent": {
28                                         "properties": {
29                                                 "hostid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
30                                                 "hostcpu": { "include_in_all": true,  "type": "long" },
31                                                 "hostmem": { "include_in_all": true,  "type": "double" },
32                                                 "hostdisk": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
33                                                 "jvmid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
34                                                 "jvmcpu": { "include_in_all": true,"type": "long" },
35                                                 "jvmmem": { "include_in_all": true, "type": "long" },
36                                                 "jvmtnum": { "include_in_all": true, "type": "integer" },
37                                                 "appid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
38                                                 "appstat": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
39                                                 "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" }
40                                         },
41                                         "_all": { "enabled": true } 
42                                 }
43                         },
44                         "aliases": { "last_3_months": {} }
45                 }' http://localhost:9200/_template/monitoring_template
46         EOH
47 end