pagerduty

package
v0.0.0-...-b3b8b85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package pagerduty contains wrappers for pagerduty api calls

Index

Constants

View Source
const (
	// InvalidInputParamsErrorCode is exposed from the PagerDuty's API error response, used to distinguish between different error codes.
	// for more details see https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTYz-errors#pagerduty-error-codes
	InvalidInputParamsErrorCode = 2001

	// CADEmailAddress is the email address for the 'Configuration-Anomaly-Detection' PagerDuty User
	CADEmailAddress = "sd-sre-platform+pagerduty-configuration-anomaly-detection-agent@redhat.com"
	// CADIntegrationName is the name of the PD integration used to escalate alerts to Primary.
	CADIntegrationName = "Dead Man's Snitch"

	// IncidentResolved is an incident event type
	IncidentResolved = "incident.resolved"
	// IncidentTriggered is an incident event type
	IncidentTriggered = "incident.triggered"
	// IncidentEscalated is an incident event type
	IncidentEscalated = "incident.escalated"
	// IncidentReopened is an incident event type
	IncidentReopened = "incident.reopened"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertDetails

type AlertDetails struct {
	ID        string
	ClusterID string // This can be internal or external ID
}

AlertDetails exposes the required info we need from an alert

type Client

type Client interface {
	SilenceAlert() error
	SilenceAlertWithNote(notes string) error
	AddNote(notes string) error
	CreateNewAlert(newAlert NewAlert, serviceID string) error
	GetServiceID() string
	EscalateAlertWithNote(notes string) error
	EscalateAlert() error
}

Client is the interface exposing pagerduty functions

type CreateEventError

type CreateEventError struct {
	Err error
}

CreateEventError wraps the errors returned when failing to create a PagerDuty event

func (CreateEventError) Error

func (c CreateEventError) Error() string

Error prints the wrapped and original error

func (CreateEventError) Is

func (CreateEventError) Is(target error) bool

Is indicates whether the supplied error is a CreateEventError

type FileNotFoundError

type FileNotFoundError struct {
	Err      error
	FilePath string
}

FileNotFoundError wraps the filesystem NotFound Error

func (FileNotFoundError) Error

func (f FileNotFoundError) Error() string

Error prints the wrapped error and the original one

func (FileNotFoundError) Is

func (f FileNotFoundError) Is(target error) bool

Is ignores the internal error, thus making errors.Is work (as by default it compares the internal objects)

type IncidentData

type IncidentData struct {
	IncidentTitle  string // e.g. InfraNodesNeedResizingSRE CRITICAL (1)
	IncidentID     string // e.g. Q2I4AV3ZURABC
	IncidentRef    string // e.g. https://<>.pagerduty.com/incidents/Q2I4AV3ZURABC
	ServiceID      string // e.g. PCH1XGB
	ServiceSummary string // e.g. prod-deadmanssnitch
}

IncidentData represents the data contained in an incident

type IncidentNotFoundError

type IncidentNotFoundError struct {
	Err error
}

IncidentNotFoundError wraps the PagerDuty not found error while adding notes to an incident

func (IncidentNotFoundError) Error

func (i IncidentNotFoundError) Error() string

Error prints the wrapped error and the original one

func (IncidentNotFoundError) Is

func (IncidentNotFoundError) Is(target error) bool

Is ignores the internal error, thus making errors.Is work (as by default it compares the internal objects)

type IntegrationNotFoundError

type IntegrationNotFoundError struct {
	Err error
}

IntegrationNotFoundError wraps the errors returned when a PagerDuty service's integration cannot be found

func (IntegrationNotFoundError) Error

func (i IntegrationNotFoundError) Error() string

Error prints the wrapped and original error

func (IntegrationNotFoundError) Is

func (IntegrationNotFoundError) Is(target error) bool

Is indicates whether the supplied error is an IntegrationNotFoundError

type InvalidInputParamsError

type InvalidInputParamsError struct {
	Err error
}

InvalidInputParamsError wraps the PagerDuty Invalid parameters error TODO: the API also returns any other error in here, if this persists, think on renaming to "ClientMisconfiguration"

func (InvalidInputParamsError) Error

func (i InvalidInputParamsError) Error() string

Error prints the wrapped error and the original one

func (InvalidInputParamsError) Is

func (InvalidInputParamsError) Is(target error) bool

Is ignores the internal error, thus making errors.Is work (as by default it compares the internal objects)

type InvalidTokenError

type InvalidTokenError struct {
	Err error
}

InvalidTokenError wraps the PagerDuty token invalid error

func (InvalidTokenError) Error

func (i InvalidTokenError) Error() string

Error prints the wrapped error and the original one

func (InvalidTokenError) Is

func (InvalidTokenError) Is(target error) bool

Is ignores the internal error, thus making errors.Is work (as by default it compares the internal objects)

type NewAlert

type NewAlert struct {
	// The alert description acts as a title for the resulting incident
	Description string
	Details     NewAlertCustomDetails
}

NewAlert is a type for alerts to create on pagerduty

type NewAlertCustomDetails

type NewAlertCustomDetails struct {
	ClusterID  string `json:"Cluster ID"`
	Error      string `json:"Error"`
	Resolution string `json:"Resolution"`
	SOP        string `json:"SOP"`
}

NewAlertCustomDetails is a format for the alert details shown in the pagerduty incident

type SdkClient

type SdkClient struct {
	// contains filtered or unexported fields
}

SdkClient will hold all the required fields for any SdkClient Operation

func GetPDClient

func GetPDClient(webhookPayload []byte) (*SdkClient, error)

GetPDClient will retrieve the PagerDuty from the 'pagerduty' package

func NewWithToken

func NewWithToken(escalationPolicy string, silentPolicy string, webhookPayload []byte, authToken string, options ...sdk.ClientOptions) (*SdkClient, error)

NewWithToken initializes a new SdkClient The token can be created using the docs https://support.pagerduty.com/docs/api-access-keys#section-generate-a-user-token-rest-api-key

func (*SdkClient) AcknowledgeIncident

func (c *SdkClient) AcknowledgeIncident() error

AcknowledgeIncident will acknowledge an incident This is currently not needed by anything

func (*SdkClient) AddNote

func (c *SdkClient) AddNote(noteContent string) error

AddNote will add a note to the incident the client was initialized with

func (*SdkClient) AddNoteToIncident

func (c *SdkClient) AddNoteToIncident(incidentID string, noteContent string) error

AddNoteToIncident will add a note to an incident

func (*SdkClient) AssignToUser

func (c *SdkClient) AssignToUser(userID string) error

AssignToUser will assign the incident to the provided user This is currently not needed by anything

func (*SdkClient) CreateNewAlert

func (c *SdkClient) CreateNewAlert(newAlert NewAlert, serviceID string) error

CreateNewAlert triggers an alert using the Deadmanssnitch integration for the given service. If the provided service does not have a DMS integration, an error is returned

func (*SdkClient) EscalateAlert

func (c *SdkClient) EscalateAlert() error

EscalateAlert escalates the alert to the on call escalation policy

func (*SdkClient) EscalateAlertWithNote

func (c *SdkClient) EscalateAlertWithNote(notes string) error

EscalateAlertWithNote annotates the PagerDuty alert with the given notes and escalates it by assigning to the on call escalation policy

func (*SdkClient) GetAlertListDetails

func (c *SdkClient) GetAlertListDetails(alertList *[]sdk.IncidentAlert) ([]AlertDetails, error)

GetAlertListDetails will retrieve the required details for a list of alerts and return an array of alertDetails in the same order

func (*SdkClient) GetAlertsForIncident

func (c *SdkClient) GetAlertsForIncident(incidentID string) (*[]sdk.IncidentAlert, error)

GetAlertsForIncident gets all alerts that are part of an incident

func (*SdkClient) GetIncidentID

func (c *SdkClient) GetIncidentID() string

GetIncidentID returns the event type of the webhook

func (*SdkClient) GetIncidentRef

func (c *SdkClient) GetIncidentRef() string

GetIncidentRef returns a link to the pagerduty incident

func (*SdkClient) GetOnCallEscalationPolicy

func (c *SdkClient) GetOnCallEscalationPolicy() string

GetOnCallEscalationPolicy returns the set on call escalation policy

func (*SdkClient) GetServiceID

func (c *SdkClient) GetServiceID() string

GetServiceID returns the event type of the webhook

func (*SdkClient) GetServiceName

func (c *SdkClient) GetServiceName() string

GetServiceName returns the event type of the webhook

func (*SdkClient) GetSilentEscalationPolicy

func (c *SdkClient) GetSilentEscalationPolicy() string

GetSilentEscalationPolicy returns the set policy for silencing alerts

func (*SdkClient) GetTitle

func (c *SdkClient) GetTitle() string

GetTitle returns the event type of the webhook

func (*SdkClient) MoveToEscalationPolicy

func (c *SdkClient) MoveToEscalationPolicy(escalationPolicyID string) error

MoveToEscalationPolicy will move the incident's EscalationPolicy to the new EscalationPolicy

func (*SdkClient) ResolveIncident

func (c *SdkClient) ResolveIncident(incident *pagerduty.Incident) error

ResolveIncident resolves an incident

func (*SdkClient) RetrieveClusterID

func (c *SdkClient) RetrieveClusterID() (string, error)

RetrieveClusterID returns the clusterID for the current alert context of the SdkClient. The cluster id is not on the payload so the first time it is called it will retrieve the clusterID from pagerduty, and update the client.

func (*SdkClient) SetIncidentData

func (c *SdkClient) SetIncidentData(incidentData *IncidentData)

SetIncidentData sets the Client's incidentData

func (*SdkClient) SilenceAlert

func (c *SdkClient) SilenceAlert() error

SilenceAlert silences the alert by assigning the "Silent Test" escalation policy

func (*SdkClient) SilenceAlertWithNote

func (c *SdkClient) SilenceAlertWithNote(notes string) error

SilenceAlertWithNote annotates the PagerDuty alert with the given notes and silences it by assigning the "Silent Test" escalation policy

type ServiceNotFoundError

type ServiceNotFoundError struct {
	Err error
}

ServiceNotFoundError wraps the errors returned when PagerDuty services cannot be retrieved

func (ServiceNotFoundError) Error

func (s ServiceNotFoundError) Error() string

Error prints the wrapped and original error

func (ServiceNotFoundError) Is

func (ServiceNotFoundError) Is(target error) bool

Is indicates whether the supplied error is a ServiceNotFoundError

type UnmarshalError

type UnmarshalError struct {
	Err error
}

UnmarshalError wraps JSON's json.SyntaxError

func (UnmarshalError) Error

func (u UnmarshalError) Error() string

Error prints the wrapped error and the original one

func (UnmarshalError) Is

func (u UnmarshalError) Is(target error) bool

Is ignores the internal error, thus making errors.Is work (as by default it compares the internal objects)

Directories

Path Synopsis
Package pdmock is a generated GoMock package.
Package pdmock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL