MON-259 use regex to avoid name matching

This commit is contained in:
Quentin Manfroi 2018-07-17 14:58:41 +02:00
parent 975587e9d2
commit eea3477acb
2 changed files with 7 additions and 5 deletions

View File

@ -53,8 +53,9 @@ Creates DataDog monitors with the following checks :
EOF EOF
SAVEIFS=$IFS SAVEIFS=$IFS
IFS=$(echo -en "\n\b") IFS=$(echo -en "\n\b")
for match in $(grep name $(basename ${path})); do for match in $(grep -E ^[[:space:]]+name[[:space:]]+= $(basename ${path})); do
echo "- $(get_name "${match}")" >> README.md name=$(get_name "${match}")
echo "- $name" >> README.md
done done
IFS=$SAVEIFS IFS=$SAVEIFS
terraform-docs md ./ >> README.md terraform-docs md ./ >> README.md

View File

@ -18,11 +18,12 @@ function get_name {
if [[ "${1}" =~ ${regex} ]]; then if [[ "${1}" =~ ${regex} ]]; then
name="${BASH_REMATCH[1]}" name="${BASH_REMATCH[1]}"
else else
echo "Error: impossible to parse monitor name"
return 42 return 42
fi fi
if [[ "${name}" =~ ^(.*)[[:space:]]\{\{#is_alert\}\}.*$ ]]; then if [[ "${name}" =~ ^(.*)[[:space:]]\{\{#is_alert\}\}.*$ ]]; then
echo "${BASH_REMATCH[1]}" name="${BASH_REMATCH[1]}"
else
echo $name
fi fi
echo $name
return 0
} }