8ee4087325720826e6e7c2c837b02097600faaa8
[sdc.git] / sdc-os-chef / sdc-init-elasticsearch / chef-repo / cookbooks / init-sdc-elasticsearch / recipes / ES_1_create_audit_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 50
23    retry_delay 2
24 end
25
26
27 bash "create audit mapping" do
28         code <<-EOH
29                 curl -i -X PUT -d '{ "order": 1, "template": "auditingevents-*", "settings": {}, "mappings":
30         {
31                 "distributiondownloadevent": { 
32                         "properties": {
33                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
34                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
35                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
36                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
37                                 "DESC": { "include_in_all": true, "type": "string" },
38                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
39                                 "RESOURCE_URL": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
40                                 "CONSUMER_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" }
41                         },
42                         "_all": { "enabled": true } 
43                 },
44                 "auditinggetuebclusterevent": { 
45                         "properties": {
46                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
47                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
48                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
49                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
50                                 "DESC": { "include_in_all": true, "type": "string" },
51                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
52                                 "CONSUMER_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" }
53                         },
54                         "_all": { "enabled": true } 
55                 },
56                 "distributionstatusevent": {
57                         "properties": {
58                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
59                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
60                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
61                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
62                                 "DESC": { "include_in_all": true, "type": "string" },
63                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
64                                 "RESOURCE_URL": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
65                                 "DID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
66                                 "TOPIC_NAME":{ "include_in_all": true, "index": "not_analyzed", "type": "string" },
67                                 "CONSUMER_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" }
68                         },
69                         "_all": { "enabled": true } 
70                 },
71                 "distributionengineevent": {
72                         "properties": {
73                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
74                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
75                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
76                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
77                                 "DESC": { "include_in_all": true, "type": "string" },
78                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
79                                 "TOPIC_NAME":{ "include_in_all": true, "index": "not_analyzed", "type": "string" },
80                                 "ROLE": { "include_in_all": true, "type": "string" },
81                                 "API_KEY": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
82                                 "D_ENV": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
83                                 "CONSUMER_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" }
84                         },
85                         "_all": { "enabled": true } 
86                 },
87                 "useraccessevent": { 
88                         "properties": {
89                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
90                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
91                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
92                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
93                                 "DESC": { "include_in_all": true, "type": "string" },
94                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
95                                 "USER": { "include_in_all": true, "type": "string" }
96                         },
97                         "_all": { "enabled": true }
98                 },
99                 "resourceadminevent": {
100                         "properties": {
101                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
102                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
103                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
104                                 "INVARIANT_UUID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
105                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
106                                 "DESC": { "include_in_all": true, "type": "string" },
107                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
108                                 "CURR_VERSION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
109                                 "CURR_STATE": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
110                                 "DID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
111                                 "MODIFIER": { "include_in_all": true, "type": "string" },
112                                 "PREV_VERSION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
113                                 "PREV_STATE": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
114                                 "RESOURCE_NAME": { "include_in_all": true, "type": "string" },
115                                 "RESOURCE_TYPE": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
116                                 "DPREV_STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
117                                 "DCURR_STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
118                                 "TOSCA_NODE_TYPE": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
119                                 "COMMENT": { "include_in_all": true, "type": "string" },
120                                 "ARTIFACT_DATA": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
121                                 "PREV_ARTIFACT_UUID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
122                                 "CURR_ARTIFACT_UUID": { "include_in_all": true, "index": "not_analyzed", "type": "string" } 
123                         },
124                         "_all": { "enabled": true }
125                 },
126                 "useradminevent": {
127                         "properties": {
128                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
129                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
130                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
131                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
132                                 "DESC": { "include_in_all": true, "type": "string" },
133                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
134                                 "USER_AFTER": { "include_in_all": true, "type": "string" },
135                                 "USER_BEFORE": { "include_in_all": true, "type": "string" },
136                                 "MODIFIER": { "include_in_all": true, "type": "string" }
137                         },
138                         "_all": { "enabled": true } 
139                 },
140                 "distributionnotificationevent": {
141                         "properties": {
142                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
143                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
144                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
145                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
146                 "DESC": { "include_in_all": true, "type": "string" },
147                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
148                 "CURR_STATE": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
149                 "CURR_VERSION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
150                 "DID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
151                 "MODIFIER": { "include_in_all": true, "type": "string" },
152                 "RESOURCE_NAME": { "include_in_all": true, "type": "string" },
153                 "RESOURCE_TYPE": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
154                 "TOPIC_NAME":{ "include_in_all": true, "index": "not_analyzed", "type": "string" }
155                         },
156             "_all": { "enabled": true } 
157                 },
158                 "categoryevent": {
159                         "properties": {
160                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
161                                 "DESC": { "include_in_all": true, "type": "string" },
162                                 "MODIFIER": { "include_in_all": true, "type": "string" },
163                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
164                                 "CATEGORY_NAME": { "include_in_all": true, "type": "string" },
165                                 "SUB_CATEGORY_NAME": { "include_in_all": true, "type": "string" },
166                                 "GROUPING_NAME": { "include_in_all": true, "type": "string" },
167                                 "RESOURCE_TYPE": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
168                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
169                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
170                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" }
171                         },
172             "_all": { "enabled": true } 
173                 },
174                 "authevent": {
175                         "properties": {
176                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" },
177                                 "DESC": { "include_in_all": true, "type": "string" },
178                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
179                                 "URL": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
180                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
181                                 "USER": { "include_in_all": true, "type": "string" },
182                                 "AUTH_STATUS": { "include_in_all": true, "index": "not_analyzed","type": "string" } ,
183                                 "REALM": { "include_in_all": true, "index": "not_analyzed","type": "string" }
184                         },
185                         "_all": { "enabled": true }
186                 },
187                 "consumerevent": {
188                         "properties": {
189                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
190                                 "MODIFIER": { "include_in_all": true, "type": "string" },
191                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
192                                 "DESC": { "include_in_all": true, "type": "string" },
193                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
194                                 "ECOMP_USER": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
195                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" }
196                         },
197                         "_all": { "enabled": true } 
198                 },
199                 "getuserslistevent": {
200                         "properties": {
201                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
202                                 "MODIFIER": { "include_in_all": true, "type": "string" },
203                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
204                                 "DESC": { "include_in_all": true, "type": "string" },
205                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
206                                 "DETAILS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
207                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" }
208                         },
209             "_all": { "enabled": true } 
210                 },
211                 "getcategoryhierarchyevent": {
212                         "properties": {
213                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
214                                 "MODIFIER": { "include_in_all": true, "type": "string" },
215                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
216                                 "DESC": { "include_in_all": true, "type": "string" },
217                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
218                                 "DETAILS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
219                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" }
220                         },
221                         "_all": { "enabled": true } 
222                 },
223                 "distributiondeployevent": {
224                         "properties": {
225                                 "ACTION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
226                                 "CURR_VERSION": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
227                                 "DESC": { "include_in_all": true, "type": "string" },
228                                 "DID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
229                                 "MODIFIER": { "include_in_all": true, "type": "string" },
230                                 "REQUEST_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
231                                 "RESOURCE_NAME": { "include_in_all": true, "type": "string" },
232                                 "RESOURCE_TYPE": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
233                                 "SERVICE_INSTANCE_ID": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
234                                 "STATUS": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
235                                 "TIMESTAMP": { "include_in_all": true, "ignore_malformed": false, "format": "yyyy-MM-dd HH:mm:ss.SSS z", "precision_step": 4, "type": "date" }
236                         },
237             "_all": { "enabled": true } }
238                 },
239         "aliases": { "last_3_months": {}}}' http://#{es_node}:9200/_template/audit_template
240         EOH
241 end
242
243 bash "set default index for Kibana" do
244         code <<-EOH
245         curl -XPUT http://#{es_node}:9200/.kibana/index-pattern/auditingevents-* -d '{"title" : "events-*",  "timeFieldName": "TIMESTAMP"}'
246         curl -XPUT http://#{es_node}:9200/.kibana/config/4.3.3 -d '{"defaultIndex" : "auditingevents-*"}'
247     EOH
248 end