pagerduty

package
v1.20240719.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNon200Status ex.Class = "non-200 status code from remote"
	Err404Status    ex.Class = "404 status code from remote"
)

Errors

View Source
const (
	// DefaultAddr is the default api address.
	DefaultAddr = "https://api.pagerduty.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIObject added in v1.20210826.18

type APIObject struct {
	ID      string        `json:"id"`
	Type    ReferenceType `json:"type"`
	Summary string        `json:"summary,omitempty"`
	Self    string        `json:"self,omitempty"`
	HTMLUrl string        `json:"html_url,omitempty"`
}

APIObject represents generic api json response that is shared by most domain object

type APIReference added in v1.20210826.18

type APIReference struct {
	ID   string `json:"id,omitempty"`
	Type string `json:"type,omitempty"`
}

APIReference are the fields required to reference another API object.

type Acknowledgement

type Acknowledgement struct {
	At           time.Time `json:"at,omitempty"`
	Acknowledger APIObject `json:"acknowledger,omitempty"`
}

Acknowledgement is an api type.

type Action

type Action struct {
	Type string    `json:"type,omitempty"`
	At   time.Time `json:"at,omitempty"`
}

Action is an api type.

type ActiveBetween added in v1.20210826.18

type ActiveBetween struct {
	StartTime int `json:"start_time,omitempty"`
	EndTime   int `json:"end_time,omitempty"`
}

ActiveBetween represents an active_between object for setting a timeline for rules

type AlertGroupParamsConfig added in v1.20210826.18

type AlertGroupParamsConfig struct {
	Timeout   uint     `json:"timeout,omitempty"`
	Aggregate string   `json:"aggregate,omitempty"`
	Fields    []string `json:"fields,omitempty"`
}

AlertGroupParamsConfig is the config object on alert_grouping_parameters

type AlertGroupingParameters added in v1.20210826.18

type AlertGroupingParameters struct {
	Type   string                 `json:"type"`
	Config AlertGroupParamsConfig `json:"config"`
}

AlertGroupingParameters defines how alerts on the servicewill be automatically grouped into incidents

type Assignment

type Assignment struct {
	At       time.Time  `json:"at,omitempty"`
	Assignee *APIObject `json:"assignee"`
}

Assignment is an assignment.

type Body

type Body struct {
	Type    string `json:"type"`
	Details string `json:"details,omitempty"`
}

Body is an api type.

type Client

type Client interface {
	CreateIncident(context.Context, CreateIncidentInput) (Incident, error)
	UpdateIncident(context.Context, string, UpdateIncidentInput) (Incident, error)
	ListIncidents(context.Context, ...ListIncidentOption) (ListIncidentsOutput, error)
	GetService(context.Context, string) (Service, error)
}

Client is the interface pagerduty clients implement.

type ConditionParameter added in v1.20210826.18

type ConditionParameter struct {
	Path  string `json:"path,omitempty"`
	Value string `json:"value,omitempty"`
}

ConditionParameter represents parameters in a rule condition

type ConferenceBridge

type ConferenceBridge struct {
	ConferenceNumber string `json:"conference_number,omitempty"`
	ConferenceURL    string `json:"conference_url,omitempty"`
}

ConferenceBridge is an api type.

type Config

type Config struct {
	Addr  string `yaml:"addr,omitempty"`
	Token string `yaml:"token,omitempty"`
	Email string `yaml:"email,omitempty"`
}

Config is the pagerduty config.

func (Config) IsZero

func (c Config) IsZero() bool

IsZero returns if the config is set or not.

func (*Config) Resolve

func (c *Config) Resolve(ctx context.Context) error

Resolve resolves the config.

type CreateIncidentInput

type CreateIncidentInput struct {
	Type             string            `json:"type"`    // required
	Title            string            `json:"title"`   // required
	Service          APIObject         `json:"service"` /// required
	Priority         *APIObject        `json:"priority,omitempty"`
	Body             *Body             `json:"body,omitempty"`
	IncidentKey      string            `json:"incident_key,omitempty"`
	Assignments      []Assignment      `json:"assignments,omitempty"`
	EscalationPolicy *APIObject        `json:"escalation_policy,omitempty"`
	Urgency          Urgency           `json:"urgency,omitempty"`
	ConferenceBridge *ConferenceBridge `json:"conference_bridge,omitempty"`
}

CreateIncidentInput is the input to create|update incident.

type EscalationPolicy added in v1.20210826.18

type EscalationPolicy struct {
	APIObject
	Name            string           `json:"name,omitempty"`
	EscalationRules []EscalationRule `json:"escalation_rules,omitempty"`
	Services        []APIObject      `json:"services,omitempty"`
	NumLoops        uint             `json:"num_loops,omitempty"`
	Teams           []APIReference   `json:"teams"`
	Description     string           `json:"description,omitempty"`
	RepeatEnabled   bool             `json:"repeat_enabled,omitempty"`
}

EscalationPolicy is a collection of escalation rules.

type EscalationRule added in v1.20210826.18

type EscalationRule struct {
	ID      string      `json:"id,omitempty"`
	Delay   uint        `json:"escalation_delay_in_minutes,omitempty"`
	Targets []APIObject `json:"targets"`
}

EscalationRule is a rule for an escalation policy to trigger.

type HTTPClient

type HTTPClient struct {
	Config   Config
	Defaults []r2.Option
}

HTTPClient is an implementation of the http client.

func (HTTPClient) CreateIncident

func (hc HTTPClient) CreateIncident(ctx context.Context, incident CreateIncidentInput) (output Incident, err error)

CreateIncident creates an incident using the incident events api.

func (HTTPClient) GetService added in v1.20210826.18

func (hc HTTPClient) GetService(ctx context.Context, id string) (service Service, err error)

GetService gets a service

func (HTTPClient) ListIncidents

func (hc HTTPClient) ListIncidents(ctx context.Context, opts ...ListIncidentOption) (output ListIncidentsOutput, err error)

ListIncidents lists incidents.

Use the variadic options to set constraining query parameters to filter or sort the incidents.

func (HTTPClient) Request

func (hc HTTPClient) Request(ctx context.Context, opts ...r2.Option) *r2.Request

Request creates a request with a context and a given set of options.

func (HTTPClient) UpdateIncident

func (hc HTTPClient) UpdateIncident(ctx context.Context, id string, incident UpdateIncidentInput) (output Incident, err error)

UpdateIncident implements the update incident method for the client.

type Incident

type Incident struct {
	ID                 string            `json:"id"`
	Summary            string            `json:"summary,omitempty"`
	Type               string            `json:"type,omitempty"`
	Self               string            `json:"self,omitempty"`
	HTMLUrl            string            `json:"html_url,omitempty"`
	IncidentNumber     int               `json:"incident_number,omitempty"`
	CreatedAt          time.Time         `json:"created_at,omitempty"`
	Status             IncidentStatus    `json:"status"`
	Title              string            `json:"title,omitempty"`
	PendingActions     []Action          `json:"pending_actions,omitempty"`
	IncidentKey        string            `json:"incident_key,omitempty"`
	Service            APIObject         `json:"service,omitempty"`
	Assignments        []Assignment      `json:"assignments,omitempty"`
	AssignedVia        string            `json:"assigned_via,omitempty"`
	Acknowledgements   []Acknowledgement `json:"acknowledgements,omitempty"`
	LastStatusChangeAt time.Time         `json:"last_status_change_at,omitempty"`
	LastStatusChangeBy APIObject         `json:"last_status_change_by,omitempty"`
	EscalationPolicy   APIObject         `json:"escalation_policy,omitempty"`
	Teams              []APIObject       `json:"teams,omitempty"`
	Priority           APIObject         `json:"priority,omitempty"`
	Urgency            string            `json:"urgency"`
	ResolveReason      ResolveReason     `json:"resolve_reason,omitempty"`
	AlertCounts        struct {
		Triggered int `json:"triggered,omitempty"`
		Resolved  int `json:"resolved,omitempty"`
		All       int `json:"all,omitempty"`
	} `json:"alert_counts,omitempty"`
	Body Body `json:"body,omitempty"`
}

Incident is the full api type for incidents.

type IncidentStatus

type IncidentStatus string

IncidentStatus is a status for an incident

const (
	IncidentStatusTriggered    IncidentStatus = "triggered"
	IncidentStatusAcknowledged IncidentStatus = "acknowledged"
	IncidentStatusResolved     IncidentStatus = "resolved"
)

IncidentStatuses

type IncidentUrgencyRule added in v1.20210826.18

type IncidentUrgencyRule struct {
	Type                string               `json:"type,omitempty"`
	Urgency             string               `json:"urgency,omitempty"`
	DuringSupportHours  *IncidentUrgencyType `json:"during_support_hours,omitempty"`
	OutsideSupportHours *IncidentUrgencyType `json:"outside_support_hours,omitempty"`
}

IncidentUrgencyRule is the default urgency for new incidents.

type IncidentUrgencyType added in v1.20210826.18

type IncidentUrgencyType struct {
	Type    string `json:"type,omitempty"`
	Urgency string `json:"urgency,omitempty"`
}

IncidentUrgencyType are the incidents urgency during or outside support hours.

type Include

type Include string

Include is an object type constant.

const (
	IncludeUsers                  Include = "users"
	IncludeServices               Include = "services"
	IncludeFirstTriggerLogEntries Include = "first_trigger_log_entries"
	IncludeEscalationPolicies     Include = "escalation_policies"
	IncludeTeams                  Include = "teams"
	IncludeAssignees              Include = "assignees"
	IncludeAcknowledgers          Include = "acknowledgers"
	IncludePriorities             Include = "priorities"
	IncludeConferenceBridge       Include = "conference_bridge"
)

Includes

type InlineModel added in v1.20210826.18

type InlineModel struct {
	Type string `json:"type,omitempty"`
	Name string `json:"name,omitempty"`
}

InlineModel represents when a scheduled action will occur.

type Integration added in v1.20210826.18

type Integration struct {
	APIObject
	Name             string     `json:"name,omitempty"`
	Service          *APIObject `json:"service,omitempty"`
	CreatedAt        string     `json:"created_at,omitempty"`
	Vendor           *APIObject `json:"vendor,omitempty"`
	Type             string     `json:"type,omitempty"`
	IntegrationKey   string     `json:"integration_key,omitempty"`
	IntegrationEmail string     `json:"integration_email,omitempty"`
}

Integration is an endpoint (like Nagios, email, or an API call) that generates events, which are normalized and de-duplicated by PagerDuty to create incidents.

type ListIncidentOption

type ListIncidentOption func(*ListIncidentsOptions)

ListIncidentOption mutates the list incidents options.

func OptListIncidentsDateRange

func OptListIncidentsDateRange(dateRange string) ListIncidentOption

OptListIncidentsDateRange sets a field on the options.

func OptListIncidentsIncidentKey

func OptListIncidentsIncidentKey(incidentKey string) ListIncidentOption

OptListIncidentsIncidentKey sets a field on the options.

func OptListIncidentsInclude

func OptListIncidentsInclude(include ...Include) ListIncidentOption

OptListIncidentsInclude sets the "include" query string value.

Include sets if we should add additional data to the response for corresponding fields on the output object.

func OptListIncidentsLimit

func OptListIncidentsLimit(limit int) ListIncidentOption

OptListIncidentsLimit sets a field on the options.

func OptListIncidentsOffset

func OptListIncidentsOffset(offset int) ListIncidentOption

OptListIncidentsOffset sets a field on the options.

func OptListIncidentsServiceIDs

func OptListIncidentsServiceIDs(serviceIDs ...string) ListIncidentOption

OptListIncidentsServiceIDs sets a field on the options.

func OptListIncidentsSince

func OptListIncidentsSince(since string) ListIncidentOption

OptListIncidentsSince sets a field on the options.

func OptListIncidentsSortBy

func OptListIncidentsSortBy(sortBy string) ListIncidentOption

OptListIncidentsSortBy sets a field on the options.

func OptListIncidentsStatuses

func OptListIncidentsStatuses(statuses ...IncidentStatus) ListIncidentOption

OptListIncidentsStatuses sets a field on the options.

func OptListIncidentsTeamIDs

func OptListIncidentsTeamIDs(teamIDs ...string) ListIncidentOption

OptListIncidentsTeamIDs sets a field on the options.

func OptListIncidentsTimeZone

func OptListIncidentsTimeZone(timeZone string) ListIncidentOption

OptListIncidentsTimeZone sets a field on the options.

func OptListIncidentsTotal

func OptListIncidentsTotal(total bool) ListIncidentOption

OptListIncidentsTotal sets a field on the options.

func OptListIncidentsUntil

func OptListIncidentsUntil(until string) ListIncidentOption

OptListIncidentsUntil sets a field on the options.

func OptListIncidentsUrgencies

func OptListIncidentsUrgencies(urgencies ...string) ListIncidentOption

OptListIncidentsUrgencies sets a field on the options.

func OptListIncidentsUserIDs

func OptListIncidentsUserIDs(userIDs ...string) ListIncidentOption

OptListIncidentsUserIDs sets a field on the options.

type ListIncidentsOptions

type ListIncidentsOptions struct {
	DateRange   string
	IncidentKey string
	Include     []Include
	Limit       int
	Offset      int
	ServiceIDs  []string
	Since       string
	SortBy      string
	Statuses    []IncidentStatus
	TeamIDs     []string
	TimeZone    string
	Total       *bool
	Until       string
	Urgencies   []string
	UserIDs     []string
}

ListIncidentsOptions are all the options for a list incidents call.

func (ListIncidentsOptions) Options

func (lio ListIncidentsOptions) Options() (output []r2.Option)

Options yields the r2 options for the options.

_Allow myself to introduce ... myself_

type ListIncidentsOutput

type ListIncidentsOutput struct {
	Offset    int        `json:"offset"`
	Limit     int        `json:"limit"`
	More      bool       `json:"more"`
	Total     *int       `json:"total"`
	Incidents []Incident `json:"incidents"`
}

ListIncidentsOutput is the output of a list incidents call.

type ListServiceRulesResponse added in v1.20210826.18

type ListServiceRulesResponse struct {
	Offset uint          `json:"offset,omitempty"`
	Limit  uint          `json:"limit,omitempty"`
	More   bool          `json:"more,omitempty"`
	Total  uint          `json:"total,omitempty"`
	Rules  []ServiceRule `json:"rules,omitempty"`
}

ListServiceRulesResponse represents a list of rules in a service

type MockAPI

type MockAPI struct {
	ListIncidents  func() (ListIncidentsOutput, error)
	UpdateIncident func(string, UpdateIncidentInput) (Incident, error)
	CreateIncident func(CreateIncidentInput) (Incident, error)
}

MockAPI implements methods that can be called with the client.

func (MockAPI) ServeHTTP

func (ma MockAPI) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Handler implements http.Handler.

type ReferenceType

type ReferenceType string

ReferenceType is a type of reference.

const (
	ReferenceTypeEscalationPolicy ReferenceType = "escalation_policy_reference"
	ReferenceTypeService          ReferenceType = "service_reference"
	ReferenceTypeUser             ReferenceType = "user_reference"
)

ReferenceTypes

type ResolveReason

type ResolveReason struct {
	Type     string    `json:"type,omitempty"`
	Incident APIObject `json:"incident,omitempty"`
}

ResolveReason is an api type.

type RuleActionExtraction added in v1.20210826.18

type RuleActionExtraction struct {
	Target string `json:"target,omitempty"`
	Source string `json:"source,omitempty"`
	Regex  string `json:"regex,omitempty"`
}

RuleActionExtraction represents a rule extraction action object

type RuleActionParameter added in v1.20210826.18

type RuleActionParameter struct {
	Value string `json:"value,omitempty"`
}

RuleActionParameter represents a generic parameter object on a rule action

type RuleActionSuppress added in v1.20210826.18

type RuleActionSuppress struct {
	Value               bool   `json:"value,omitempty"`
	ThresholdValue      int    `json:"threshold_value,omitempty"`
	ThresholdTimeUnit   string `json:"threshold_time_unit,omitempty"`
	ThresholdTimeAmount int    `json:"threshold_time_amount,omitempty"`
}

RuleActionSuppress represents a rule suppress action object

type RuleActionSuspend added in v1.20210826.18

type RuleActionSuspend struct {
	Value *bool `json:"value,omitempty"`
}

RuleActionSuspend represents a rule suspend action object

type RuleConditions added in v1.20210826.18

type RuleConditions struct {
	Operator          string              `json:"operator,omitempty"`
	RuleSubconditions []*RuleSubcondition `json:"subconditions,omitempty"`
}

RuleConditions represents the conditions field for a Ruleset

type RuleSubcondition added in v1.20210826.18

type RuleSubcondition struct {
	Operator   string              `json:"operator,omitempty"`
	Parameters *ConditionParameter `json:"parameters,omitempty"`
}

RuleSubcondition represents a subcondition of a ruleset condition

type RuleTimeFrame added in v1.20210826.18

type RuleTimeFrame struct {
	ScheduledWeekly *ScheduledWeekly `json:"scheduled_weekly,omitempty"`
	ActiveBetween   *ActiveBetween   `json:"active_between,omitempty"`
}

RuleTimeFrame represents a time_frame object on the rule object

type ScheduledAction added in v1.20210826.18

type ScheduledAction struct {
	Type      string      `json:"type,omitempty"`
	At        InlineModel `json:"at,omitempty"`
	ToUrgency string      `json:"to_urgency"`
}

ScheduledAction contains scheduled actions for the service.

type ScheduledWeekly added in v1.20210826.18

type ScheduledWeekly struct {
	Weekdays  []int  `json:"weekdays,omitempty"`
	Timezone  string `json:"timezone,omitempty"`
	StartTime int    `json:"start_time,omitempty"`
	Duration  int    `json:"duration,omitempty"`
}

ScheduledWeekly represents a time_frame object for scheduling rules weekly

type Service added in v1.20210826.18

type Service struct {
	APIObject
	Name                    string                   `json:"name,omitempty"`
	Description             string                   `json:"description,omitempty"`
	AutoResolveTimeout      *uint                    `json:"auto_resolve_timeout"`
	AcknowledgementTimeout  *uint                    `json:"acknowledgement_timeout"`
	CreateAt                string                   `json:"created_at,omitempty"`
	Status                  string                   `json:"status,omitempty"`
	LastIncidentTimestamp   string                   `json:"last_incident_timestamp,omitempty"`
	Integrations            []Integration            `json:"integrations,omitempty"`
	EscalationPolicy        EscalationPolicy         `json:"escalation_policy,omitempty"`
	Teams                   []Team                   `json:"teams,omitempty"`
	IncidentUrgencyRule     *IncidentUrgencyRule     `json:"incident_urgency_rule,omitempty"`
	SupportHours            *SupportHours            `json:"support_hours"`
	ScheduledActions        []ScheduledAction        `json:"scheduled_actions"`
	AlertCreation           string                   `json:"alert_creation,omitempty"`
	AlertGrouping           string                   `json:"alert_grouping,omitempty"`
	AlertGroupingTimeout    *uint                    `json:"alert_grouping_timeout,omitempty"`
	AlertGroupingParameters *AlertGroupingParameters `json:"alert_grouping_parameters,omitempty"`
}

Service represents something you monitor (like a web service, email service, or database service).

type ServiceRule added in v1.20210826.18

type ServiceRule struct {
	ID         string              `json:"id,omitempty"`
	Self       string              `json:"self,omitempty"`
	Disabled   *bool               `json:"disabled,omitempty"`
	Conditions *RuleConditions     `json:"conditions,omitempty"`
	TimeFrame  *RuleTimeFrame      `json:"time_frame,omitempty"`
	Position   *int                `json:"position,omitempty"`
	Actions    *ServiceRuleActions `json:"actions,omitempty"`
}

ServiceRule represents a Service rule

type ServiceRuleActions added in v1.20210826.18

type ServiceRuleActions struct {
	Annotate    *RuleActionParameter   `json:"annotate,omitempty"`
	EventAction *RuleActionParameter   `json:"event_action,omitempty"`
	Extractions []RuleActionExtraction `json:"extractions,omitempty"`
	Priority    *RuleActionParameter   `json:"priority,omitempty"`
	Severity    *RuleActionParameter   `json:"severity,omitempty"`
	Suppress    *RuleActionSuppress    `json:"suppress,omitempty"`
	Suspend     *RuleActionSuspend     `json:"suspend,omitempty"`
}

ServiceRuleActions represents a rule action

type SupportHours added in v1.20210826.18

type SupportHours struct {
	Type       string `json:"type,omitempty"`
	Timezone   string `json:"time_zone,omitempty"`
	StartTime  string `json:"start_time,omitempty"`
	EndTime    string `json:"end_time,omitempty"`
	DaysOfWeek []uint `json:"days_of_week,omitempty"`
}

SupportHours are the support hours for the service.

type Team added in v1.20210826.18

type Team struct {
	APIObject
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
}

Team is a collection of users and escalation policies that represent a group of people within an organization.

type UpdateIncidentInput

type UpdateIncidentInput struct {
	Type             string            `json:"type"`             // required
	Status           IncidentStatus    `json:"status,omitempty"` // required
	Priority         *APIObject        `json:"priority,omitempty"`
	Resolution       string            `json:"resolution,omitempty"`
	Title            string            `json:"title,omitempty"`
	EscalationLevel  int               `json:"escalation_level,omitempty"`
	Assignments      []Assignment      `json:"assignments,omitempty"`
	EscalationPolicy *APIObject        `json:"escalation_policy,omitempty"`
	Urgency          string            `json:"urgency,omitempty"`
	ConferenceBridge *ConferenceBridge `json:"conference_bridge,omitempty"`
}

UpdateIncidentInput is the input to update incident.

type Urgency

type Urgency string

Urgency is a urgency.

const (
	UrgencyHigh Urgency = "high"
	UrgencyLow  Urgency = "low"
)

Urgencies

Jump to

Keyboard shortcuts

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