Documentation ¶
Index ¶
- Constants
- type Action
- type Adapter
- type AdditionalData
- type DelayedScenario
- type DelayedScenarioManager
- type DelayedScenarioStorage
- type DelayedScenarioTask
- type ExecuteScenariosTask
- type Execution
- type Parameters
- type RpcResult
- type Scenario
- type ScenarioExecution
- type ScenarioExecutionStorage
- type ScenarioResult
- type ScenarioStorage
- type Service
- type Task
- type TaskManager
- type TaskResult
- type WorkerPool
Constants ¶
View Source
const ( TaskNew = iota TaskNotMatched TaskCancelled TaskRpcError )
View Source
const MaxRetries = 5
View Source
const PbehaviorOrigin = "scenario"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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"` }
Action represents a canopsis Action on alarms.
type Adapter ¶
type AdditionalData ¶
type AdditionalData struct { Trigger string `json:"trigger"` Author string `json:"author"` User string `json:"user"` Initiator string `json:"initiator"` Output string `json:"event_output"` RuleName string `json:"rule_name"` // Deprecated: use Trigger instead of AlarmChangeType AlarmChangeType string `json:"alarm_change_type"` }
type DelayedScenario ¶
type DelayedScenario struct { ID string `json:"id"` ScenarioID string `json:"scenario_id"` AlarmID string `json:"alarm_id"` ExecutionTime datetime.CpsTime `json:"execution_time"` Paused bool `json:"paused"` TimeLeft time.Duration `json:"time_left"` AdditionalData AdditionalData `json:"additional_data"` }
type DelayedScenarioManager ¶
type DelayedScenarioManager interface { AddDelayedScenario(context.Context, types.Alarm, Scenario, AdditionalData) error PauseDelayedScenarios(context.Context, types.Alarm) error ResumeDelayedScenarios(context.Context, types.Alarm) error Run(context.Context) (<-chan DelayedScenarioTask, error) }
func NewDelayedScenarioManager ¶
func NewDelayedScenarioManager( adapter Adapter, alarmAdapter libalarm.Adapter, storage DelayedScenarioStorage, periodicalTimeout time.Duration, logger zerolog.Logger, ) DelayedScenarioManager
type DelayedScenarioStorage ¶
type DelayedScenarioStorage interface { Add(ctx context.Context, scenario DelayedScenario) (string, error) GetAll(ctx context.Context) ([]DelayedScenario, error) Get(ctx context.Context, id string) (*DelayedScenario, error) Delete(ctx context.Context, id string) (bool, error) Update(ctx context.Context, scenario DelayedScenario) (bool, error) }
type DelayedScenarioTask ¶
type ExecuteScenariosTask ¶
type Parameters ¶
type Parameters struct { Output string `json:"output,omitempty" bson:"output,omitempty" binding:"max=1000"` ForwardAuthor *bool `json:"forward_author,omitempty" bson:"forward_author,omitempty"` Author string `json:"author,omitempty" bson:"author,omitempty"` // State is used in changestate action. // * `0` - Info // * `1` - Minor // * `2` - Major // * `3` - Critical State *types.CpsNumber `json:"state,omitempty" bson:"state,omitempty"` // Ticket is used in assocticket action. Ticket string `json:"ticket,omitempty" binding:"max=255" bson:"ticket,omitempty"` // TicketURL is used in assocticket action. TicketURL string `json:"ticket_url,omitempty" binding:"max=255" bson:"ticket_url,omitempty"` // TicketSystemName is used in assocticket and webhook action. TicketSystemName string `json:"ticket_system_name,omitempty" binding:"max=255" bson:"ticket_system_name,omitempty"` // TicketData is used in assocticket action. TicketData map[string]string `json:"ticket_data,omitempty" bson:"ticket_data,omitempty"` // Duration is used in snooze and pbehavior actions. Duration *datetime.DurationWithUnit `json:"duration,omitempty" bson:"duration,omitempty"` // Name is used in pbehavior action. Name string `json:"name,omitempty" binding:"max=255" bson:"name,omitempty"` // Reason is used in pbehavior action. Reason string `json:"reason,omitempty" bson:"reason,omitempty"` // Type is used in pbehavior action. Type string `json:"type,omitempty" bson:"type,omitempty"` // RRule is used in pbehavior action. RRule string `json:"rrule,omitempty" bson:"rrule,omitempty"` // Tstart is used in pbehavior action. Tstart *datetime.CpsTime `json:"tstart,omitempty" bson:"tstart,omitempty" swaggertype:"integer"` // Tstop is used in pbehavior action. Tstop *datetime.CpsTime `json:"tstop,omitempty" bson:"tstop,omitempty" swaggertype:"integer"` // StartOnTrigger is used in pbehavior action. StartOnTrigger *bool `json:"start_on_trigger,omitempty" bson:"start_on_trigger,omitempty"` // Color is used in pbehavior action. Color string `json:"color,omitempty" bson:"color,omitempty"` // Request is used in webhook action. Request *request.Parameters `json:"request,omitempty" bson:"request,omitempty"` // SkipForChild is used in webhook action. SkipForChild *bool `json:"skip_for_child,omitempty" bson:"skip_for_child,omitempty"` // SkipForInstruction is used in webhook action. SkipForInstruction *bool `json:"skip_for_instruction,omitempty" bson:"skip_for_instruction,omitempty"` // DeclareTicket is used in webhook action. DeclareTicket *request.WebhookDeclareTicket `json:"declare_ticket,omitempty" bson:"declare_ticket,omitempty"` }
type RpcResult ¶
type Scenario ¶
type Scenario struct { ID string `bson:"_id,omitempty" json:"_id,omitempty"` Name string `bson:"name" json:"name"` Author string `bson:"author" json:"author"` Enabled bool `bson:"enabled" json:"enabled"` DisableDuringPeriods []string `bson:"disable_during_periods" json:"disable_during_periods"` Triggers []string `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"` Updated datetime.CpsTime `bson:"updated,omitempty" json:"updated,omitempty"` }
type ScenarioExecution ¶
type ScenarioExecution struct { ID string `json:"_id"` ScenarioID string `json:"sid"` ScenarioName string `json:"sn"` AlarmID string `json:"aid"` Entity types.Entity `json:"e"` ActionExecutions []Execution `json:"ae"` LastUpdate int64 `json:"u"` Tries int64 `json:"t"` AdditionalData AdditionalData `json:"ad"` FifoAckEvent types.Event `json:"fev"` IsMetaAlarmUpdated bool `json:"mau,omitempty"` IsInstructionMatched bool `json:"im,omitempty"` StartEventProcessing int64 `json:"sep"` }
func (ScenarioExecution) GetCacheKey ¶
func (e ScenarioExecution) GetCacheKey() string
type ScenarioExecutionStorage ¶
type ScenarioExecutionStorage interface { Get(ctx context.Context, key string) (*ScenarioExecution, error) GetAbandoned(ctx context.Context) ([]ScenarioExecution, error) Create(ctx context.Context, execution ScenarioExecution) (bool, error) Update(ctx context.Context, execution ScenarioExecution) error Del(ctx context.Context, key string) error IncExecutingCount(ctx context.Context, key string, inc int64, drop bool) (int64, error) DelExecutingCount(ctx context.Context, key string) (int64, error) IncExecutedCount(ctx context.Context, key string, inc int64, drop bool) (int64, error) DelExecutedCount(ctx context.Context, key string) (int64, error) IncExecutedWebhookCount(ctx context.Context, key string, inc int64, drop bool) (int64, error) DelExecutedWebhookCount(ctx context.Context, key string) (int64, error) }
type ScenarioResult ¶
type ScenarioStorage ¶
type ScenarioStorage interface { // ReloadScenarios trigger a refresh on scenarios cache from DB ReloadScenarios(ctx context.Context) error // GetTriggeredScenarios returns scenarios which are triggered by triggers. GetTriggeredScenarios( triggers []string, alarm types.Alarm, ) (map[string][]Scenario, error) // RunDelayedScenarios starts delay timeout for scenarios which are triggered by triggers. RunDelayedScenarios( ctx context.Context, triggers []string, alarm types.Alarm, entity types.Entity, additionalData AdditionalData, ) error // GetScenario returns scenario. GetScenario(id string) *Scenario }
ScenarioStorage is used to provide scenarios.
func NewScenarioStorage ¶
func NewScenarioStorage( actionAdapter Adapter, delayedScenarioManager DelayedScenarioManager, logger zerolog.Logger, ) ScenarioStorage
type Service ¶
type Service interface { // Process parse an event to see if an action is suitable. Process(ctx context.Context, event *types.Event) error // ListenScenarioFinish receives message when all scenarios for event are finished // and acknowledges fifo. ListenScenarioFinish(ctx context.Context, channel <-chan ScenarioResult) // ProcessAbandonedExecutions checks execution storage and processes executions which // weren't updated for a long time ProcessAbandonedExecutions(ctx context.Context) error }
Service allows you to manipulate actions.
func NewService ¶
func NewService( alarmAdapter libalarm.Adapter, scenarioInputChan chan<- ExecuteScenariosTask, delayedScenarioManager DelayedScenarioManager, storage ScenarioExecutionStorage, encoder encoding.Encoder, decoder encoding.Decoder, fifoChan libamqp.Channel, fifoExchange string, fifoQueue string, activationService libalarm.ActivationService, techMetricsSender techmetrics.Sender, logger zerolog.Logger, ) Service
NewService gives the correct action adapter.
type Task ¶
type TaskManager ¶
type TaskManager interface { Run(ctx context.Context, rpcResultChannel <-chan RpcResult, inputChannel <-chan ExecuteScenariosTask) (<-chan ScenarioResult, error) }
TaskManager is used to execute scenarios.
func NewTaskManager ¶
func NewTaskManager( workerPool WorkerPool, executionStorage ScenarioExecutionStorage, scenarioStorage ScenarioStorage, logger zerolog.Logger, ) TaskManager
type TaskResult ¶
Click to show internal directories.
Click to hide internal directories.