New docker start monitor engine
[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 "echo status" do
24    code <<-EOH
25      echo "DOCKER STARTED"
26    EOH
27 end
28
29 bash "create monitoring mapping" do
30         code <<-EOH     
31                 curl -i -X PUT -d '{ "order": 1, "template": "monitoring_events-*", "settings": {}, "mappings":
32                         {
33                                 "monitoringevent": {
34                                         "properties": {
35                                                 "hostid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
36                                                 "hostcpu": { "include_in_all": true,  "type": "long" },
37                                                 "hostmem": { "include_in_all": true,  "type": "double" },
38                                                 "hostdisk": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
39                                                 "jvmid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
40                                                 "jvmcpu": { "include_in_all": true,"type": "long" },
41                                                 "jvmmem": { "include_in_all": true, "type": "long" },
42                                                 "jvmtnum": { "include_in_all": true, "type": "integer" },
43                                                 "appid": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
44                                                 "appstat": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
45                                                 "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" }
46                                         },
47                                         "_all": { "enabled": true } 
48                                 }
49                         },
50                         "aliases": { "last_3_months": {} }
51                 }' http://localhost:9200/_template/monitoring_template
52         EOH
53 end