Update documentation
[oam.git] / solution / dev / ves-test-collector / client-scripts-ves-v7 / sendTca.sh
1 #!/bin/bash
2 ################################################################################
3 #
4 # Copyright 2019 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 #     http://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              action=$3;
25              domain=thresholdCrossingAlert;
26 collectionTimestamp=$(date -u -R -d @$timeInS );:
27           time15min=$(( $timeInS - $(($timeInS % 900))));
28 eventStartTimestamp=$(date -u -R -d @$time15min );
29
30 declare -A severities=(
31     [clear]=NORMAL
32     [cont]=WARNING
33     [set]=WARNING
34 )
35          severity=${severities[${3,,}]};
36
37 declare -A mapping=(
38     [domain]=$domain
39     [controllerName]=$(hostname --fqdn)
40     [pnfId]=${pnfIdByType[$pnfType]}
41     [eventId]="${pnfIdByType[$pnfType]}_${interfaceByType[$pnfType]}_${alarmType}"
42     [eventType]=${eventType}
43     [type]=${pnfType^^}
44     [interface]=${interfaceByType[$pnfType]}
45     [alarm]=${alarmType}
46     [action]=${action}
47     [severity]=${severity}
48     [timestamp]=${timestamp}
49     [eventTime]=${eventTime}
50     [collectionTimestamp]=${collectionTimestamp}
51     [eventStartTimestamp]=${eventStartTimestamp}
52     [vendor]=${vendorsByType[$pnfType]^^}
53     [model]=${modelByType[$pnfType]}
54 )
55
56 echo "################################################################################";
57 echo "# send threshold crossed alert";
58 echo
59 for key in "${!mapping[@]}"
60 do
61   label=$spaces$key;
62   label=${label:(-20)};
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}-${action}-${domain}.json;
73 sed -e "$sequence" ./json/templates/$domain.json > $body;
74
75 curl -i -k -u $basicAuthVes -X POST -d  @${body} --header "Content-Type: application/json" $urlVes