How can pass variables to alertmanager rest api

49 views
Skip to first unread message

Vasily Reshetov

unread,
Sep 2, 2021, 5:55:42 AM9/2/21
to Prometheus Users
I am trying to use variables in "startsAt":  and  "endsAt ",  but I get the error parsing.
  Moreover, if I substitute the output of variables, there are no errors.
$mydate1=` date -u +"%Y-%m-%dT%H:%M:%SZ"
$mydate2=` date -u +"%Y-%m-%dT%H:%M:%SZ" --date '4 hours'

Example:
curl http://localhost:9093/api/v1/silences -d '{
      "matchers": [
        {
          "name": "instance",
          "value": "host1:9100",
          "isRegex": true
        }
      ],
      "startsAt": "$mydate1",
      "endsAt": "$mydate2",
      "createdBy": "api",
     "comment": "Silence",
      "status": {
        "state": "active"
      }
}'

Brian Candler

unread,
Sep 2, 2021, 7:57:08 AM9/2/21
to Prometheus Users
Try changing "curl" to "echo" and you'll see the problem.

The problem is with your shell command.  Anything inside single-quotes is not expanded - so $mydate remains as the literal string "$mydate"

Use double-quotes - in which case you'll need to escape the double-quotes inside the double-quotes with backslash.  Or use a real programming language.

Reply all
Reply to author
Forward
0 new messages