blob: 534c220b3ad39965e3e97016e82f01fc8f8c3474 [file] [log] [blame]
santanudee1169f52021-05-13 20:11:38 +05301#!/bin/bash
santanudebc32a2a2021-09-24 17:47:31 +05302# Original work Copyright 2017-2018 AT&T Intellectual Property, Inc
3# Modified work Copyright 2021 Xoriant Corporation
santanudee1169f52021-05-13 20:11:38 +05304#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
santanudef22d9b52021-07-27 15:43:30 +053017# What this is: Startup script for the VES Collector running under docker.
18# the variables used below are now passed in as environmental variables
19# from the docker run command.
santanudee1169f52021-05-13 20:11:38 +053020cd /opt/ves
21touch monitor.log
22
23sed -i -- \
24 "s~log_file = /var/log/att/collector.log~log_file = /opt/ves/collector.log~" \
25 evel-test-collector/config/collector.conf
26sed -i -- "s/vel_domain = 127.0.0.1/vel_domain = $ves_host/g" \
27 evel-test-collector/config/collector.conf
28sed -i -- "s/vel_port = 30000/vel_port = $ves_port/g" \
29 evel-test-collector/config/collector.conf
30sed -i -- "s/vel_username =/vel_username = $ves_user/g" \
31 evel-test-collector/config/collector.conf
32sed -i -- "s/vel_password =/vel_password = $ves_pass/g" \
33 evel-test-collector/config/collector.conf
34sed -i -- "s~vel_path = vendor_event_listener/~vel_path = $ves_path~g" \
35 evel-test-collector/config/collector.conf
36sed -i -- "s~vel_topic_name = example_vnf~vel_topic_name = $ves_topic~g" \
37 evel-test-collector/config/collector.conf
38sed -i -- "/vel_topic_name = /a influxdb = $ves_influxdb_host:$ves_influxdb_port" \
39 evel-test-collector/config/collector.conf
40
41echo; echo "evel-test-collector/config/collector.conf"
42cat evel-test-collector/config/collector.conf
43
44echo; echo "wait for InfluxDB API at $ves_influxdb_host:$ves_influxdb_port"
45while ! curl http://$ves_influxdb_host:$ves_influxdb_port/ping ; do
46 echo "InfluxDB API is not yet responding... waiting 10 seconds"
47 sleep 10
48done
49
50echo; echo "setup veseventsdb in InfluxDB"
51# TODO: check if pre-existing and skip
52curl -X POST http://$ves_influxdb_host:$ves_influxdb_port/query \
53 --data-urlencode "q=CREATE DATABASE veseventsdb"
54
55echo; echo "wait for Grafana API to be active"
56while ! curl http://$ves_grafana_host:$ves_grafana_port ; do
57 echo "Grafana API is not yet responding... waiting 10 seconds"
58 sleep 10
59done
60
61echo; echo "add VESEvents datasource to Grafana"
62# TODO: check if pre-existing and skip
63cat <<EOF >/opt/ves/datasource.json
64{ "name":"VESEvents",
65 "type":"influxdb",
66 "access":"direct",
67 "url":"http://$ves_influxdb_host:$ves_influxdb_port",
68 "password":"root",
69 "user":"root",
70 "database":"veseventsdb",
71 "basicAuth":false,
72 "basicAuthUser":"",
73 "basicAuthPassword":"",
74 "withCredentials":false,
75 "isDefault":false,
76 "jsonData":null
77}
78EOF
79
80curl -H "Accept: application/json" -H "Content-type: application/json" \
81 -X POST -d @/opt/ves/datasource.json \
82 http://$ves_grafana_auth@$ves_grafana_host:$ves_grafana_port/api/datasources
83
84echo; echo "add VES dashboard to Grafana"
85curl -H "Accept: application/json" -H "Content-type: application/json" \
86 -X POST -d @/opt/ves/Dashboard.json \
santanudef22d9b52021-07-27 15:43:30 +053087 http://$ves_grafana_auth@$ves_grafana_host:$ves_grafana_port/api/dashboards/db
santanudee1169f52021-05-13 20:11:38 +053088
santanudef22d9b52021-07-27 15:43:30 +053089if [ "$ves_loglevel" != "" ]; then
90 python3 /opt/ves/evel-test-collector/code/collector/monitor.py \
santanudee1169f52021-05-13 20:11:38 +053091 --config /opt/ves/evel-test-collector/config/collector.conf \
92 --influxdb $ves_influxdb_host:$ves_influxdb_port \
93 --section default > /opt/ves/monitor.log 2>&1
94else
santanudef22d9b52021-07-27 15:43:30 +053095 python3 /opt/ves/evel-test-collector/code/collector/monitor.py \
santanudee1169f52021-05-13 20:11:38 +053096 --config /opt/ves/evel-test-collector/config/collector.conf \
97 --influxdb $ves_influxdb_host:$ves_influxdb_port \
98 --section default
99fi