pd

package module
v0.0.0-...-c8d49c3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: MIT Imports: 8 Imported by: 0

README

pd

pd is a library and command line utility built on top of go-pagerduty.

It currently provides some functions for finding conflicts that one or more users may have in a set of oncall schedules.

To use the CLI, first get an auth token, and then use like:

go build -o pd.bin ./cmd/
./pd.bin --auth-token "$YOUR_AUTH_TOKEN" -s"$SCHEDULE_1,$SCHEDULE_2,..."

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindConflictsByUser

func FindConflictsByUser(entries []*RenderedScheduleEntry) map[string][]*Conflict

FindConflictsByUser returns a mapping of user ID to a list of Conflicts for that user in the given list of RenderedScheduleEntries.

It also logs any conflicts found as a side-effect, which may change in the future.

func GetAllSchedules

func GetAllSchedules(client *pagerduty.Client, scheduleIDs []string, opts pagerduty.GetScheduleOptions) ([]*pagerduty.Schedule, error)

GetAllSchedules makes concurrent client.GetSchedule calls for each schedule ID. Unlike GetSchedules, if any GetSchedule call fails, this method returns an error. Consequently, callers should use this function when they do not want to permit partial responses.

func GetSchedules

func GetSchedules(client *pagerduty.Client, scheduleIDs []string, opts pagerduty.GetScheduleOptions) ([]*pagerduty.Schedule, []string, error)

GetSchedules makes concurrent client.GetSchedule calls for each schedule ID. Individual call failures are collected into a failures slice, so that callers can decide whether to permit partial responses or not. If every GetSchedule call returns an error, this method will return an error, which is the concatenation of those failure messages.

Types

type Conflict

type Conflict struct {
	Left  *RenderedScheduleEntry
	Right *RenderedScheduleEntry
}

Conflict represents an overlap in two RenderedScheduleEntries, where the Left side begins first, but the Right side begins before the Left side ends.

Currently, we only support finding conflicts grouped to a particular user ID, so callers can assume that Left.User.ID == Right.User.ID and use either. This may have to change to support other modes of conflict detection.

type RenderedScheduleEntries

type RenderedScheduleEntries []*RenderedScheduleEntry

RenderedScheduleEntries is a list of RenderedScheduleEntry objects.

func (RenderedScheduleEntries) GroupBy

func (entries RenderedScheduleEntries) GroupBy(keyFn func(entry *RenderedScheduleEntry) string) map[string][]*RenderedScheduleEntry

GroupBy returns a mapping of some string key, as determined by the provided keyFn, to lists of RenderedScheduleEntry objects that map to that key.

type RenderedScheduleEntry

type RenderedScheduleEntry struct {
	Start    time.Time
	End      time.Time
	User     pagerduty.APIObject
	Schedule string
}

RenderedScheduleEntry is a different representation of the pagerduty.RenderedScheduleEntry type. The notable changes are that the Start and End fields are time.Time objects, rather than RFC3337 timestamp strings, and that schedule of the schedule the entry came from is included in the Schedule field, for easier grouping.

func GetRenderedScheduleEntries

func GetRenderedScheduleEntries(schedule *pagerduty.Schedule) ([]*RenderedScheduleEntry, error)

GetRenderedScheduleEntries returns a list of RenderedScheduleEntry objects corresponding to the final rendered schedule. It returns an error if any of the Start or End fields fail to parse as RFC3337 timestamps.

func ParseRenderedScheduleEntry

func ParseRenderedScheduleEntry(schedule *pagerduty.Schedule, entry pagerduty.RenderedScheduleEntry) (*RenderedScheduleEntry, error)

ParseRenderedScheduleEntry parses a RenderedScheduleEntry object out of a pagerduty.RenderedScheduleEntry object. It returns an error if either the Start or End fields fail to parse as RFC337 timestamps.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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