forked from claranet/terraform-datadog-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.sh
executable file
·62 lines (55 loc) · 1.3 KB
/
utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
function goto_root() {
script_dir=$(dirname $0)
if [[ "$script_dir" == "." ]]; then
cd ..
else
cd "$(dirname $script_dir)"
fi
}
function init() {
set -euo pipefail
if [[ ${GITLAB_CI:-} == "true" ]]; then
set -x
fi
# MON-478 fix sort order behavior on case
export LC_COLLATE=C
goto_root
if ! [ -z ${1:-} ]; then
cd "$1"
fi
REPO="integrations"
if head -n1 ./README.md | grep -q -i monitors; then
REPO="monitors"
fi
}
function get_scope() {
TO_PARSE="./"
if [ ! -z ${1+x} ] && [ $1 != "." ]; then
TO_PARSE="$1"
fi
if [[ $TO_PARSE != ./* ]]; then
TO_PARSE="./${TO_PARSE}"
fi
echo $TO_PARSE
}
function list_dirs() {
echo ${1} | awk -F '/' '{$1=""; print $0}' | cut -c 2-
}
function browse_modules() {
find "$1" -name "$2" -exec dirname "{}" \; | sort -fdbiu
}
function get_name() {
regex='^[[:space:]]+name[[:space:]]+=[[:space:]]+"\$.*\[.*\][[:space:]]+(.*)"$'
if [[ "${1}" =~ ${regex} ]]; then
name="${BASH_REMATCH[1]}"
else
echo "Error: impossible to parse monitor name"
return 42
fi
if [[ "${name}" =~ ^(.*)[[:space:]]\{\{#is_alert\}\}.*$ ]]; then
name="${BASH_REMATCH[1]}"
fi
echo $name
return 0
}