amtool: error: [GET /alerts][400] getAlertsBadRequest matcher value contains unescaped double quote: instance=~".+rem-prod.+" team="OMNR2"

125 views
Skip to first unread message

Evelyn Pereira Souza

unread,
Jun 6, 2022, 12:11:27 PM6/6/22
to Prometheus Users
Hi

I get this error with "amtool"

amtool: error: [GET /alerts][400] getAlertsBadRequest matcher value
contains unescaped double quote: instance=~".+rem-prod.+" team="OMNR2"

This the relevant snippet

QUERY_STRING='instance=~".+rem-prod.+" team="OMNR2"'


COUNTER=0
until [[ -z $ALERTS ]]
do
ALERTS=$("${WORKSPACE}"/amtool --tls.insecure.skip.verify
--alertmanager.url="$ENDPOINT" -o extended alert query "$QUERY_STRING" |
grep -w active)
[[ $COUNTER -gt 600 ]] && echo "(..)
done

kind regards
Evelyn
OpenPGP_0x61776FA8E38403FB.asc
OpenPGP_signature

Brian Candler

unread,
Jun 6, 2022, 1:11:46 PM6/6/22
to Prometheus Users
This isn't promQL, although it's similar. It appears that amtool isn't happy with matchers that have two conditions with double quotes:

# /opt/alertmanager/amtool --alertmanager.url="$ENDPOINT" alert query 'foo=~"bar" baz=~"qux"'
amtool: error: [GET /alerts][400] getAlertsBadRequest  matcher value contains unescaped double quote: foo=~"bar" baz=~"qux"


I suggest you try simply removing the double quotes from your amtool query:
QUERY_STRING='instance=~".+rem-prod.+" team="OMNR2"'
=>
QUERY_STRING='instance=~.+rem-prod.+ team=OMNR2'

Ref:

Evelyn Pereira Souza

unread,
Jun 9, 2022, 7:16:19 AM6/9/22
to promethe...@googlegroups.com
On 06.06.22 19:11, Brian Candler wrote:
> I suggest you try simply removing the double quotes from your amtool query:

Thanks. That solved the issue.

kind regards
Evelyn
OpenPGP_0x61776FA8E38403FB.asc
OpenPGP_signature

Brian Candler

unread,
Jun 9, 2022, 9:43:09 AM6/9/22
to Prometheus Users
I think I see the problem now.  Each query term has to be a separate argument on the command line.

/opt/alertmanager/amtool --alertmanager.url="$ENDPOINT" alert query 'alertname=DiskFull95 alertname=DiskFull95'   # does not work (no results; I think it treats this as alertname="DiskFull95 alertname=DiskFull95")
/opt/alertmanager/amtool --alertmanager.url="$ENDPOINT" alert query 'alertname=DiskFull95' 'alertname=DiskFull95'  # works

Hence this works:

/opt/alertmanager/amtool --alertmanager.url="$ENDPOINT" alert query 'alertname=~"Disk.+"' 'alertname=~".+Full.+"'

Since you put
    amtool ... alert query "$QUERY_STRING"
then the multi-word value is passed as a single argument.

Removing the quotes will allow the shell to split it and pass it as separate arguments:
    amtool ... alert query $QUERY_STRING

Tested:

QUERY_STRING='alertname=~"Disk.+" alertname=~".+Full.+"'
/opt/alertmanager/amtool --alertmanager.url="$ENDPOINT" alert query "$QUERY_STRING"  # does not work (error about unescaped quotes)
/opt/alertmanager/amtool --alertmanager.url="$ENDPOINT" alert query $QUERY_STRING  # works
Reply all
Reply to author
Forward
0 new messages