blob: 6b478261e8daf88ec8f50b7f29e5ed6e55c5045c [file] [log] [blame]
garciadeblas0bc87522021-10-20 22:16:17 +02001#!/bin/bash
2# This file is meant to be SOURCED
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17function track(){
18# Tracks events by sending HTTP GET requests with query strings to a web server
garciadeblas8fed1082022-08-29 11:25:02 +020019# Input:
20# - First argument (mandatory): event name
21# - Rest of arguments:
22# - If they exist, they correspond to tuples of operation-value-comment-tags
23# - operation: particular operation in an event
24# - value: particular value for an operation
25# - comment
26# - none will be passed when empty
27# - will be parsed to replace spaces by underscores
28# - tags
29# - none will be passed when empty
30# - will be parsed to replace spaces by ~
31# - If no arguments:
32# - operation: like event
33# - value: ""
34# - comment: ""
35# - tags: ""
36# Output:
37# Sends as many HTTP requests as operations with the following query string
38# "&{OSM_TRACK_INSTALLATION_ID}&{TIMESTAMP}&{EVENT}&{OPERATION}&{VALUE}&{COMMENT}&{TAGS}"
39#
garciadeblas0bc87522021-10-20 22:16:17 +020040
41 if [ $# -lt 1 ]; then
42 echo "Unexpected error in track function. At least 1 arg is expected: event"
43 return 1
44 fi
45
46 osm_track_event_name=$1
47
48 ctime=`date +%s`
49
50 query_string=""
51 query_string="${query_string}&installation_id=${OSM_TRACK_INSTALLATION_ID}"
52 query_string="${query_string}&local_ts=${ctime}"
53 query_string="${query_string}&event=${osm_track_event_name}"
54
55 shift 1
56 if [ $# -eq 0 ]; then
57 operation="${osm_track_event_name}"
58 value=""
59 comment=""
60 tags=""
61 final_query_string="${query_string}"
62 final_query_string="${final_query_string}&operation=${operation}"
63 final_query_string="${final_query_string}&value=${value}"
64 final_query_string="${final_query_string}&comment=${comment}"
65 final_query_string="${final_query_string}&tags=${tags}"
66 url="https://osm.etsi.org/InstallLog.php?${final_query_string}"
67 echo "Track $osm_track_event_name $operation: ${url}"
garciadeblase572aab2022-01-14 11:19:16 +010068 LANG=C wget -q -O /dev/null "$url"
garciadeblas0bc87522021-10-20 22:16:17 +020069 else
70 while (( "$#" > 0 )); do
71 operation="${1:-${osm_track_event_name}}"
72 shift 1
73 value="${1:-}"
garciadeblas4d89c372021-11-25 11:57:18 +010074 value="${value// /_}"
garciadeblas0bc87522021-10-20 22:16:17 +020075 shift 1
76 comment="${1:-}"
garciadeblas0bc87522021-10-20 22:16:17 +020077 comment="${comment// /_}"
garciadeblas0bc87522021-10-20 22:16:17 +020078 shift 1
garciadeblas4d89c372021-11-25 11:57:18 +010079 tags="${1:-}"
garciadeblas0bc87522021-10-20 22:16:17 +020080 tags="${tags//,/\~}"
garciadeblas4d89c372021-11-25 11:57:18 +010081 shift 1
garciadeblas0bc87522021-10-20 22:16:17 +020082 [ "$value" == "none" ] && value=""
83 [ "$comment" == "none" ] && comment=""
84 [ "$tags" == "none" ] && tags=""
85 final_query_string="${query_string}"
86 final_query_string="${final_query_string}&operation=${operation}"
87 final_query_string="${final_query_string}&value=${value}"
88 final_query_string="${final_query_string}&comment=${comment}"
89 final_query_string="${final_query_string}&tags=${tags}"
90 url="https://osm.etsi.org/InstallLog.php?${final_query_string}"
91 echo "Track $osm_track_event_name $operation: ${url}"
garciadeblase572aab2022-01-14 11:19:16 +010092 LANG=C wget -q -O /dev/null "$url"
garciadeblas0bc87522021-10-20 22:16:17 +020093 done
94 fi
95 return 0
96}