diff --git a/contracts/ee_monitoring_service_contracts.go b/contracts/ee_monitoring_service_contracts.go index 94e7ba3..17062d2 100644 --- a/contracts/ee_monitoring_service_contracts.go +++ b/contracts/ee_monitoring_service_contracts.go @@ -13,9 +13,10 @@ type IncidentDetails struct { } type SeverityUpdateRequestMetaData struct { - OldSeverity SeverityInfo `json:"oldSeverity"` - NewSeverity SeverityInfo `json:"newSeverity"` - UpdatedBy string `json:"updatedBy"` + CurrentSeverity SeverityInfo `json:"currentSeverity"` + UpdatedBy string `json:"updatedBy"` + ResponderTeam string `json:"responderTeam"` + SlackChannelId string `json:"slackChannelId"` } type SeverityInfo struct { diff --git a/pkg/monitoringService/ee_monitoring_service_client.go b/pkg/monitoringService/ee_monitoring_service_client.go index 2ac1ae6..13c594f 100644 --- a/pkg/monitoringService/ee_monitoring_service_client.go +++ b/pkg/monitoringService/ee_monitoring_service_client.go @@ -24,7 +24,9 @@ func (client *EEMonitoringServiceClientImpl) TriggerSeverityUpdateWebhook( incidentId uint, triggerredBy string, requestId string, - oldSeverity, newSeverity contracts.SeverityInfo, + 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 @@ -39,9 +41,10 @@ func (client *EEMonitoringServiceClientImpl) TriggerSeverityUpdateWebhook( } metaData := contracts.SeverityUpdateRequestMetaData{ - OldSeverity: oldSeverity, - NewSeverity: newSeverity, - UpdatedBy: triggerredBy, + CurrentSeverity: currentSeverity, + UpdatedBy: triggerredBy, + ResponderTeam: responderTeam, + SlackChannelId: slackChannelId, } requestBody := contracts.SeverityUpdateWebhookRequest{ Requester: "HOUSTON", diff --git a/pkg/monitoringService/ee_monitoring_service_client_interface.go b/pkg/monitoringService/ee_monitoring_service_client_interface.go index 31cad65..c868017 100644 --- a/pkg/monitoringService/ee_monitoring_service_client_interface.go +++ b/pkg/monitoringService/ee_monitoring_service_client_interface.go @@ -8,7 +8,8 @@ import ( type EEMonitoringServiceClient interface { TriggerSeverityUpdateWebhook( - incidentId uint, triggerredBy string, requestId string, oldSeverity, newSeverity contracts.SeverityInfo, + incidentId uint, triggerredBy string, requestId string, currentSeverity contracts.SeverityInfo, + responderTeam string, slackChannelId string, ) error } diff --git a/pkg/monitoringService/ee_monitoring_service_client_test.go b/pkg/monitoringService/ee_monitoring_service_client_test.go index f16704b..a984e49 100644 --- a/pkg/monitoringService/ee_monitoring_service_client_test.go +++ b/pkg/monitoringService/ee_monitoring_service_client_test.go @@ -53,7 +53,7 @@ func (suite *EEMonitoringServiceSuite) Test_TriggerWebhook_ErrorResponseCase() { defer close(responseChannel) err := NewEEMonitoringServiceClient(restClient).TriggerSeverityUpdateWebhook( - 1, "test", requestId, getOldSeverity(), getNewSeverity(), + 1, "test", requestId, getCurrentSeverity(), "Houston-testing", "slack-channel", ) suite.Error(err) } @@ -85,7 +85,7 @@ func (suite *EEMonitoringServiceSuite) Test_TriggerWebhook_SuccessCase() { responseChannel := make(chan service.MonitoringServiceClientResponse) defer close(responseChannel) err := NewEEMonitoringServiceClient(restClient).TriggerSeverityUpdateWebhook( - 1, "test", requestId, getOldSeverity(), getNewSeverity(), + 1, "test", requestId, getCurrentSeverity(), "Houston-testing", "slack-channel", ) suite.Nil(err) @@ -97,9 +97,10 @@ func getRequestBody() *contracts.SeverityUpdateWebhookRequest { IncidentID: 1, } metaData := contracts.SeverityUpdateRequestMetaData{ - OldSeverity: getOldSeverity(), - NewSeverity: getNewSeverity(), - UpdatedBy: "test", + CurrentSeverity: getCurrentSeverity(), + UpdatedBy: "test", + ResponderTeam: "Houston-testing", + SlackChannelId: "slack-channel", } return &contracts.SeverityUpdateWebhookRequest{ Requester: "HOUSTON", @@ -109,11 +110,8 @@ func getRequestBody() *contracts.SeverityUpdateWebhookRequest { } } -func getOldSeverity() contracts.SeverityInfo { - return contracts.SeverityInfo{Name: "Sev-1", ID: 2} -} -func getNewSeverity() contracts.SeverityInfo { - return contracts.SeverityInfo{Name: "Sev-0", ID: 1} +func getCurrentSeverity() contracts.SeverityInfo { + return contracts.SeverityInfo{Name: "Sev-0", ID: 2} } func TestEEMonitoringServiceClient(t *testing.T) { diff --git a/service/incident/impl/incident_service_v2.go b/service/incident/impl/incident_service_v2.go index 5d17217..0b98da9 100644 --- a/service/incident/impl/incident_service_v2.go +++ b/service/incident/impl/incident_service_v2.go @@ -1428,8 +1428,6 @@ func (i *IncidentServiceV2) UpdateSeverityId( return nil } - oldSeverity := contracts.SeverityInfo{Name: incidentEntity.Severity.Name, ID: incidentEntity.SeverityId} - severityId, err := strconv.Atoi(request.SeverityId) if err != nil { logger.Error("String conversion to int failed in UpdateSeverityId for "+request.SeverityId, zap.Error(err)) @@ -1522,23 +1520,36 @@ func (i *IncidentServiceV2) UpdateSeverityId( }() } go i.SendAlert(incidentEntity) - i.eeMonitoringServiceWebhookCall(incidentEntity, oldSeverity) + go i.EeMonitoringServiceWebhookCall(incidentEntity) } } return nil } -func (i *IncidentServiceV2) eeMonitoringServiceWebhookCall( - incidentEntity *incident.IncidentEntity, oldSeverity contracts.SeverityInfo, +func (i *IncidentServiceV2) EeMonitoringServiceWebhookCall( + incidentEntity *incident.IncidentEntity, ) { task := func(ctx context.Context) error { updatedIncident, err := i.incidentRepository.FindIncidentById(incidentEntity.ID) if err != nil { return errors.New(fmt.Sprintf("error in fetching incident by id: %+v", err)) } - newSeverity := contracts.SeverityInfo{Name: updatedIncident.Severity.Name, ID: updatedIncident.SeverityId} + currentSeverity := contracts.SeverityInfo{Name: updatedIncident.Severity.Name, ID: updatedIncident.SeverityId} + teamEntity, err := i.teamRepository.FindTeamById(updatedIncident.TeamId) + if err != nil { + return errors.New(fmt.Sprintf("error in fetching team by id: %+v", err)) + } + var triggerredBy = incidentEntity.UpdatedBy + if triggerredBy == "" || triggerredBy == "null" { + triggerredBy = incidentEntity.CreatedBy + } err = i.eeMonitoringServiceClient.TriggerSeverityUpdateWebhook( - incidentEntity.ID, incidentEntity.UpdatedBy, uuid.NewString(), oldSeverity, newSeverity, + incidentEntity.ID, + triggerredBy, + uuid.NewString(), + currentSeverity, + teamEntity.Name, + incidentEntity.SlackChannel, ) if err != nil { return errors.New(fmt.Sprintf("error in triggering severity update webhook: %+v", err)) diff --git a/service/incident/incident_service_v2_interface.go b/service/incident/incident_service_v2_interface.go index e3ae987..c79e847 100644 --- a/service/incident/incident_service_v2_interface.go +++ b/service/incident/incident_service_v2_interface.go @@ -41,4 +41,5 @@ type IIncidentService interface { CanUserWithEmailAccessIncidentWithId(userEmail string, incidentId uint) bool GetIncidentsByIds(incidentIds []uint) ([]incident.IncidentDTO, error) MoveIncidentsToInvestigating() error + EeMonitoringServiceWebhookCall(incidentEntity *incident.IncidentEntity) } diff --git a/service/orchestration/incident_orchestrator_impl.go b/service/orchestration/incident_orchestrator_impl.go index 9bf20c0..1b313f0 100644 --- a/service/orchestration/incident_orchestrator_impl.go +++ b/service/orchestration/incident_orchestrator_impl.go @@ -243,6 +243,7 @@ func (i *incidentOrchestratorImpl) CreateIncident( blazeGroupChannelID, ) }() + i.incidentService.EeMonitoringServiceWebhookCall(incidentEntity) incidentResponse := response.ConvertToIncidentResponse(*incidentEntity) return &incidentResponse, nil }