|
|
|
|
@ -53,8 +53,8 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr) |
|
|
|
|
// nolint
|
|
|
|
|
resp := postRequest(t, testReceiversURL, `{ |
|
|
|
|
"receivers": [] |
|
|
|
|
}`, http.StatusBadRequest) |
|
|
|
|
"receivers": [] |
|
|
|
|
}`, http.StatusBadRequest) |
|
|
|
|
t.Cleanup(func() { |
|
|
|
|
err := resp.Body.Close() |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
@ -84,27 +84,27 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
mockEmails := &mockEmailHandler{} |
|
|
|
|
env.NotificationService.EmailHandler = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
env.NotificationService.EmailHandlerSync = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
|
|
|
|
|
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr) |
|
|
|
|
// nolint
|
|
|
|
|
resp := postRequest(t, testReceiversURL, `{ |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": { |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusOK) |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": { |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusOK) |
|
|
|
|
t.Cleanup(func() { |
|
|
|
|
err := resp.Body.Close() |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
@ -119,28 +119,28 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
require.Len(t, result.Receivers[0].Configs, 1) |
|
|
|
|
|
|
|
|
|
expectedJSON := fmt.Sprintf(`{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "ok" |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "ok" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
result.Receivers[0].Configs[0].UID, |
|
|
|
|
result.NotifiedAt.Format(time.RFC3339Nano)) |
|
|
|
|
require.JSONEq(t, expectedJSON, string(b)) |
|
|
|
|
@ -168,25 +168,25 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
mockEmails := &mockEmailHandler{} |
|
|
|
|
env.NotificationService.EmailHandler = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
env.NotificationService.EmailHandlerSync = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
|
|
|
|
|
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr) |
|
|
|
|
// nolint
|
|
|
|
|
resp := postRequest(t, testReceiversURL, `{ |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": {}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusBadRequest) |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": {}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusBadRequest) |
|
|
|
|
t.Cleanup(func() { |
|
|
|
|
require.NoError(t, resp.Body.Close()) |
|
|
|
|
}) |
|
|
|
|
@ -200,29 +200,29 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
require.Len(t, result.Receivers[0].Configs, 1) |
|
|
|
|
|
|
|
|
|
expectedJSON := fmt.Sprintf(`{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "failed", |
|
|
|
|
"error": "the receiver is invalid: failed to validate receiver \"receiver-1\" of type \"email\": could not find addresses in settings" |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "failed", |
|
|
|
|
"error": "the receiver is invalid: failed to validate receiver \"receiver-1\" of type \"email\": could not find addresses in settings" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
result.Receivers[0].Configs[0].UID, |
|
|
|
|
result.NotifiedAt.Format(time.RFC3339Nano)) |
|
|
|
|
require.JSONEq(t, expectedJSON, string(b)) |
|
|
|
|
@ -249,26 +249,26 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
mockEmails := &mockEmailHandlerWithTimeout{ |
|
|
|
|
timeout: 5 * time.Second, |
|
|
|
|
} |
|
|
|
|
env.NotificationService.EmailHandler = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
env.NotificationService.EmailHandlerSync = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
|
|
|
|
|
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr) |
|
|
|
|
req, err := http.NewRequest(http.MethodPost, testReceiversURL, strings.NewReader(`{ |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": { |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`)) |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": { |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`)) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
req.Header.Set("Content-Type", "application/json") |
|
|
|
|
req.Header.Set("Request-Timeout", "1") |
|
|
|
|
@ -289,29 +289,29 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
require.Len(t, result.Receivers[0].Configs, 1) |
|
|
|
|
|
|
|
|
|
expectedJSON := fmt.Sprintf(`{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "failed", |
|
|
|
|
"error": "the receiver timed out: context deadline exceeded" |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "failed", |
|
|
|
|
"error": "the receiver timed out: context deadline exceeded" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
result.Receivers[0].Configs[0].UID, |
|
|
|
|
result.NotifiedAt.Format(time.RFC3339Nano)) |
|
|
|
|
require.JSONEq(t, expectedJSON, string(b)) |
|
|
|
|
@ -338,38 +338,38 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
mockEmails := &mockEmailHandlerWithTimeout{ |
|
|
|
|
timeout: 5 * time.Second, |
|
|
|
|
} |
|
|
|
|
env.NotificationService.EmailHandler = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
env.NotificationService.EmailHandlerSync = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
|
|
|
|
|
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr) |
|
|
|
|
req, err := http.NewRequest(http.MethodPost, testReceiversURL, strings.NewReader(`{ |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": {}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}, { |
|
|
|
|
"name":"receiver-2", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-2", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": { |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`)) |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": {}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}, { |
|
|
|
|
"name":"receiver-2", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid": "", |
|
|
|
|
"name": "receiver-2", |
|
|
|
|
"type": "email", |
|
|
|
|
"disableResolveMessage": false, |
|
|
|
|
"settings": { |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields": {} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`)) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
req.Header.Set("Content-Type", "application/json") |
|
|
|
|
req.Header.Set("Request-Timeout", "1") |
|
|
|
|
@ -391,39 +391,39 @@ func TestTestReceivers(t *testing.T) { |
|
|
|
|
require.Len(t, result.Receivers[1].Configs, 1) |
|
|
|
|
|
|
|
|
|
expectedJSON := fmt.Sprintf(`{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "failed", |
|
|
|
|
"error": "the receiver is invalid: failed to validate receiver \"receiver-1\" of type \"email\": could not find addresses in settings" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}, { |
|
|
|
|
"name":"receiver-2", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-2", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "failed", |
|
|
|
|
"error": "the receiver timed out: context deadline exceeded" |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "failed", |
|
|
|
|
"error": "the receiver is invalid: failed to validate receiver \"receiver-1\" of type \"email\": could not find addresses in settings" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}, { |
|
|
|
|
"name":"receiver-2", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-2", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "failed", |
|
|
|
|
"error": "the receiver timed out: context deadline exceeded" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
result.Receivers[0].Configs[0].UID, |
|
|
|
|
result.Receivers[1].Configs[0].UID, |
|
|
|
|
result.NotifiedAt.Format(time.RFC3339Nano)) |
|
|
|
|
@ -451,36 +451,36 @@ func TestTestReceiversAlertCustomization(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
mockEmails := &mockEmailHandler{} |
|
|
|
|
env.NotificationService.EmailHandler = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
env.NotificationService.EmailHandlerSync = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
|
|
|
|
|
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr) |
|
|
|
|
// nolint
|
|
|
|
|
resp := postRequest(t, testReceiversURL, `{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"annotation1": "value1", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"label1": "value1" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid":"", |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"type":"email", |
|
|
|
|
"disableResolveMessage":false, |
|
|
|
|
"settings":{ |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields":{} |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"annotation1": "value1", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"label1": "value1" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusOK) |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid":"", |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"type":"email", |
|
|
|
|
"disableResolveMessage":false, |
|
|
|
|
"settings":{ |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields":{} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusOK) |
|
|
|
|
t.Cleanup(func() { |
|
|
|
|
err := resp.Body.Close() |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
@ -495,30 +495,30 @@ func TestTestReceiversAlertCustomization(t *testing.T) { |
|
|
|
|
require.Len(t, result.Receivers[0].Configs, 1) |
|
|
|
|
|
|
|
|
|
expectedJSON := fmt.Sprintf(`{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"annotation1": "value1", |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana", |
|
|
|
|
"label1": "value1" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "ok" |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"annotation1": "value1", |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana", |
|
|
|
|
"label1": "value1" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "ok" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
result.Receivers[0].Configs[0].UID, |
|
|
|
|
result.NotifiedAt.Format(time.RFC3339Nano)) |
|
|
|
|
require.JSONEq(t, expectedJSON, string(b)) |
|
|
|
|
@ -546,33 +546,33 @@ func TestTestReceiversAlertCustomization(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
mockEmails := &mockEmailHandler{} |
|
|
|
|
env.NotificationService.EmailHandler = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
env.NotificationService.EmailHandlerSync = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
|
|
|
|
|
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr) |
|
|
|
|
// nolint
|
|
|
|
|
resp := postRequest(t, testReceiversURL, `{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "This is a custom annotation", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid":"", |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"type":"email", |
|
|
|
|
"disableResolveMessage":false, |
|
|
|
|
"settings":{ |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields":{} |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "This is a custom annotation", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusOK) |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid":"", |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"type":"email", |
|
|
|
|
"disableResolveMessage":false, |
|
|
|
|
"settings":{ |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields":{} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusOK) |
|
|
|
|
t.Cleanup(func() { |
|
|
|
|
err := resp.Body.Close() |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
@ -587,28 +587,28 @@ func TestTestReceiversAlertCustomization(t *testing.T) { |
|
|
|
|
require.Len(t, result.Receivers[0].Configs, 1) |
|
|
|
|
|
|
|
|
|
expectedJSON := fmt.Sprintf(`{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "This is a custom annotation", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "ok" |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "This is a custom annotation", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "TestAlert", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "ok" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
result.Receivers[0].Configs[0].UID, |
|
|
|
|
result.NotifiedAt.Format(time.RFC3339Nano)) |
|
|
|
|
require.JSONEq(t, expectedJSON, string(b)) |
|
|
|
|
@ -636,32 +636,32 @@ func TestTestReceiversAlertCustomization(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
mockEmails := &mockEmailHandler{} |
|
|
|
|
env.NotificationService.EmailHandler = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
env.NotificationService.EmailHandlerSync = mockEmails.sendEmailCommandHandlerSync |
|
|
|
|
|
|
|
|
|
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr) |
|
|
|
|
// nolint
|
|
|
|
|
resp := postRequest(t, testReceiversURL, `{ |
|
|
|
|
"alert": { |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "This is a custom label" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid":"", |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"type":"email", |
|
|
|
|
"disableResolveMessage":false, |
|
|
|
|
"settings":{ |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields":{} |
|
|
|
|
"alert": { |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "This is a custom label" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusOK) |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"uid":"", |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"type":"email", |
|
|
|
|
"disableResolveMessage":false, |
|
|
|
|
"settings":{ |
|
|
|
|
"addresses":"example@email.com" |
|
|
|
|
}, |
|
|
|
|
"secureFields":{} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}] |
|
|
|
|
}`, http.StatusOK) |
|
|
|
|
t.Cleanup(func() { |
|
|
|
|
err := resp.Body.Close() |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
@ -676,28 +676,28 @@ func TestTestReceiversAlertCustomization(t *testing.T) { |
|
|
|
|
require.Len(t, result.Receivers[0].Configs, 1) |
|
|
|
|
|
|
|
|
|
expectedJSON := fmt.Sprintf(`{ |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "This is a custom label", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "ok" |
|
|
|
|
"alert": { |
|
|
|
|
"annotations": { |
|
|
|
|
"summary": "Notification test", |
|
|
|
|
"__value_string__": "[ metric='foo' labels={instance=bar} value=10 ]" |
|
|
|
|
}, |
|
|
|
|
"labels": { |
|
|
|
|
"alertname": "This is a custom label", |
|
|
|
|
"instance": "Grafana" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
}, |
|
|
|
|
"receivers": [{ |
|
|
|
|
"name":"receiver-1", |
|
|
|
|
"grafana_managed_receiver_configs": [ |
|
|
|
|
{ |
|
|
|
|
"name": "receiver-1", |
|
|
|
|
"uid": "%s", |
|
|
|
|
"status": "ok" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}], |
|
|
|
|
"notified_at": "%s" |
|
|
|
|
}`, |
|
|
|
|
result.Receivers[0].Configs[0].UID, |
|
|
|
|
result.NotifiedAt.Format(time.RFC3339Nano)) |
|
|
|
|
require.JSONEq(t, expectedJSON, string(b)) |
|
|
|
|
@ -744,7 +744,7 @@ func TestNotificationChannels(t *testing.T) { |
|
|
|
|
channels.ThreemaGwBaseURL = fmt.Sprintf("http://%s/threema_recv/threema_test", mockChannel.server.Addr) |
|
|
|
|
channels.GetBoundary = func() string { return "abcd" } |
|
|
|
|
|
|
|
|
|
env.NotificationService.EmailHandler = mockEmail.sendEmailCommandHandlerSync |
|
|
|
|
env.NotificationService.EmailHandlerSync = mockEmail.sendEmailCommandHandlerSync |
|
|
|
|
// As we are using a NotificationService mock here, but he test expects real NotificationService -
|
|
|
|
|
// we try to issue a real POST request here
|
|
|
|
|
env.NotificationService.WebhookHandler = func(_ context.Context, cmd *models.SendWebhookSync) error { |
|
|
|
|
|