schedule

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package schedule allows you to synchronise the participants of a schedule.

Using this as a source supports schedule with multiple rotations, however if you wish to use this as a destination adapter the schedule must only have 1 rotation configured, and all members of the source adapter must already have an Opsgenie license allocated.

Requirements

You will need to create an API Key with the following access rights:

  • Read
  • Update

Examples

See [New] and Init.

Index

Examples

Constants

View Source
const OpsgenieAPIKey gosync.ConfigKey = "opsgenie_api_key" //nolint:gosec

OpsgenieAPIKey is an API key for authenticating with Opsgenie.

View Source
const ScheduleID gosync.ConfigKey = "schedule_id"

ScheduleID is the name of the Opsgenie Schedule ID.

Variables

View Source
var (
	ErrMultipleRotations = errors.New("gosync can only manage schedules with a single rotation")
	ErrNoRotations       = errors.New("gosync cannot create rotations - you must have 1 already defined for schedule")
)

Functions

func WithClient added in v0.14.0

func WithClient(client *ogSchedule.Client) gosync.ConfigFn[*Schedule]

WithClient passes a custom Opsgenie Schedule client to the adapter.

Example
package main

import (
	"context"
	"log"

	"github.com/opsgenie/opsgenie-go-sdk-v2/client"
	ogSchedule "github.com/opsgenie/opsgenie-go-sdk-v2/schedule"

	gosync "github.com/ovotech/go-sync"
	"github.com/ovotech/go-sync/adapters/opsgenie/schedule"
)

func main() {
	ctx := context.Background()

	scheduleClient, err := ogSchedule.NewClient(&client.Config{
		ApiKey: "default",
	})
	if err != nil {
		log.Fatal(err)
	}

	adapter, err := schedule.Init(ctx, map[gosync.ConfigKey]string{
		schedule.ScheduleID: "opsgenie-schedule-id",
	}, schedule.WithClient(scheduleClient))
	if err != nil {
		log.Fatal(err)
	}

	gosync.New(adapter)
}
Output:

func WithLogger added in v0.14.0

func WithLogger(logger *log.Logger) gosync.ConfigFn[*Schedule]

WithLogger passes a custom logger to the adapter.

Example
package main

import (
	"context"
	"log"
	"os"

	gosync "github.com/ovotech/go-sync"
	"github.com/ovotech/go-sync/adapters/opsgenie/schedule"
)

func main() {
	ctx := context.Background()

	logger := log.New(os.Stdout, "", log.LstdFlags)

	adapter, err := schedule.Init(ctx, map[gosync.ConfigKey]string{
		schedule.OpsgenieAPIKey: "default",
		schedule.ScheduleID:     "opsgenie-schedule-id",
	}, schedule.WithLogger(logger))
	if err != nil {
		log.Fatal(err)
	}

	gosync.New(adapter)
}
Output:

Types

type Schedule

type Schedule struct {
	Logger *log.Logger
	// contains filtered or unexported fields
}

func Init added in v0.7.0

func Init(
	_ context.Context,
	config map[gosync.ConfigKey]string,
	configFns ...gosync.ConfigFn[*Schedule],
) (*Schedule, error)

Init a new Opsgenie Schedule gosync.Adapter.

Required config:

Example
package main

import (
	"context"
	"log"

	gosync "github.com/ovotech/go-sync"
	"github.com/ovotech/go-sync/adapters/opsgenie/schedule"
)

func main() {
	ctx := context.Background()

	adapter, err := schedule.Init(ctx, map[gosync.ConfigKey]string{
		schedule.OpsgenieAPIKey: "default",
		schedule.ScheduleID:     "opsgenie-schedule-id",
	})
	if err != nil {
		log.Fatal(err)
	}

	gosync.New(adapter)
}
Output:

func (*Schedule) Add

func (s *Schedule) Add(ctx context.Context, emails []string) error

Add new participants to a rotation, but the schedule must only have 1 rotation defined.

func (*Schedule) Get

func (s *Schedule) Get(ctx context.Context) ([]string, error)

Get a flattened list of all participants, even across multiple rotations.

func (*Schedule) Remove

func (s *Schedule) Remove(ctx context.Context, emails []string) error

Remove participants from a rotation, but the schedule must only have 1 rotation defined.

Jump to

Keyboard shortcuts

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