scenario

package
v0.0.0-...-9b5cd94 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewApi

func NewApi(
	store Store,
	actionLogger logger.ActionLogger,
	transformer common.PatternFieldsTransformer,
	logger zerolog.Logger,
) common.BulkCrudAPI

func ValidateActionRequest

func ValidateActionRequest(sl validator.StructLevel)

Types

type Action

type Action struct {
	Type                     string     `bson:"type" json:"type"`
	Comment                  string     `bson:"comment" json:"comment"`
	Parameters               Parameters `bson:"parameters,omitempty" json:"parameters,omitempty"`
	DropScenarioIfNotMatched bool       `bson:"drop_scenario_if_not_matched" json:"drop_scenario_if_not_matched"`
	EmitTrigger              bool       `bson:"emit_trigger" json:"emit_trigger"`

	savedpattern.EntityPatternFields `bson:",inline"`
	savedpattern.AlarmPatternFields  `bson:",inline"`
}

type ActionRequest

type ActionRequest struct {
	Type                     string            `json:"type" binding:"required,oneof=ack ackremove assocticket cancel changestate pbehavior snooze webhook"`
	Parameters               action.Parameters `json:"parameters,omitempty"`
	Comment                  string            `json:"comment"`
	DropScenarioIfNotMatched *bool             `json:"drop_scenario_if_not_matched" binding:"required"`
	EmitTrigger              *bool             `json:"emit_trigger" binding:"required"`

	common.EntityPatternFieldsRequest `bson:",inline"`
	common.AlarmPatternFieldsRequest  `bson:",inline"`
}

type AggregationResult

type AggregationResult struct {
	Data       []Scenario `bson:"data" json:"data"`
	TotalCount int64      `bson:"total_count" json:"total_count"`
}

func (AggregationResult) GetData

func (r AggregationResult) GetData() interface{}

GetData implementation PaginatedData interface

func (AggregationResult) GetTotal

func (r AggregationResult) GetTotal() int64

GetTotal implementation PaginatedData interface

type BulkDeleteRequestItem

type BulkDeleteRequestItem struct {
	ID string `json:"_id" binding:"required"`
}

type BulkUpdateRequestItem

type BulkUpdateRequestItem struct {
	EditRequest
	ID string `json:"_id" binding:"required"`
}

type CreateRequest

type CreateRequest struct {
	EditRequest
	ID string `json:"_id" binding:"id"`
}

type EditRequest

type EditRequest struct {
	Name                 string                     `json:"name" binding:"required,max=255"`
	Author               string                     `json:"author" binding:"required,max=255"`
	Enabled              *bool                      `json:"enabled" binding:"required"`
	Priority             int64                      `json:"priority" binding:"min=0"`
	Triggers             []Trigger                  `json:"triggers" binding:"required,notblank,dive"`
	DisableDuringPeriods []string                   `json:"disable_during_periods" binding:"dive,oneof=maintenance pause inactive"`
	Delay                *datetime.DurationWithUnit `json:"delay"`
	Actions              []ActionRequest            `json:"actions" binding:"required,notblank,dive"`
}

type FilteredQuery

type FilteredQuery struct {
	pagination.FilteredQuery
	SortBy string `json:"sort_by" form:"sort_by" binding:"oneoforempty=_id name author.name created updated enabled priority"`
}

type ModelTransformer

type ModelTransformer interface {
	TransformEditRequestToModel(request EditRequest) libaction.Scenario
}

func NewModelTransformer

func NewModelTransformer() ModelTransformer

type Parameters

type Parameters struct {
	Output string `json:"output,omitempty" bson:"output"`

	ForwardAuthor *bool  `json:"forward_author,omitempty" bson:"forward_author"`
	Author        string `json:"author,omitempty" bson:"author"`

	// ChangeState
	State *types.CpsNumber `json:"state,omitempty" bson:"state"`
	// AssocTicket
	Ticket     string            `json:"ticket,omitempty" bson:"ticket"`
	TicketURL  string            `json:"ticket_url,omitempty" bson:"ticket_url"`
	TicketData map[string]string `json:"ticket_data,omitempty" bson:"ticket_data"`
	// AssocTicket and Webhook
	TicketSystemName string `json:"ticket_system_name,omitempty" bson:"ticket_system_name"`
	// Snooze and Pbehavior
	Duration *datetime.DurationWithUnit `json:"duration,omitempty" bson:"duration"`
	// Pbehavior
	Name           string            `json:"name,omitempty" bson:"name"`
	Reason         *pbehavior.Reason `json:"reason,omitempty" bson:"reason"`
	Type           *pbehavior.Type   `json:"type,omitempty" bson:"type"`
	RRule          string            `json:"rrule,omitempty" bson:"rrule"`
	Tstart         *int64            `json:"tstart,omitempty" bson:"tstart"`
	Tstop          *int64            `json:"tstop,omitempty" bson:"tstop"`
	StartOnTrigger *bool             `json:"start_on_trigger,omitempty" bson:"start_on_trigger"`
	// Webhook
	Request            *request.Parameters           `json:"request,omitempty" bson:"request"`
	SkipForChild       *bool                         `json:"skip_for_child,omitempty" bson:"skip_for_child"`
	SkipForInstruction *bool                         `json:"skip_for_instruction,omitempty" bson:"skip_for_instruction,omitempty"`
	DeclareTicket      *request.WebhookDeclareTicket `json:"declare_ticket,omitempty" bson:"declare_ticket"`
}

type Scenario

type Scenario struct {
	ID                   string                     `bson:"_id" json:"_id"`
	Name                 string                     `bson:"name" json:"name"`
	Author               *author.Author             `bson:"author" json:"author"`
	Enabled              bool                       `bson:"enabled" json:"enabled"`
	DisableDuringPeriods []string                   `bson:"disable_during_periods" json:"disable_during_periods"`
	Triggers             []Trigger                  `bson:"triggers" json:"triggers"`
	Actions              []Action                   `bson:"actions" json:"actions"`
	Priority             int64                      `bson:"priority" json:"priority"`
	Delay                *datetime.DurationWithUnit `bson:"delay" json:"delay"`
	Created              datetime.CpsTime           `bson:"created,omitempty" json:"created,omitempty" swaggertype:"integer"`
	Updated              datetime.CpsTime           `bson:"updated,omitempty" json:"updated,omitempty" swaggertype:"integer"`
}

type Store

type Store interface {
	Insert(ctx context.Context, r CreateRequest) (*Scenario, error)
	Find(ctx context.Context, q FilteredQuery) (*AggregationResult, error)
	GetOneBy(ctx context.Context, id string) (*Scenario, error)
	Update(ctx context.Context, r UpdateRequest) (*Scenario, error)
	Delete(ctx context.Context, id string) (bool, error)
}

func NewStore

func NewStore(db mongo.DbClient, authorProvider author.Provider) Store

type Trigger

type Trigger struct {
	// Possible trigger type values.
	//   * `create` - Alarm creation
	//   * `statedec` - Alarm state decrease
	//   * `changestate` - Alarm state has been changed by "change state" action
	//   * `stateinc` - Alarm state increase
	//   * `changestatus` - Alarm status changes eg. flapping
	//   * `ack` - Alarm has been acked
	//   * `ackremove` - Alarm has been unacked
	//   * `cancel` - Alarm has been cancelled
	//   * `uncancel` - Alarm has been uncancelled
	//   * `comment` - Alarm has been commented
	//   * `declareticketwebhook` - Ticket has been declared by the webhook
	//   * `assocticket` - Ticket has been associated with an alarm
	//   * `snooze` - Alarm has been snoozed
	//   * `unsnooze` - Alarm has been unsnoozed
	//   * `pbhenter` - Alarm enters a periodic behavior
	//   * `activate` - Alarm has been activated
	//   * `resolve` - Alarm has been resolved
	//   * `pbhleave` - Alarm leaves a periodic behavior
	//   * `instructionfail` - Manual instruction has failed
	//   * `autoinstructionfail` - Auto instruction has failed
	//   * `instructionjobfail` - Manual or auto instruction's job is failed
	//   * `instructionjobcomplete` - Manual or auto instruction's job is completed
	//   * `instructioncomplete` - Manual instruction is completed
	//   * `autoinstructioncomplete` - Auto instruction is completed
	//   * `autoinstructionresultok` - Alarm is in OK state after all auto instructions
	//   * `autoinstructionresultfail` - Alarm is in not in OK state after all auto instructions
	//   * `eventscount` - Alarm check events count
	Type      string `` /* 392-byte string literal not displayed */
	Threshold int    `json:"threshold,omitempty" binding:"required_if=Type eventscount,excluded_unless=Type eventscount,omitempty,gt=1"`
}

func (*Trigger) UnmarshalBSONValue

func (t *Trigger) UnmarshalBSONValue(valueType bsontype.Type, b []byte) error

type UpdateRequest

type UpdateRequest struct {
	EditRequest
	ID string `json:"-"`
}

Jump to

Keyboard shortcuts

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