Add to_directory method to relevant object classes
[oam.git] / code / client-scripts-ves-v7 / sendStndDefinedNotifyAlarm.sh
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 echo "  alarmEventType: $raised"
59 for key in "${!mapping[@]}"
60 do
61   #label=${${"$spaces$i"}:(-14)};
62   label=$spaces$key;
63   label=${label:(-16)};
64   echo "$label: ${mapping[$key]}";
65   if [ $key = "timestamp" ]; then
66       sequence="$sequence s/\"@$key@\"/${mapping[$key]}/g; "
67   else
68       sequence="$sequence s/@$key@/${mapping[$key]}/g; "
69   fi
70 done
71 echo;
72
73 body="./json/examples/${pnfType^^}-${alarmType}-${severity}-${raised,,}-${domain}.json"
74 template="./json/templates/$domain-r16-notify-${raised,,}-alarm.json"
75 sed -e "$sequence" $template > $body;
76
77 curl -i -k -u $basicAuthVes -X POST -d @${body} --header "Content-Type: application/json" $urlVes