demx8as6 | 20f0c4e | 2022-09-24 14:01:27 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ################################################################################ |
| 3 | # |
| 4 | # Copyright 2022 highstreet technologies GmbH and others |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | |
| 18 | ################################################################################ |
| 19 | # Script to send an VES Message Event to DCAE |
| 20 | |
| 21 | . config; |
| 22 | pnfType=${1,,}; |
| 23 | alarmType=$2; |
| 24 | severity=$3; |
| 25 | raised=$4; |
| 26 | domain="stndDefined"; |
| 27 | |
| 28 | # exception for controller alarms |
| 29 | if [ "${pnfType^^}" == "SDNR" ] |
| 30 | then |
| 31 | eventType="ONAP_SDNR_Controller"; |
| 32 | fi |
| 33 | |
| 34 | if [ "${raised,,}" != "cleared" ] |
| 35 | then |
| 36 | raised="new"; |
| 37 | fi |
| 38 | |
| 39 | declare -A mapping=( |
| 40 | [domain]=$domain |
| 41 | [controllerName]=$(hostname --fqdn) |
| 42 | [pnfId]=${pnfIdByType[$pnfType]} |
| 43 | [eventId]="${pnfIdByType[$pnfType]}_${interfaceByType[$pnfType]}_${alarmType}" |
| 44 | [eventType]=${eventType} |
| 45 | [type]=${pnfType^^} |
| 46 | [interface]=${interfaceByType[$pnfType]} |
| 47 | [alarm]=${alarmType} |
| 48 | [severity]=${severity} |
| 49 | [timestamp]=${timestamp} |
| 50 | [eventTime]=${eventTime} |
| 51 | [vendor]=${vendorsByType[$pnfType]^^} |
| 52 | [model]=${modelByType[$pnfType]} |
| 53 | ) |
| 54 | |
| 55 | echo "################################################################################"; |
| 56 | echo "# send NotifyNewAlarm or NotifyClearedAlarm"; |
| 57 | echo; |
| 58 | for key in "${!mapping[@]}" |
| 59 | do |
| 60 | #label=${${"$spaces$i"}:(-14)}; |
| 61 | label=$spaces$key; |
| 62 | label=${label:(-16)}; |
| 63 | echo "$label: ${mapping[$key]}"; |
| 64 | if [ $key = "timestamp" ]; then |
| 65 | sequence="$sequence s/\"@$key@\"/${mapping[$key]}/g; " |
| 66 | else |
| 67 | sequence="$sequence s/@$key@/${mapping[$key]}/g; " |
| 68 | fi |
| 69 | done |
| 70 | echo; |
| 71 | |
| 72 | body="./json/examples/${pnfType^^}-${alarmType}-${severity}-${raised,,}-${domain}.json" |
| 73 | template="./json/templates/$domain-r16-notify-${raised,,}-alarm.json" |
| 74 | sed -e "$sequence" $template > $body; |
| 75 | |
| 76 | curl -i -k -u $basicAuthVes -X POST -d @${body} --header "Content-Type: application/json" $urlVes |
| 77 | |
| 78 | #curl -i -k -u "sample1:sample1" -X POST -d @./json/examples/NSKY-lossOfSignal-CRITICAL-stndDefined.json --header "Content-Type: application/json" https://localhost:8443/eventListener/v7 |