Skip to content

Commit

Permalink
Merge pull request #103 from devppratik/team-alerts-remove-silentTest
Browse files Browse the repository at this point in the history
OSD-15291: Excluded SilentTest Alerts when kite --assigned-to team is run
  • Loading branch information
openshift-merge-robot authored Mar 17, 2023
2 parents b5fb50b + 98f44cf commit 1a39c9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const (
// PagerDuty IDs
TeamID = "PASPK4G"
SilentTest = "P8QS6CC"
NobodySREP = "P53J4TK"

// Escalation Policy IDs
SilentTestEscalationPolicyID = "PCGXUDY"
CADSilentTestEscalationPolicyID = "PQXIBX3"
CADSilentTestStageEscalationPolicyID = "PBWX63A"

// PagerDuty Incident Statuses
StatusTriggered = "triggered"
Expand Down
20 changes: 18 additions & 2 deletions pkg/pdcli/alerts/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ var (
// GetIncidents returns a slice of pagerduty incidents.
func GetIncidents(c client.PagerDutyClient, opts *pdApi.ListIncidentsOptions) ([]pdApi.Incident, error) {
var aerr pdApi.APIError
var incidents []pdApi.Incident

// Check if incidents are fetched for a Team
isTeam := len(opts.TeamIDs) > 0

// Get incidents via pagerduty API
incidents, err := c.ListIncidents(*opts)
incidentsList, err := c.ListIncidents(*opts)

if err != nil {
if errors.As(err, &aerr) {
Expand All @@ -52,7 +56,19 @@ func GetIncidents(c client.PagerDutyClient, opts *pdApi.ListIncidentsOptions) ([
}
}

return incidents.Incidents, nil
for _, incident := range incidentsList.Incidents {
// When incidents are fetched for a team, do not include the incidents assigned to SilentTest
if isTeam && (incident.EscalationPolicy.ID == constants.SilentTestEscalationPolicyID ||
incident.EscalationPolicy.ID == constants.CADSilentTestEscalationPolicyID ||
incident.EscalationPolicy.ID == constants.CADSilentTestStageEscalationPolicyID ||
incident.Assignments[0].Assignee.ID == constants.SilentTest ||
incident.Assignments[0].Assignee.ID == constants.NobodySREP) {
continue
}
incidents = append(incidents, incident)
}

return incidents, nil
}

// GetIncidentAlerts returns all the alerts belonging to a particular incident.
Expand Down

0 comments on commit 1a39c9c

Please sign in to comment.