pagerduty

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIEndpointDefaultURL          = "https://api.pagerduty.com"
	NotifyServiceDefaultAnnotation = "pagerduty_notify_service"
	ServicesDefaultAnnotation      = "pagerduty_services"
)
View Source
const (
	Unresolved       = ResolutionTag("")
	ResolvedApproved = ResolutionTag("approved")
	ResolvedDenied   = ResolutionTag("denied")
	ResolvedExpired  = ResolutionTag("expired")
	ResolvedPromoted = ResolutionTag("promoted")
)

Variables

View Source
var (
	// Version package version, specified in Makefile using ldflags
	Version = `Not specified, use --ldflags "-X main.Version "1.0.0""`

	// Gitref variable is specified in Makefile using ldflags
	Gitref string
)

Functions

func EncodePluginData

func EncodePluginData(data PluginData) map[string]string

EncodePluginData serializes a PluginData struct into a string map.

Types

type App

type App struct {
	*lib.Process
	// contains filtered or unexported fields
}

App contains global application state of the PagerDuty plugin.

func NewApp

func NewApp(conf Config) (*App, error)

NewApp constructs a new PagerDuty App.

func (*App) Err

func (a *App) Err() error

Err returns the error app finished with.

func (*App) Run

func (a *App) Run(ctx context.Context) error

Run initializes and runs a watcher and a callback server

func (*App) WaitReady

func (a *App) WaitReady(ctx context.Context) (bool, error)

WaitReady waits for http and watcher service to start up.

type Config

type Config struct {
	Teleport  lib.TeleportConfig `toml:"teleport"`
	Pagerduty PagerdutyConfig    `toml:"pagerduty"`
	Log       logger.Config      `toml:"log"`

	// Teleport is a handle to the client to use when communicating with
	// the Teleport auth server. The PagerDuty app will create a gRPC-
	// based client on startup if this is not set.
	Client teleport.Client

	// StatusSink receives any status updates from the plugin for
	// further processing. Status updates will be ignored if not set.
	StatusSink common.StatusSink

	// TeleportUser is the name of the Teleport user that will act
	// as the access request approver
	TeleportUser string
}

func (*Config) CheckAndSetDefaults

func (c *Config) CheckAndSetDefaults() error

type Details

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

type ErrorResult

type ErrorResult struct {
	Code    int      `json:"code"`
	Message string   `json:"message"`
	Errors  []string `json:"errors"`
}

type Extension

type Extension struct {
	ID               string      `json:"id,omitempty"`
	Name             string      `json:"name"`
	EndpointURL      string      `json:"endpoint_url"`
	ExtensionObjects []Reference `json:"extension_objects"`
	ExtensionSchema  Reference   `json:"extension_schema"`
}

type ExtensionBody

type ExtensionBody struct {
	Name             string      `json:"name"`
	EndpointURL      string      `json:"endpoint_url"`
	ExtensionObjects []Reference `json:"extension_objects"`
	ExtensionSchema  Reference   `json:"extension_schema"`
}

type ExtensionBodyWrap

type ExtensionBodyWrap struct {
	Extension ExtensionBody `json:"extension"`
}

type ExtensionResult

type ExtensionResult struct {
	Extension Extension `json:"extension"`
}

type ExtensionSchema

type ExtensionSchema struct {
	ID  string `json:"id"`
	Key string `json:"key"`
}

type Incident

type Incident struct {
	ID          string               `json:"id"`
	Title       string               `json:"title"`
	Status      string               `json:"status"`
	IncidentKey string               `json:"incident_key"`
	Service     Reference            `json:"service"`
	Assignments []IncidentAssignment `json:"assignments"`
	Body        Details              `json:"body"`
}

type IncidentAssignment

type IncidentAssignment struct {
	At       string    `json:"at"`
	Assignee Reference `json:"assignee"`
}

type IncidentBody

type IncidentBody struct {
	ID          string    `json:"id,omitempty"`
	Title       string    `json:"title,omitempty"`
	IncidentKey string    `json:"incident_key,omitempty"`
	Service     Reference `json:"service,omitempty"`
	Body        Details   `json:"body,omitempty"`
	Type        string    `json:"type,omitempty"`
	Status      string    `json:"status,omitempty"`
}

type IncidentBodyWrap

type IncidentBodyWrap struct {
	Incident IncidentBody `json:"incident"`
}

type IncidentNote

type IncidentNote struct {
	ID      string `json:"id"`
	Content string `json:"content"`
}

type IncidentNoteBody

type IncidentNoteBody struct {
	Content string `json:"content,omitempty"`
}

type IncidentNoteBodyWrap

type IncidentNoteBodyWrap struct {
	Note IncidentNoteBody `json:"note"`
}

type IncidentNoteResult

type IncidentNoteResult struct {
	Note IncidentNote `json:"note"`
}

type IncidentResult

type IncidentResult struct {
	Incident Incident `json:"incident"`
}

type ListAbilitiesResult

type ListAbilitiesResult struct {
	Abilities []string `json:"abilities"`
}

ListAbilitiesResult describes the output of the PagerDuty /abilities API call.

type ListExtensionSchemasResult

type ListExtensionSchemasResult struct {
	PaginationResult
	ExtensionSchemas []ExtensionSchema `json:"extension_schemas"`
}

type ListExtensionsResult

type ListExtensionsResult struct {
	PaginationResult
	Extensions []Extension `json:"extensions"`
}

type ListIncidentsResult

type ListIncidentsResult struct {
	PaginationResult
	Incidents []Incident `json:"incidents"`
}

type ListOnCallsQuery

type ListOnCallsQuery struct {
	PaginationQuery
	UserIDs             []string `url:"user_ids,omitempty,brackets"`
	EscalationPolicyIDs []string `url:"escalation_policy_ids,omitempty,brackets"`
}

type ListOnCallsResult

type ListOnCallsResult struct {
	PaginationResult
	OnCalls []OnCall `json:"oncalls"`
}

type ListServicesQuery

type ListServicesQuery struct {
	PaginationQuery
	Query string `url:"query,omitempty"`
}

type ListServicesResult

type ListServicesResult struct {
	PaginationResult
	Services []Service `json:"services"`
}

type ListUsersQuery

type ListUsersQuery struct {
	PaginationQuery
	Query string `url:"query,omitempty"`
}

type ListUsersResult

type ListUsersResult struct {
	PaginationResult
	Users []User `json:"users"`
}

type OnCall

type OnCall struct {
	User             Reference `json:"user"`
	EscalationPolicy Reference `json:"escalation_policy"`
}

type Pagerduty

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

Pagerduty is a wrapper around resty.Client.

func NewPagerdutyClient

func NewPagerdutyClient(conf PagerdutyConfig, clusterName, webProxyAddr string, statusSink common.StatusSink) (Pagerduty, error)

func (Pagerduty) CreateIncident

func (p Pagerduty) CreateIncident(ctx context.Context, serviceID, reqID string, reqData RequestData) (PagerdutyData, error)

CreateIncident creates a notification incident.

func (*Pagerduty) FilterOnCallPolicies

func (p *Pagerduty) FilterOnCallPolicies(ctx context.Context, userID string, escalationPolicyIDs []string) ([]string, error)

RangeOnCallPolicies iterates over the escalation policy IDs for which a given user is currently on-call.

func (*Pagerduty) FindServiceByName

func (p *Pagerduty) FindServiceByName(ctx context.Context, serviceName string) (Service, error)

FindServiceByName finds a service by its name (case-insensitive).

func (Pagerduty) FindServicesByNames

func (p Pagerduty) FindServicesByNames(ctx context.Context, serviceNames []string) ([]Service, error)

FindServicesByNames finds a bunch of services by its names making a query for each service.

func (*Pagerduty) FindUserByEmail

func (p *Pagerduty) FindUserByEmail(ctx context.Context, userEmail string) (User, error)

GetUserByEmail finds a user by email.

func (Pagerduty) GetUserInfo

func (p Pagerduty) GetUserInfo(ctx context.Context, userID string) (User, error)

GetUserInfo loads a user profile by id.

func (Pagerduty) HealthCheck

func (p Pagerduty) HealthCheck(ctx context.Context) error

func (Pagerduty) PostReviewNote

func (p Pagerduty) PostReviewNote(ctx context.Context, incidentID string, review types.AccessReview) error

PostReviewNote posts a note once a new request review appears.

func (Pagerduty) ResolveIncident

func (p Pagerduty) ResolveIncident(ctx context.Context, incidentID string, resolution Resolution) error

ResolveIncident resolves an incident and posts a note with resolution details.

type PagerdutyConfig

type PagerdutyConfig struct {
	APIEndpoint        string `toml:"-"`
	APIKey             string `toml:"api_key"`
	UserEmail          string `toml:"user_email"`
	RequestAnnotations struct {
		NotifyService string `toml:"notify_service"`
		Services      string `toml:"services"`
	}
}

type PagerdutyData

type PagerdutyData struct {
	ServiceID  string
	IncidentID string
}

PagerdutyData stores the notification incident info.

type PaginationQuery

type PaginationQuery struct {
	Limit  uint `url:"limit,omitempty"`
	Offset uint `url:"offset,omitempty"`
	Total  bool `url:"total,omitempty"`
}

type PaginationResult

type PaginationResult struct {
	Limit  uint `json:"limit"`
	Offset uint `json:"offset"`
	More   bool `json:"more"`
	Total  uint `json:"total"`
}

type PluginData

type PluginData struct {
	RequestData
	PagerdutyData
}

PluginData is a data associated with access request that we store in Teleport using UpdatePluginData API.

func DecodePluginData

func DecodePluginData(dataMap map[string]string) (data PluginData)

DecodePluginData deserializes a string map to PluginData struct.

type Reference

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

type RequestData

type RequestData struct {
	User          string
	Roles         []string
	Created       time.Time
	RequestReason string
	ReviewsCount  int
	Resolution    Resolution
}

RequestData stores a slice of some request fields in a convenient format.

type Resolution

type Resolution struct {
	Tag    ResolutionTag
	Reason string
}

Resolution stores the resolution (approved, denied or expired) and its reason.

type ResolutionTag

type ResolutionTag string

type Service

type Service struct {
	ID               string    `json:"id"`
	Name             string    `json:"name"`
	EscalationPolicy Reference `json:"escalation_policy"`
}

type ServiceResult

type ServiceResult struct {
	Service Service `json:"service"`
}

type User

type User struct {
	ID    string `json:"id"`
	Email string `json:"email"`
	Name  string `json:"name"`
}

type UserResult

type UserResult struct {
	User User `json:"user"`
}

Jump to

Keyboard shortcuts

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