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
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for match in $(grep name $(basename ${path})); do
echo "- $(get_name "${match}")" >> README.md
for match in $(grep -E ^[[:space:]]+name[[:space:]]+= $(basename ${path})); do
name=$(get_name "${match}")
echo "- $name" >> README.md
done
IFS=$SAVEIFS
terraform-docs md ./ >> README.md

View File

@ -18,11 +18,12 @@ function get_name {
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
echo "${BASH_REMATCH[1]}"
else
echo $name
name="${BASH_REMATCH[1]}"
fi
echo $name
return 0
}