Jakub Latusek | fcf6784 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 1 | {{/* |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 2 | # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. |
Mukul | 379e252 | 2018-09-05 12:26:02 +0000 | [diff] [blame] | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Jakub Latusek | fcf6784 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 15 | */}} |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 16 | input { |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 17 | http_poller { |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 18 | urls => { |
| 19 | event_queue => { |
| 20 | method => get |
| 21 | url => "${dmaap_base_url}/events/${event_topic}/${dmaap_consumer_group}/${dmaap_consumer_id}?timeout=15000" |
| 22 | headers => { |
| 23 | Accept => "application/json" |
| 24 | } |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 25 | topic => "${event_topic}" |
| 26 | tags => [ "dmaap_source" ] |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 27 | } |
| 28 | notification_queue => { |
| 29 | method => get |
| 30 | url => "${dmaap_base_url}/events/${notification_topic}/${dmaap_consumer_group}/${dmaap_consumer_id}?timeout=15000" |
| 31 | headers => { |
| 32 | Accept => "application/json" |
| 33 | } |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 34 | topic => "${notification_topic}" |
| 35 | tags => [ "dmaap_source" ] |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 36 | } |
| 37 | request_queue => { |
| 38 | method => get |
| 39 | url => "${dmaap_base_url}/events/${request_topic}/${dmaap_consumer_group}/${dmaap_consumer_id}?timeout=15000" |
| 40 | headers => { |
| 41 | Accept => "application/json" |
| 42 | } |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 43 | topic => "${request_topic}" |
| 44 | tags => [ "dmaap_source" ] |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | socket_timeout => 30 |
| 48 | request_timeout => 30 |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 49 | schedule => { "every" => "1m" } |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 50 | codec => "plain" |
osgn422w | 7981445 | 2020-09-25 02:28:02 +0200 | [diff] [blame] | 51 | {{- if .Values.global.aafEnabled }} |
| 52 | cacert => "{{ .Values.certInitializer.credsPath }}/{{ .Values.certInitializer.clamp_ca_certs_pem }}" |
| 53 | {{- else }} |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 54 | cacert => "/certs.d/aafca.pem" |
osgn422w | 7981445 | 2020-09-25 02:28:02 +0200 | [diff] [blame] | 55 | {{- end }} |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 56 | } |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 57 | } |
| 58 | |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 59 | |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 60 | filter { |
| 61 | # avoid noise if no entry in the list |
| 62 | if [message] == "[]" { |
| 63 | drop { } |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 64 | } |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 65 | |
Krysiak Adam | 4993cae | 2019-04-04 09:58:27 +0200 | [diff] [blame] | 66 | if [http_request_failure] or [@metadata][code] != 200 { |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 67 | mutate { |
Sylvain Desbureaux | 8c2a162 | 2020-04-22 10:50:26 +0200 | [diff] [blame] | 68 | add_tag => [ "error" ] |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Krysiak Adam | 4993cae | 2019-04-04 09:58:27 +0200 | [diff] [blame] | 72 | if "dmaap_source" in [@metadata][request][tags] { |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 73 | # |
| 74 | # Dmaap provides a json list, whose items are Strings containing the event |
| 75 | # provided to Dmaap, which itself is an escaped json. |
| 76 | # |
| 77 | # We first need to parse the json as we have to use the plaintext as it cannot |
| 78 | # work with list of events, then split that list into multiple string events, |
| 79 | # that we then transform into json. |
| 80 | # |
| 81 | json { |
| 82 | source => "[message]" |
| 83 | target => "message" |
| 84 | } |
Krysiak Adam | 4993cae | 2019-04-04 09:58:27 +0200 | [diff] [blame] | 85 | |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 86 | split { |
| 87 | field => "message" |
| 88 | } |
| 89 | json { |
| 90 | source => "message" |
| 91 | } |
| 92 | mutate { |
| 93 | remove_field => [ "message" ] |
| 94 | } |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 95 | } |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 96 | |
| 97 | # |
| 98 | # Some timestamps are expressed as milliseconds, some are in microseconds |
| 99 | # |
| 100 | if [closedLoopAlarmStart] { |
| 101 | ruby { |
| 102 | code => " |
| 103 | if event.get('closedLoopAlarmStart').to_s.to_i(10) > 9999999999999 |
| 104 | event.set('closedLoopAlarmStart', event.get('closedLoopAlarmStart').to_s.to_i(10) / 1000) |
| 105 | else |
| 106 | event.set('closedLoopAlarmStart', event.get('closedLoopAlarmStart').to_s.to_i(10)) |
| 107 | end |
| 108 | " |
| 109 | } |
| 110 | date { |
| 111 | match => [ "closedLoopAlarmStart", UNIX_MS ] |
| 112 | target => "closedLoopAlarmStart" |
| 113 | } |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | if [closedLoopAlarmEnd] { |
| 117 | ruby { |
osgn422w | 7bc14fa | 2018-09-06 15:33:50 +0200 | [diff] [blame] | 118 | code => " |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 119 | if event.get('closedLoopAlarmEnd').to_s.to_i(10) > 9999999999999 |
| 120 | event.set('closedLoopAlarmEnd', event.get('closedLoopAlarmEnd').to_s.to_i(10) / 1000) |
| 121 | else |
| 122 | event.set('closedLoopAlarmEnd', event.get('closedLoopAlarmEnd').to_s.to_i(10)) |
| 123 | end |
| 124 | " |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 125 | } |
| 126 | date { |
| 127 | match => [ "closedLoopAlarmEnd", UNIX_MS ] |
| 128 | target => "closedLoopAlarmEnd" |
| 129 | } |
| 130 | |
| 131 | } |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 132 | |
| 133 | |
| 134 | # |
| 135 | # Notification time are expressed under the form "yyyy-MM-dd HH:mm:ss", which |
| 136 | # is close to ISO8601, but lacks of T as spacer: "yyyy-MM-ddTHH:mm:ss" |
| 137 | # |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 138 | if [notificationTime] { |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 139 | mutate { |
| 140 | gsub => [ |
| 141 | "notificationTime", " ", "T" |
| 142 | ] |
| 143 | } |
| 144 | date { |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 145 | match => [ "notificationTime", ISO8601 ] |
| 146 | target => "notificationTime" |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | |
| 151 | # |
| 152 | # Renaming some fields for readability |
| 153 | # |
| 154 | if [AAI][generic-vnf.vnf-name] { |
| 155 | mutate { |
| 156 | add_field => { "vnfName" => "%{[AAI][generic-vnf.vnf-name]}" } |
| 157 | } |
| 158 | } |
| 159 | if [AAI][generic-vnf.vnf-type] { |
| 160 | mutate { |
| 161 | add_field => { "vnfType" => "%{[AAI][generic-vnf.vnf-type]}" } |
| 162 | } |
| 163 | } |
| 164 | if [AAI][vserver.vserver-name] { |
| 165 | mutate { |
| 166 | add_field => { "vmName" => "%{[AAI][vserver.vserver-name]}" } |
| 167 | } |
| 168 | } |
| 169 | if [AAI][complex.city] { |
| 170 | mutate { |
| 171 | add_field => { "locationCity" => "%{[AAI][complex.city]}" } |
| 172 | } |
| 173 | } |
| 174 | if [AAI][complex.state] { |
| 175 | mutate { |
| 176 | add_field => { "locationState" => "%{[AAI][complex.state]}" } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | |
| 181 | # |
| 182 | # Adding some flags to ease aggregation |
| 183 | # |
| 184 | if [closedLoopEventStatus] =~ /(?i)ABATED/ { |
| 185 | mutate { |
| 186 | add_field => { "flagAbated" => "1" } |
| 187 | } |
| 188 | } |
| 189 | if [notification] =~ /^.*?(?:\b|_)FINAL(?:\b|_).*?(?:\b|_)FAILURE(?:\b|_).*?$/ { |
| 190 | mutate { |
| 191 | add_field => { "flagFinalFailure" => "1" } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | |
Krysiak Adam | 4993cae | 2019-04-04 09:58:27 +0200 | [diff] [blame] | 196 | if "error" not in [@metadata][request][tags]{ |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 197 | # |
| 198 | # Creating data for a secondary index |
| 199 | # |
| 200 | clone { |
| 201 | clones => [ "event-cl-aggs" ] |
| 202 | add_tag => [ "event-cl-aggs" ] |
| 203 | } |
Sylvain Desbureaux | 8c2a162 | 2020-04-22 10:50:26 +0200 | [diff] [blame] | 204 | |
Krysiak Adam | 4993cae | 2019-04-04 09:58:27 +0200 | [diff] [blame] | 205 | if "event-cl-aggs" in [@metadata][request][tags]{ |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 206 | # |
| 207 | # we only need a few fields for aggregations; remove all fields from clone except : |
| 208 | # vmName,vnfName,vnfType,requestID,closedLoopAlarmStart, closedLoopControlName,closedLoopAlarmEnd,abated,nbrDmaapevents,finalFailure |
| 209 | # |
| 210 | prune { |
| 211 | whitelist_names => ["^@.*$","^topic$","^type$","^tags$","^flagFinalFailure$","^flagAbated$","^locationState$","^locationCity$","^vmName$","^vnfName$","^vnfType$","^requestID$","^closedLoopAlarmStart$","^closedLoopControlName$","^closedLoopAlarmEnd$","^target$","^target_type$","^triggerSourceName$","^policyScope$","^policyName$","^policyVersion$"] |
| 212 | } |
Sylvain Desbureaux | 8c2a162 | 2020-04-22 10:50:26 +0200 | [diff] [blame] | 213 | |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 214 | } |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 215 | } |
| 216 | } |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 217 | |
| 218 | |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 219 | output { |
| 220 | stdout { |
| 221 | codec => rubydebug |
| 222 | } |
| 223 | |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 224 | if "error" in [tags] { |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 225 | elasticsearch { |
osgn422w | 87d267d | 2020-09-26 11:38:01 +0200 | [diff] [blame] | 226 | ilm_enabled => false |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 227 | codec => "json" |
osgn422w | 7981445 | 2020-09-25 02:28:02 +0200 | [diff] [blame] | 228 | {{- if .Values.global.aafEnabled }} |
| 229 | cacert => "{{ .Values.certInitializer.credsPath }}/{{ .Values.certInitializer.clamp_ca_certs_pem }}" |
| 230 | {{- else }} |
osgn422w | b561a59 | 2020-02-11 15:50:21 +0100 | [diff] [blame] | 231 | cacert => "/clamp-cert/ca-certs.pem" |
osgn422w | 7981445 | 2020-09-25 02:28:02 +0200 | [diff] [blame] | 232 | {{- end }} |
osgn422w | b561a59 | 2020-02-11 15:50:21 +0100 | [diff] [blame] | 233 | ssl_certificate_verification => false |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 234 | hosts => ["${elasticsearch_base_url}"] |
osgn422w | 6e663e4 | 2019-08-02 11:31:11 +0200 | [diff] [blame] | 235 | user => ["${logstash_user}"] |
| 236 | password => ["${logstash_pwd}"] |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 237 | index => "errors-%{+YYYY.MM.DD}" |
| 238 | doc_as_upsert => true |
| 239 | } |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 240 | |
| 241 | } else if "event-cl-aggs" in [tags] { |
| 242 | elasticsearch { |
osgn422w | 87d267d | 2020-09-26 11:38:01 +0200 | [diff] [blame] | 243 | ilm_enabled => false |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 244 | codec => "json" |
| 245 | hosts => ["${elasticsearch_base_url}"] |
osgn422w | 7981445 | 2020-09-25 02:28:02 +0200 | [diff] [blame] | 246 | {{- if .Values.global.aafEnabled }} |
| 247 | cacert => "{{ .Values.certInitializer.credsPath }}/{{ .Values.certInitializer.clamp_ca_certs_pem }}" |
| 248 | {{- else }} |
osgn422w | b561a59 | 2020-02-11 15:50:21 +0100 | [diff] [blame] | 249 | cacert => "/clamp-cert/ca-certs.pem" |
osgn422w | 7981445 | 2020-09-25 02:28:02 +0200 | [diff] [blame] | 250 | {{- end }} |
osgn422w | b561a59 | 2020-02-11 15:50:21 +0100 | [diff] [blame] | 251 | ssl_certificate_verification => false |
osgn422w | 6e663e4 | 2019-08-02 11:31:11 +0200 | [diff] [blame] | 252 | user => ["${logstash_user}"] |
| 253 | password => ["${logstash_pwd}"] |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 254 | document_id => "%{requestID}" |
| 255 | index => "events-cl-%{+YYYY.MM.DD}" # creates daily indexes for control loop |
| 256 | doc_as_upsert => true |
| 257 | action => "update" |
| 258 | } |
| 259 | |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 260 | } else { |
| 261 | elasticsearch { |
osgn422w | 87d267d | 2020-09-26 11:38:01 +0200 | [diff] [blame] | 262 | ilm_enabled => false |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 263 | codec => "json" |
| 264 | hosts => ["${elasticsearch_base_url}"] |
osgn422w | 7981445 | 2020-09-25 02:28:02 +0200 | [diff] [blame] | 265 | {{- if .Values.global.aafEnabled }} |
| 266 | cacert => "{{ .Values.certInitializer.credsPath }}/{{ .Values.certInitializer.clamp_ca_certs_pem }}" |
| 267 | {{- else }} |
osgn422w | b561a59 | 2020-02-11 15:50:21 +0100 | [diff] [blame] | 268 | cacert => "/clamp-cert/ca-certs.pem" |
osgn422w | 7981445 | 2020-09-25 02:28:02 +0200 | [diff] [blame] | 269 | {{- end }} |
osgn422w | b561a59 | 2020-02-11 15:50:21 +0100 | [diff] [blame] | 270 | ssl_certificate_verification => false |
osgn422w | 6e663e4 | 2019-08-02 11:31:11 +0200 | [diff] [blame] | 271 | user => ["${logstash_user}"] |
| 272 | password => ["${logstash_pwd}"] |
ac2550 | a0496b0 | 2018-09-20 14:57:22 +0200 | [diff] [blame] | 273 | index => "events-%{+YYYY.MM.DD}" # creates daily indexes |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 274 | doc_as_upsert => true |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 275 | } |
| 276 | } |
ac2550 | 8ac9717 | 2018-04-18 14:23:17 +0200 | [diff] [blame] | 277 | } |