70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package monitoringService
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"go.uber.org/zap"
|
|
"houston/contracts"
|
|
"houston/logger"
|
|
"houston/pkg/rest"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type EEMonitoringServiceClientImpl struct {
|
|
BaseURL string
|
|
Client rest.HttpRestClient
|
|
DefaultTimeout time.Duration
|
|
WebhookAPIPath string
|
|
}
|
|
|
|
func (client *EEMonitoringServiceClientImpl) TriggerSeverityUpdateWebhook(
|
|
incidentId uint,
|
|
triggerredBy string,
|
|
requestId string,
|
|
currentSeverity contracts.SeverityInfo,
|
|
responderTeam string,
|
|
slackChannelId string,
|
|
) error {
|
|
logger.Info(fmt.Sprintf("Triggering severity update webhook for requestId: %s", requestId))
|
|
fullURL := client.BaseURL + client.WebhookAPIPath
|
|
requestHeaders := map[string]string{
|
|
"Content-Type": "application/json",
|
|
"X-Correlation-Id": requestId,
|
|
"correlationId": requestId,
|
|
}
|
|
|
|
incidentDetails := contracts.IncidentDetails{
|
|
IncidentType: "HOUSTON",
|
|
IncidentID: incidentId,
|
|
}
|
|
|
|
metaData := contracts.SeverityUpdateRequestMetaData{
|
|
CurrentSeverity: currentSeverity,
|
|
UpdatedBy: triggerredBy,
|
|
ResponderTeam: responderTeam,
|
|
SlackChannelId: slackChannelId,
|
|
}
|
|
requestBody := contracts.SeverityUpdateWebhookRequest{
|
|
Requester: "HOUSTON",
|
|
RequestType: "HOUSTON_SEVERITY_UPDATE",
|
|
IncidentDetails: incidentDetails,
|
|
RequestMetaData: metaData,
|
|
}
|
|
payload, err := json.Marshal(requestBody)
|
|
if err != nil {
|
|
logger.Error("Error while marshalling request body", zap.Error(err))
|
|
return errors.New("error while marshalling request body")
|
|
}
|
|
|
|
response, err := client.Client.PostWithTimeout(fullURL, *bytes.NewBuffer(payload), requestHeaders,
|
|
client.DefaultTimeout, nil)
|
|
if err != nil || response.StatusCode != http.StatusOK {
|
|
logger.Error("Error while triggering webhook", zap.Error(err))
|
|
return errors.New("error while triggering webhook")
|
|
}
|
|
return nil
|
|
}
|