diff --git a/CHANGELOG.md b/CHANGELOG.md
index d09255a69..9957ddd73 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,9 @@
configured by setting `silences:expired` option or `--silences.expired` flag.
Setting this value to `5m` will show silences if they expired in the last 5
minutes but only if the alert started firing at least 5 minutes ago.
+- `alertAcknowledgement:comment` will replace `%NOWLOC%` string with a timestamp
+ formatted using local time zone, use `%NOW%` for timestamps using `UTC` timezone,
+ #3704.
## v0.93
diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md
index 04de5dd75..31679d6ae 100644
--- a/docs/CONFIGURATION.md
+++ b/docs/CONFIGURATION.md
@@ -497,7 +497,8 @@ alertAcknowledgement:
- `author` - default author for acknowledgement silences. If user set the
author field on the silence form then that value will be used instead.
- `comment` - custom comment used for acknowledgement silences (optional).
- If the comment contains `%NOW%` it will be replaced by current timestamp.
+ If the comment contains `%NOW%` it will be replaced by current timestamp
+ with UTC timezone, to use timestamp with local timezone use `%NOWLOC%`.
Defaults:
diff --git a/ui/src/Components/AlertAck/index.test.tsx b/ui/src/Components/AlertAck/index.test.tsx
index 59a7769d1..a7e52c7a8 100644
--- a/ui/src/Components/AlertAck/index.test.tsx
+++ b/ui/src/Components/AlertAck/index.test.tsx
@@ -353,7 +353,7 @@ describe("", () => {
});
});
- it("injects timestamp when configured", async () => {
+ it("injects UTC timestamp when configured", async () => {
alertStore.settings.setValues({
...alertStore.settings.values,
...{
@@ -384,6 +384,28 @@ describe("", () => {
});
});
+ it("injects local timezone timestamp when configured", async () => {
+ alertStore.settings.setValues({
+ ...alertStore.settings.values,
+ ...{
+ alertAcknowledgement: {
+ enabled: true,
+ durationSeconds: 237,
+ author: "me",
+ comment: "ACK! This alert was acknowledged using karma on %NOWLOC%",
+ },
+ },
+ });
+ await MountAndClick();
+ const comment = JSON.parse((fetchMock.lastOptions() as any).body).comment;
+ expect(comment).not.toEqual(
+ "ACK! This alert was acknowledged using karma on Tue Feb 01 2000 00:00:00 GMT"
+ );
+ expect(comment).toMatch(
+ /ACK! This alert was acknowledged using karma on (Mon Jan 31 2000 19|Tue Feb 01 2000 00):00:00 GMT([+-]+)[0-9]+ \(.*\)/
+ );
+ });
+
it("uses author from authentication info when auth is enabled", async () => {
alertStore.info.setAuthentication(true, "auth@example.com");
alertStore.settings.setValues({
diff --git a/ui/src/Components/AlertAck/index.tsx b/ui/src/Components/AlertAck/index.tsx
index 20a2a64a7..951ca85f4 100644
--- a/ui/src/Components/AlertAck/index.tsx
+++ b/ui/src/Components/AlertAck/index.tsx
@@ -79,7 +79,9 @@ const AlertAck: FC<{
const now = new Date();
const comment = toJS(
alertStore.settings.values.alertAcknowledgement.comment
- ).replace("%NOW%", now.toUTCString());
+ )
+ .replace("%NOW%", now.toUTCString())
+ .replace("%NOWLOC%", now.toString());
c.push({
payload: GenerateAlertmanagerSilenceData(
now,