Hour time difference when calling Alertmanager silence API

232 views
Skip to first unread message

Danny de Waard

unread,
Mar 26, 2021, 7:06:07 AM3/26/21
to Prometheus Users
When i do a curl from mu RHEL machine to set a silence with curl like this:

curl -s -i -X POST -H "Content-Type: application/json" -d '{"comment": "testsilence for job KT3","createdBy": "DDW","startsAt": "'${startSilence}'","endsAt": "'${endSilence}'","matchers": [{"isRegex": false,"name": "job","value": "KT3"}]}' lsrv6003.linux.rabobank.nl:9093/api/v2/silences)

And the times are as following:

start: 2021-03-26T12:03:13Z
end: 2021-03-26T13:03:13Z

It shows pending in the GUI>

Starts at
12:03:13, 2021-03-26 (UTC)
Ends at
13:03:13, 2021-03-26 (UTC)
Updated at
11:03:13, 2021-03-26 (UTC)
Created by
DDW
Comment
testsilence for job KT3
State
pending

And the start time is set at script start so like this:

startSilence=`date +%Y-%m-%dT%H:%M:%SZ`
endSilence=`date -d '1 hour' +%Y-%m-%dT%H:%M:%SZ`

What am i missing?

If i subtract 1 hour from the start it shows as Active


David Leadbeater

unread,
Mar 26, 2021, 7:30:33 AM3/26/21
to Danny de Waard, Prometheus Users
On Fri, 26 Mar 2021 at 11:06, Danny de Waard <waa...@gmail.com> wrote:
[...]
startSilence=`date +%Y-%m-%dT%H:%M:%SZ`
endSilence=`date -d '1 hour' +%Y-%m-%dT%H:%M:%SZ`

What am i missing?

I think this is formatting it as UTC time but actually is in your local timezone.

Try something like:

startSilence=`TZ=UTC date +%Y-%m-%dT%H:%M:%SZ`

Danny de Waard

unread,
Mar 26, 2021, 7:53:46 AM3/26/21
to Prometheus Users
This works perfect Tnx!!

Op vrijdag 26 maart 2021 om 12:30:33 UTC+1 schreef d...@dgl.cx:
Reply all
Reply to author
Forward
0 new messages