santanude | e1169f5 | 2021-05-13 20:11:38 +0530 | [diff] [blame] | 1 | #!/bin/bash |
santanude | bc32a2a | 2021-09-24 17:47:31 +0530 | [diff] [blame^] | 2 | # Original work Copyright 2017-2018 AT&T Intellectual Property, Inc |
| 3 | # Modified work Copyright 2021 Xoriant Corporation |
santanude | e1169f5 | 2021-05-13 20:11:38 +0530 | [diff] [blame] | 4 | # |
| 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 | # |
santanude | f22d9b5 | 2021-07-27 15:43:30 +0530 | [diff] [blame] | 17 | # 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. |
santanude | e1169f5 | 2021-05-13 20:11:38 +0530 | [diff] [blame] | 20 | cd /opt/ves |
| 21 | touch monitor.log |
| 22 | |
| 23 | sed -i -- \ |
| 24 | "s~log_file = /var/log/att/collector.log~log_file = /opt/ves/collector.log~" \ |
| 25 | evel-test-collector/config/collector.conf |
| 26 | sed -i -- "s/vel_domain = 127.0.0.1/vel_domain = $ves_host/g" \ |
| 27 | evel-test-collector/config/collector.conf |
| 28 | sed -i -- "s/vel_port = 30000/vel_port = $ves_port/g" \ |
| 29 | evel-test-collector/config/collector.conf |
| 30 | sed -i -- "s/vel_username =/vel_username = $ves_user/g" \ |
| 31 | evel-test-collector/config/collector.conf |
| 32 | sed -i -- "s/vel_password =/vel_password = $ves_pass/g" \ |
| 33 | evel-test-collector/config/collector.conf |
| 34 | sed -i -- "s~vel_path = vendor_event_listener/~vel_path = $ves_path~g" \ |
| 35 | evel-test-collector/config/collector.conf |
| 36 | sed -i -- "s~vel_topic_name = example_vnf~vel_topic_name = $ves_topic~g" \ |
| 37 | evel-test-collector/config/collector.conf |
| 38 | sed -i -- "/vel_topic_name = /a influxdb = $ves_influxdb_host:$ves_influxdb_port" \ |
| 39 | evel-test-collector/config/collector.conf |
| 40 | |
| 41 | echo; echo "evel-test-collector/config/collector.conf" |
| 42 | cat evel-test-collector/config/collector.conf |
| 43 | |
| 44 | echo; echo "wait for InfluxDB API at $ves_influxdb_host:$ves_influxdb_port" |
| 45 | while ! curl http://$ves_influxdb_host:$ves_influxdb_port/ping ; do |
| 46 | echo "InfluxDB API is not yet responding... waiting 10 seconds" |
| 47 | sleep 10 |
| 48 | done |
| 49 | |
| 50 | echo; echo "setup veseventsdb in InfluxDB" |
| 51 | # TODO: check if pre-existing and skip |
| 52 | curl -X POST http://$ves_influxdb_host:$ves_influxdb_port/query \ |
| 53 | --data-urlencode "q=CREATE DATABASE veseventsdb" |
| 54 | |
| 55 | echo; echo "wait for Grafana API to be active" |
| 56 | while ! curl http://$ves_grafana_host:$ves_grafana_port ; do |
| 57 | echo "Grafana API is not yet responding... waiting 10 seconds" |
| 58 | sleep 10 |
| 59 | done |
| 60 | |
| 61 | echo; echo "add VESEvents datasource to Grafana" |
| 62 | # TODO: check if pre-existing and skip |
| 63 | cat <<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 | } |
| 78 | EOF |
| 79 | |
| 80 | curl -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 | |
| 84 | echo; echo "add VES dashboard to Grafana" |
| 85 | curl -H "Accept: application/json" -H "Content-type: application/json" \ |
| 86 | -X POST -d @/opt/ves/Dashboard.json \ |
santanude | f22d9b5 | 2021-07-27 15:43:30 +0530 | [diff] [blame] | 87 | http://$ves_grafana_auth@$ves_grafana_host:$ves_grafana_port/api/dashboards/db |
santanude | e1169f5 | 2021-05-13 20:11:38 +0530 | [diff] [blame] | 88 | |
santanude | f22d9b5 | 2021-07-27 15:43:30 +0530 | [diff] [blame] | 89 | if [ "$ves_loglevel" != "" ]; then |
| 90 | python3 /opt/ves/evel-test-collector/code/collector/monitor.py \ |
santanude | e1169f5 | 2021-05-13 20:11:38 +0530 | [diff] [blame] | 91 | --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 |
| 94 | else |
santanude | f22d9b5 | 2021-07-27 15:43:30 +0530 | [diff] [blame] | 95 | python3 /opt/ves/evel-test-collector/code/collector/monitor.py \ |
santanude | e1169f5 | 2021-05-13 20:11:38 +0530 | [diff] [blame] | 96 | --config /opt/ves/evel-test-collector/config/collector.conf \ |
| 97 | --influxdb $ves_influxdb_host:$ves_influxdb_port \ |
| 98 | --section default |
| 99 | fi |