Added docker-compose ranpm
[nonrtric/plt/ranpm.git] / docker-proj / scripts / push-to-ves-collector.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2023 Nordix Foundation. All rights reserved.
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 #  ============LICENSE_END=================================================
18 #
19
20 SD=$(dirname -- "$0")
21 echo "script-home: "$SD
22 cd $SD
23 CWD=$PWD
24
25 NODE_COUNT=$1
26 EVT_COUNT=$2
27 NODE_NAME_BASE=$3
28 FILE_EXT=$4
29 SRV_COUNT=$5
30
31 HTTPS_PORT=443
32
33 print_usage() {
34     echo "Usage: push-to-ves-collector.sh <node-count> <num-of-events> <node-name-base> <file-extension> <num-servers>"
35     exit 1
36 }
37 echo $@
38 if [ $# -lt 5 ]; then
39     print_usage
40 fi
41
42 rm .out.json
43 touch .out.json
44
45 BEGINTIME=1665146700
46 CURTIME=$BEGINTIME
47
48 for (( i=0; i<$EVT_COUNT; i++)); do
49
50     echo "EVENT BATCH: $i of $EVT_COUNT events for $NODE_COUNT NODES - 1 FILE PER EVENT"
51     echo '{"eventList": [' > .out.json
52     first=0
53
54     arch="$(uname -s)"
55     if [[ $arch == "Darwin"* ]]; then
56         ST=$(date -r $CURTIME +'%Y%m%d.%H%M')
57         let CURTIME=CURTIME+900
58         ET=$(date -r $CURTIME +'%H%M')
59     else
60         ST=$(date -d @$CURTIME +'%Y%m%d.%H%M')
61         let CURTIME=CURTIME+900
62         ET=$(date -d @$CURTIME +'%H%M')
63     fi
64
65     for (( j=0; j<$NODE_COUNT; j++)); do
66
67             NO="$NODE_NAME_BASE-$j"
68             #FN="A20000626.2315+0200-2330+0200_$NO-$i.$FILE_EXT"
69             FN="A$ST+0200-$ET+0200_$NO-$i.$FILE_EXT"
70             let SRV_ID=$j%$SRV_COUNT
71             let SRV_ID=SRV_ID+1
72             #echo "NODE "$NO
73             echo "FILENAME "$FN
74             SRV="pm-https-server-$SRV_ID"
75             echo "HTTP SERVER "$SRV
76             URL="https://$SRV:$HTTPS_PORT/files/$FN"
77             EVT='{"commonEventHeader":{"startEpochMicrosec":15198378,"eventId":"FileReady_1797490e-10ae-4d48-9ea7-3d7d790b25e1","timeZoneOffset":"UTC+05.30","internalHeaderFields":{"collectorTimeStamp":"Wed,0907202211:56:02GMT"},"priority":"Normal","version":"4.0.1","reportingEntityName":"'$NO'","sequence":0,"domain":"notification","lastEpochMicrosec":151983,"eventName":"Notification_gnb-Ericsson_FileReady","vesEventListenerVersion":"7.0.1","sourceName":"'$NO'"},"notificationFields":{"notificationFieldsVersion":"2.0","changeType":"FileReady","changeIdentifier":"PM_MEAS_FILES","arrayOfNamedHashMap":[{"name":"'$FN'","hashMap":{"location":"'$URL'","fileFormatType":"org.3GPP.32.435#measCollec","fileFormatVersion":"V10","compression":"gzip"}}]}}'
78             if [ $first -ne 0 ]; then
79                 echo "," >> .out.json
80             fi
81             first=1
82             echo "$EVT" >> .out.json
83     done
84     echo ']}' >> .out.json
85     RES=$(curl -s -X POST 'localhost:8080/eventListener/v7/eventBatch' --header 'Content-Type: application/json' --data-binary @.out.json)
86     echo $RES
87 done
88