types

package
v0.0.0-...-8cc84bd Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlarmStepCropMinStates = 20
	AlarmStepsHardLimit    = 2000
)

Alarm consts

View Source
const (
	RandomWithoutPrefixNamingScheme = iota
	RandomWithTimePrefixNamingScheme
	RandomWithResourcePrefix
	RandomWithConnectorPrefix
)
View Source
const (
	SourceTypeResource  = "resource"
	SourceTypeComponent = "component"
	SourceTypeWatcher   = "watcher"
	SourceTypeMetaAlarm = "metaalarm"
)

Source types

View Source
const (
	EventTypeAck                  = "ack"
	EventTypeAckremove            = "ackremove"
	EventTypeAssocTicket          = "assocticket"
	EventTypeCalendar             = "calendar"
	EventTypeCancel               = "cancel"
	EventTypeCheck                = "check"
	EventTypeComment              = "comment"
	EventTypeConsolidation        = "consolidation"
	EventTypeDeclareTicket        = "declareticket"
	EventTypeDeclareTicketWebhook = "declareticketwebhook"
	EventTypeDone                 = "done"
	EventTypeDowntime             = "downtime"
	EventTypeEue                  = "eue"
	EventTypeLog                  = "log"
	EventTypeChangestate          = "changestate"
	EventTypeKeepstate            = "keepstate"
	EventTypePBehavior            = "pbehavior"
	EventTypePerf                 = "perf"
	EventTypeSelector             = "selector"
	EventTypeSLA                  = "sla"
	EventTypeSnooze               = "snooze"
	EventTypeUnsnooze             = "unsnooze"
	EventTypeTrap                 = "trap"
	EventTypeStatCounterInc       = "statcounterinc"
	EventTypeStatDuration         = "statduration"
	EventTypeStatStateInterval    = "statstateinterval"
	EventTypeUncancel             = "uncancel"
	EventTypeUser                 = "user"
	EventTypeWatcher              = "watcher"
	EventTypeUpdateWatcher        = "updatewatcher"
	EventTypeMetaAlarm            = "metaalarm"
	EventTypePbhEnter             = "pbhenter"
	EventTypePbhLeave             = "pbhleave"
	EventTypeResolveDone          = "resolve_done"
	EventTypeResolveCancel        = "resolve_cancel"
	EventTypeResolveClose         = "resolve_close"
	EventTypeUpdateStatus         = "updatestatus"
)

Event types

View Source
const (
	AlarmStateOK = iota
	AlarmStateMinor
	AlarmStateMajor
	AlarmStateCritical
	AlarmStateUnknown
)

Alarm states

View Source
const (
	AlarmStatusOff = iota
	AlarmStatusOngoing
	AlarmStatusStealthy
	AlarmStatusFlapping
	AlarmStatusCancelled
)

Alarm statuses

View Source
const (
	AlarmStepStateIncrease  = "stateinc"
	AlarmStepStateDecrease  = "statedec"
	AlarmStepStatusIncrease = "statusinc"
	AlarmStepStatusDecrease = "statusdec"
	AlarmStepAck            = "ack"
	AlarmStepAckRemove      = "ackremove"
	AlarmStepCancel         = "cancel"
	AlarmStepUncancel       = "uncancel"
	AlarmStepComment        = "comment"
	AlarmStepDone           = "done"
	AlarmStepDeclareTicket  = "declareticket"
	AlarmStepAssocTicket    = "assocticket"
	AlarmStepSnooze         = "snooze"
	AlarmStepPbehavior      = "pbehavior"
	AlarmStepStateCounter   = "statecounter"
	AlarmStepChangeState    = "changestate"
	AlarmStepPbhEnter       = "pbhenter"
	AlarmStepPbhLeave       = "pbhleave"
)

Alarm steps

View Source
const (
	EntityTypeConnector = "connector"
	EntityTypeComponent = "component"
	EntityTypeResource  = "resource"
	EntityTypeWatcher   = "watcher"
	EntityTypeMetaAlarm = "metaalarm"
)

Entity types

View Source
const DefaultNameSchemeTemplate = "{{ rand_string 2 }}-{{ rand_string 2 }}-{{ rand_string 2 }}"
View Source
const NamingCharacterSet = "abcdefghijklmnopqrstuvwxyz1234567890"

Variables

View Source
var NumberOfCharacter = int64(len(NamingCharacterSet))

Functions

func AlarmID

func AlarmID(connector, connectorName, entityID string) string

AlarmID build an alarmid from given parameters. Used by Alarm.AlarmID()

func AsInteger

func AsInteger(value interface{}) (int64, bool)

AsInteger tries to convert an interface{} into an int64, and returns its value and an integer indicating whether it succeeded or not.

It works with int, uint, int64, uint64, CpsNumber and CpsTime (in this case, a unix timestamp is returned).

func GenDisplayName

func GenDisplayName() string

func InterfaceToString

func InterfaceToString(v interface{}) (string, error)

InterfaceToString tries to convert v to it's string value. Supported types: * float64 * string * bool * int|int64|uint|uint64 * []interface{} : join elements with "," * nil: will return empty string

Any other type will return empty string and an error, like lists or maps...

func RandString

func RandString(n int) string

RandString generate a random string

Types

type ActionParameterPBehavior

type ActionParameterPBehavior struct {
	Author string `bson:"author" json:"author"`
	Name   string `bson:"name" json:"name"`
	Reason string `bson:"reason" json:"reason"`
	Type   string `bson:"type" json:"type"`
	RRule  string `bson:"rrule" json:"rrule"`
	Tstart int64  `bson:"tstart" json:"tstart"`
	Tstop  int64  `bson:"tstop" json:"tstop"`
}

ActionParameterPBehavior is a possible parameter value for Action

type Alarm

type Alarm struct {
	ID       string     `bson:"_id" json:"_id"`
	Time     CpsTime    `bson:"t" json:"t"`
	EntityID string     `bson:"d" json:"d"`
	Value    AlarmValue `bson:"v" json:"v"`
}

Alarm represents an alarm document.

func NewAlarm

func NewAlarm(event Event) (Alarm, error)

NewAlarm creates en new Alarm from an Event

func (*Alarm) Ack

func (a *Alarm) Ack(event Event) AlarmStep

Ack an alarm

func (Alarm) AlarmComponentID

func (a Alarm) AlarmComponentID() string

AlarmComponentID is like Alarm.AlarmID() but uses Alarm.Value.Component instead of Alarm.EntityID

func (Alarm) AlarmID

func (a Alarm) AlarmID() string

AlarmID returns current alarm's alarmid.

func (*Alarm) AssocTicket

func (a *Alarm) AssocTicket(event Event) AlarmStep

AssocTicket associate a ticket number to an alarm

func (Alarm) CacheID

func (a Alarm) CacheID() string

CacheID implements cache.Cache interface

func (*Alarm) Cancel

func (a *Alarm) Cancel(event Event) AlarmStep

Cancel cancel an alarm

func (*Alarm) ChangeState

func (a *Alarm) ChangeState(event Event) AlarmStep

ChangeState force the state of an alarm

func (*Alarm) ChangeStateFromAction

func (a *Alarm) ChangeStateFromAction(timestamp CpsTime, msg, author string, state CpsNumber) AlarmStep

ChangeStateFromAction force the state of an alarm by action

func (Alarm) Closable

func (a Alarm) Closable(baggotTime time.Duration) bool

Closable checks the last step for it's state to be OK for at least baggotTime. Reference time is time.Now() when this function is called.

func (*Alarm) Comment

func (a *Alarm) Comment(event Event) AlarmStep

Comment comment an alarm

func (*Alarm) ComputeStatus

func (a *Alarm) ComputeStatus() CpsNumber

ComputeStatus of an Alarm from an Event

func (*Alarm) CropSteps

func (a *Alarm) CropSteps() bool

CropSteps calls Crop() on Alarm.Value.Steps with alarm parameters. returns true if the alarm was modified.

func (*Alarm) CurrentState

func (a *Alarm) CurrentState() CpsNumber

CurrentState returns the Current State of the Alarm

func (*Alarm) CurrentStatus

func (a *Alarm) CurrentStatus() CpsNumber

CurrentStatus returns the Current status of the alarm

func (*Alarm) DeclareTicket

func (a *Alarm) DeclareTicket(event Event) AlarmStep

DeclareTicket ask for a creation

func (*Alarm) Done

func (a *Alarm) Done(event Event) AlarmStep

Done mark an alarm as done

func (Alarm) HasSingleAck

func (a Alarm) HasSingleAck() bool

HasSingleAck returns true if the alarm has been acknowledged exactly once. Note that this method will return false if the alarm has received a first ack, an ackremove, and a second ack. It should be used to run actions on the first acknowledgement only.

func (Alarm) IsAck

func (a Alarm) IsAck() bool

IsAck check if an Alarm is acked

func (Alarm) IsCanceled

func (a Alarm) IsCanceled() bool

IsCanceled check if an Alarm is canceled

func (Alarm) IsFlapping

func (a Alarm) IsFlapping() bool

IsFlapping check if an Alarm is currently flapping

func (Alarm) IsMalfunctioning

func (a Alarm) IsMalfunctioning() bool

IsMalfunctioning...

func (Alarm) IsMatched

func (a Alarm) IsMatched(regex string, fields []string) bool

IsMatched tell if an alarm is catched by a regex

func (Alarm) IsMetaAlarm

func (a Alarm) IsMetaAlarm() bool

func (Alarm) IsMetaChildren

func (a Alarm) IsMetaChildren() bool

func (*Alarm) IsResolved

func (a *Alarm) IsResolved() bool

IsResolved tell if an alarm has been resolved

func (Alarm) IsSnoozed

func (a Alarm) IsSnoozed() bool

IsSnoozed check if an Alarm is snoozed

func (*Alarm) IsStateLocked

func (a *Alarm) IsStateLocked() bool

IsStateLocked checks that the Alarm is not Locked (by manual intervention for example)

func (Alarm) IsStealthy

func (a Alarm) IsStealthy() bool

IsStealthy checks if an Alarm is currently stealthy

func (*Alarm) PbhEnter

func (a *Alarm) PbhEnter(event Event) AlarmStep

func (*Alarm) PbhLeave

func (a *Alarm) PbhLeave(event Event) AlarmStep

func (*Alarm) Resolve

func (a *Alarm) Resolve(timestamp *CpsTime)

Resolve mark as resolved an Alarm with a timestamp [sic]

func (*Alarm) ResolveCancel

func (a *Alarm) ResolveCancel(timestamp *CpsTime)

ResolveCancel forces alarm resolution on cancel

func (*Alarm) Snooze

func (a *Alarm) Snooze(timestamp CpsTime, duration CpsNumber, author string, output string, role string) (AlarmStep, error)

Snooze apply a snooze step to an Alarm

func (*Alarm) SnoozeFromEvent

func (a *Alarm) SnoozeFromEvent(event Event) (AlarmStep, error)

SnoozeFromEvent apply a snooze step to an Alarm

func (*Alarm) Ticket

func (a *Alarm) Ticket(stepType string, timestamp CpsTime, author string, ticketNumber string, role string, data map[string]string) AlarmStep

Ticket add a ticket on an alarm

func (*Alarm) UnSnooze

func (a *Alarm) UnSnooze()

UnSnooze cancel a snooze

func (*Alarm) Unack

func (a *Alarm) Unack(event Event) AlarmStep

Unack removes an ack on an alarm

func (*Alarm) Uncancel

func (a *Alarm) Uncancel(event Event) AlarmStep

Uncancel uncancel an alarm

func (*Alarm) Update

func (a *Alarm) Update(e Event) bool

Update an alarm from an Event

func (*Alarm) UpdateLongOutput

func (a *Alarm) UpdateLongOutput(newOutput string)

UpdateLongOutput updates an alarm output field

func (*Alarm) UpdateOutput

func (a *Alarm) UpdateOutput(newOutput string)

UpdateOutput updates an alarm output field

func (*Alarm) UpdateState

func (a *Alarm) UpdateState(stateValue CpsNumber, ts CpsTime)

UpdateState updates alarm's state to stateValue if it worst

func (*Alarm) UpdateStatus

func (a *Alarm) UpdateStatus(timestamp CpsTime, author, message string) bool

UpdateStatus recomputes the status of the alarm. If the status changes, a new step is added to the alarm, with the timestamp, author and message given in parameters.

type AlarmChange

type AlarmChange struct {
	Type                 AlarmChangeType
	PreviousState        CpsNumber
	PreviousStateChange  CpsTime
	PreviousStatus       CpsNumber
	PreviousStatusChange CpsTime
}

AlarmChange is a struct containing the type of change that occured on an alarm, as well as its previous state.

func NewAlarmChange

func NewAlarmChange() AlarmChange

func (*AlarmChange) Triggers

func (ac *AlarmChange) Triggers(triggerName string) bool

type AlarmChangeType

type AlarmChangeType string

AlarmChangeType is a type representing a change that can occur on an alarm.

const (
	AlarmChangeTypeNone                 AlarmChangeType = ""
	AlarmChangeTypeStateIncrease        AlarmChangeType = "stateinc"
	AlarmChangeTypeStateDecrease        AlarmChangeType = "statedec"
	AlarmChangeTypeCreate               AlarmChangeType = "create"
	AlarmChangeTypeAck                  AlarmChangeType = "ack"
	AlarmChangeTypeAckremove            AlarmChangeType = "ackremove"
	AlarmChangeTypeCancel               AlarmChangeType = "cancel"
	AlarmChangeTypeUncancel             AlarmChangeType = "uncancel"
	AlarmChangeTypeDeclareTicket        AlarmChangeType = "declareticket"
	AlarmChangeTypeDeclareTicketWebhook AlarmChangeType = "declareticketwebhook"
	AlarmChangeTypeAssocTicket          AlarmChangeType = "assocticket"
	AlarmChangeTypeSnooze               AlarmChangeType = "snooze"
	AlarmChangeTypeUnsnooze             AlarmChangeType = "unsnooze"
	AlarmChangeTypeResolve              AlarmChangeType = "resolve"
	AlarmChangeTypeDone                 AlarmChangeType = "done"
	AlarmChangeTypeComment              AlarmChangeType = "comment"
	AlarmChangeTypeChangeState          AlarmChangeType = "changestate"
	AlarmChangeTypePbhEnter             AlarmChangeType = "pbhenter"
	AlarmChangeTypePbhLeave             AlarmChangeType = "pbhleave"
	AlarmChangeTypeUpdateStatus         AlarmChangeType = "changestatus"
)

An AlarmChangeType can have the following values:

type AlarmStep

type AlarmStep struct {
	Type         string      `bson:"_t" json:"_t"`
	Timestamp    CpsTime     `bson:"t" json:"t"`
	Author       string      `bson:"a" json:"a"`
	Message      string      `bson:"m" json:"m"`
	Role         string      `bson:"role,omitempty" json:"role,omitempty"`
	Value        CpsNumber   `bson:"val" json:"val"`
	StateCounter CropCounter `bson:"statecounter,omitempty" json:"statecounter,omitempty"`
}

AlarmStep represents a generic step used in an alarm.

func NewAlarmStep

func NewAlarmStep(stepType string, timestamp CpsTime, author string, msg string, role string) AlarmStep

NewAlarmStep returns an AlarmStep. If the timestamp or author are empty, default values will be used to create an AlarmStep.

func NewAlarmStepFromAction

func NewAlarmStepFromAction(stepType string, event Event) AlarmStep

func NewAlarmStepFromEvent

func NewAlarmStepFromEvent(stepType string, event Event) AlarmStep

NewAlarmStepFromEvent returns an AlarmStep.

func (AlarmStep) NewTicket

func (s AlarmStep) NewTicket(value string, data map[string]string) AlarmTicket

NewTicket creates a Ticket Step from a normal step TODO: annihilate this heresy (Ticket has a distinct format from other classical steps !)

type AlarmSteps

type AlarmSteps []AlarmStep

AlarmSteps is a sortable implementation of []*AlarmStep. Used for sorting steps in some functions. Implements sort.Interface

func (*AlarmSteps) Add

func (s *AlarmSteps) Add(step AlarmStep) error

Add handle adding a step to the list

func (AlarmSteps) Crop

func (s AlarmSteps) Crop(currentStatus *AlarmStep, cropNum int) (AlarmSteps, bool)

Crop steps by replacing stateinc and statedec steps after the current status with a statecounter step Returns :

  • the updated alarm steps
  • True if it was updated, false else

param currentStatus: the current status of the alarm. The steps will be cropped from this status param cropNum: crop only if we have at least cropNum steps with type AlarmStepStateIncrease or AlarmStepStateDecrease

func (AlarmSteps) Last

func (s AlarmSteps) Last() (AlarmStep, error)

Last returns the last step, if any, or returns an error.

func (AlarmSteps) UpdateStateCounter

func (s AlarmSteps) UpdateStateCounter(currentStatus *AlarmStep, currentStatusIdx int, counter CropCounter) AlarmSteps

UpdateStateCounter updates the alarm steps with the statecounter step Returns the updated AlarmSteps and the updated (or newly created) statecounter step. param currentStatus: the current status of the alarm. The statecounter step infos will come from it. param currentStatusIdx: the alarm current status' index. It is used to insert or update the statecounter step right after it. param counter: the crop counter to update or create the statecounter step from.

type AlarmTicket

type AlarmTicket struct {
	Type      string  `bson:"_t" json:"_t"`
	Timestamp CpsTime `bson:"t" json:"t"`
	Author    string  `bson:"a" json:"a"`
	Message   string  `bson:"m" json:"m"`
	Role      string  `bson:"role,omitempty" json:"role,omitempty"`
	Value     string  `bson:"val" json:"val"`
	Data      map[string]string
}

AlarmTicket step is distinct from generic alarm step because value is a string TODO: move string value to message (and in py and js too)

type AlarmValue

type AlarmValue struct {
	ACK               *AlarmStep   `bson:"ack,omitempty" json:"ack,omitempty"`
	Canceled          *AlarmStep   `bson:"canceled,omitempty" json:"canceled,omitempty"`
	Done              *AlarmStep   `bson:"done,omitempty" json:"done,omitempty"`
	Snooze            *AlarmStep   `bson:"snooze,omitempty" json:"snooze,omitempty"`
	State             *AlarmStep   `bson:"state,omitempty" json:"state,omitempty"`
	Status            *AlarmStep   `bson:"status,omitempty" json:"status,omitempty"`
	Ticket            *AlarmTicket `bson:"ticket,omitempty" json:"ticket,omitempty"`
	Steps             AlarmSteps   `bson:"steps" json:"steps"`
	Component         string       `bson:"component" json:"component"`
	Connector         string       `bson:"connector" json:"connector"`
	ConnectorName     string       `bson:"connector_name" json:"connector_name"`
	CreationDate      CpsTime      `bson:"creation_date" json:"creation_date"`
	DisplayName       string       `bson:"display_name" json:"display_name"`
	HardLimit         *CpsNumber   `bson:"hard_limit,omitempty" json:"hard_limit,omitempty"`
	InitialOutput     string       `bson:"initial_output" json:"initial_output"`
	Output            string       `bson:"output" json:"output"`
	InitialLongOutput string       `bson:"initial_long_output" json:"initial_long_output"`
	LongOutput        string       `bson:"long_output" json:"long_output"`
	LongOutputHistory []string     `bson:"long_output_history" json:"long_output_history"`
	LastUpdateDate    CpsTime      `bson:"last_update_date" json:"last_update_date"`
	LastEventDate     CpsTime      `bson:"last_event_date" json:"last_event_date"`
	Resource          string       `bson:"resource,omitempty" json:"resource,omitempty"`
	Resolved          *CpsTime     `bson:"resolved,omitempty" json:"resolved,omitempty"`
	Tags              []string     `bson:"tags" json:"tags"`
	Meta              string       `bson:"meta,omitempty" json:"meta,omitempty"`

	Parents  []string `bson:"parents" json:"parents"`
	Children []string `bson:"children" json:"children"`

	StateChangesSinceStatusUpdate CpsNumber `bson:"state_changes_since_status_update,omitempty" json:"state_changes_since_status_update,omitempty"`
	TotalStateChanges             CpsNumber `bson:"total_state_changes,omitempty" json:"total_state_changes,omitempty"`

	Extra map[string]interface{}       `bson:"extra" json:"extra"`
	Infos map[string]map[string]string `bson:"infos" json:"infos"`

	// store version of dynamic-infos rule
	RuleVersion map[string]string `bson:"infos_rule_version"`
}

AlarmValue represents a full description of an alarm.

func (*AlarmValue) Transform

func (v *AlarmValue) Transform()

type AlarmWithEntity

type AlarmWithEntity struct {
	Alarm  Alarm  `bson:"alarm" json:"alarm"`
	Entity Entity `bson:"entity" json:"entity"`
}

AlarmWithEntity is an encapsulated type, mostly to facilitate the alarm manipulation for the post-processors

type ContextInformation

type ContextInformation struct {
	ID      string // Entity ID
	Name    string
	Type    string
	Impacts []string
	Depends []string
}

ContextInformation regroup context values necessary for creating a new entity

func (*ContextInformation) NewEntity

func (ci *ContextInformation) NewEntity() Entity

NewEntity create an entity from ContextInformation struct

type CpsDuration

type CpsDuration time.Duration

CpsDuration allow conversions from/to time.Duration to/from string

func (CpsDuration) Duration

func (t CpsDuration) Duration() time.Duration

Duration return the CpsDuration casted to time.Duration

func (CpsDuration) GetBSON

func (t CpsDuration) GetBSON() (interface{}, error)

GetBSON implements the bson.Getter interface

func (CpsDuration) MarshalJSON

func (t CpsDuration) MarshalJSON() ([]byte, error)

MarshalJSON converts a CpsDuration to string

func (*CpsDuration) SetBSON

func (t *CpsDuration) SetBSON(raw bson.Raw) error

SetBSON implements the bson.Setter interface

func (*CpsDuration) UnmarshalJSON

func (t *CpsDuration) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a string to CpsDuration

type CpsNumber

type CpsNumber int64

CpsNumber is here for compatibility with old python engines. It will force an int64 from a float64.

func (CpsNumber) CpsTimestamp

func (t CpsNumber) CpsTimestamp() CpsTime

CpsTimestamp convert a number to a timestamp

func (CpsNumber) Float64

func (t CpsNumber) Float64() float64

Float64 ...

func (CpsNumber) GetBSON

func (t CpsNumber) GetBSON() (interface{}, error)

GetBSON implements bson.Getter interface

func (CpsNumber) MarshalJSON

func (t CpsNumber) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Encoder interface

func (*CpsNumber) SetBSON

func (t *CpsNumber) SetBSON(raw bson.Raw) error

SetBSON implements bson.Setter interface

func (*CpsNumber) UnmarshalJSON

func (t *CpsNumber) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Decoder interface

type CpsTime

type CpsTime struct {
	time.Time
}

CpsTime allows conversion from time.Time to time.Time.Unix()

func NewCpsTime

func NewCpsTime(timestamp int64) CpsTime

NewCpsTime create a CpsTime from a timestamp

func (CpsTime) Format

func (t CpsTime) Format() string

Format easilly format a CpsTime as a string

func (CpsTime) GetBSON

func (t CpsTime) GetBSON() (interface{}, error)

GetBSON implements the bson.Getter interface

func (CpsTime) MarshalJSON

func (t CpsTime) MarshalJSON() ([]byte, error)

MarshalJSON converts from CpsTime to timestamp as bytes

func (*CpsTime) SetBSON

func (t *CpsTime) SetBSON(raw bson.Raw) error

SetBSON implements the bson.Setter interface

func (*CpsTime) UnmarshalJSON

func (t *CpsTime) UnmarshalJSON(b []byte) error

UnmarshalJSON converts from string to CpsTime

type CropCounter

type CropCounter struct {
	StateChanges  int `bson:"statechanges" json:"statechanges"`
	Stateinc      int `bson:"stateinc" json:"stateinc"`
	Statedec      int `bson:"statedec" json:"statedec"`
	StateInfo     int `bson:"state:0,omitempty" json:"state:0,omitempty"`
	StateMinor    int `bson:"state:1,omitempty" json:"state:1,omitempty"`
	StateMajor    int `bson:"state:2,omitempty" json:"state:2,omitempty"`
	StateCritical int `bson:"state:3,omitempty" json:"state:3,omitempty"`
}

CropCounter provides an explicit way of counting the steps that were cropped.

func (*CropCounter) MergeCounter

func (counter *CropCounter) MergeCounter(secondCounter CropCounter)

MergeCounter merges the current counter with the provided counter and returns the merged counter.

func (*CropCounter) UpdateWithStep

func (counter *CropCounter) UpdateWithStep(step AlarmStep)

UpdateWithStep updates the CropCounter with the provided step informations.

type DedupList

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

DedupList is not to be used directly, use NewDedupList instead.

func NewDedupList

func NewDedupList(rawlist ...string) DedupList

NewDedupList creates a new DedupList struct.

func (*DedupList) Add

func (i *DedupList) Add(items ...string)

Add some items to the list

func (*DedupList) Del

func (i *DedupList) Del(items ...string)

Del some items from the list. This function is VERY slow, avoid making multiple calls since for each call if the DedupList has to be modified, the internal cached list is recomputed. Prefer call Del(items...) where items is a []string

func (*DedupList) EnsureInitialized

func (i *DedupList) EnsureInitialized()

EnsureInitialized ensure internal states to be initialized

func (DedupList) Exists

func (i DedupList) Exists(item string) bool

Exists returns true if the item exists in the list

func (DedupList) GetBSON

func (i DedupList) GetBSON() (interface{}, error)

GetBSON ...

func (DedupList) List

func (i DedupList) List() []string

List returns an unordered slice

func (DedupList) Map

func (i DedupList) Map() map[string]bool

Map returns a copy of the underlying map[string]bool The bool value has no meaning, it's only here so we can deduplicate using a standard map.

func (DedupList) MarshalBinary

func (i DedupList) MarshalBinary() ([]byte, error)

MarshalBinary ...

func (DedupList) MarshalJSON

func (i DedupList) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Encoder

func (*DedupList) SetBSON

func (i *DedupList) SetBSON(raw bson.Raw) error

SetBSON ...

func (*DedupList) UnmarshalBinary

func (i *DedupList) UnmarshalBinary(in []byte) error

UnmarshalBinary ...

func (*DedupList) UnmarshalJSON

func (i *DedupList) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Decoder

type Entity

type Entity struct {
	ID            string    `bson:"_id" json:"_id"`
	Name          string    `bson:"name" json:"name"`
	Impacts       []string  `bson:"impact" json:"impact"`
	Depends       []string  `bson:"depends" json:"depends"`
	EnableHistory []CpsTime `bson:"enable_history" json:"enable_history"`
	//Measurements  *[]Measurement `bson:"measurements" json:"measurements"`
	Measurements interface{}     `bson:"measurements" json:"measurements"` // unused collection ids
	Enabled      bool            `bson:"enabled" json:"enabled"`
	Infos        map[string]Info `bson:"infos" json:"infos"`
	Type         string          `bson:"type" json:"type"`
	Component    string          `bson:"component,omitempty" json:"component,omitempty"`
}

Entity ...

func NewEntity

func NewEntity(id string, name string, entityType string, infos map[string]Info, impacts, depends []string) Entity

NewEntity instanciate a new entity struct [sic]

func (Entity) CacheID

func (e Entity) CacheID() string

CacheID implements cache.Cache interface

func (*Entity) EnsureInitialized

func (e *Entity) EnsureInitialized()

EnsureInitialized verifies that all complex structs are well initialized

func (*Entity) GetUpsertMongoBson

func (e *Entity) GetUpsertMongoBson(newImpacts []string, newDepends []string) bson.M

type Event

type Event struct {
	ID            *string                `bson:"_id" json:"_id"`
	Connector     string                 `bson:"connector" json:"connector"`
	ConnectorName string                 `bson:"connector_name" json:"connector_name"`
	EventType     string                 `bson:"event_type" json:"event_type"`
	Component     string                 `bson:"component" json:"component"`
	Resource      string                 `bson:"resource" json:"resource"`
	PerfData      *string                `bson:"perf_data" json:"perf_data"`
	PerfDataArray []PerfData             `bson:"perf_data_array" json:"perf_data_array"`
	Status        *CpsNumber             `bson:"status" json:"status"`
	Timestamp     CpsTime                `bson:"timestamp" json:"timestamp"`
	StateType     *CpsNumber             `bson:"state_type" json:"state_type"`
	SourceType    string                 `bson:"source_type" json:"source_type"`
	LongOutput    string                 `bson:"long_output" json:"long_output"`
	State         CpsNumber              `bson:"state" json:"state"`
	Output        string                 `bson:"output" json:"output"`
	Alarm         *Alarm                 `bson:"current_alarm" json:"current_alarm"`
	Entity        *Entity                `bson:"current_entity" json:"current_entity"`
	Author        string                 `bson:"author" json:"author"`
	RK            string                 `bson:"routing_key" json:"routing_key"`
	AckResources  bool                   `json:"ack_resources"`
	Duration      *CpsNumber             `json:"duration"`
	Ticket        string                 `bson:"ticket" json:"ticket"`
	StatName      string                 `bson:"stat_name" json:"stat_name"`
	Debug         bool                   `bson:"debug" json:"debug"`
	Role          string                 `bson:"role,omitempty" json:"role,omitempty"`
	ExtraInfos    map[string]interface{} `json:"extra"`
	AlarmChange   *AlarmChange           `bson:"alarm_change" json:"alarm_change"`

	MetaAlarmRuleID string `bson:"metaalarm_rule_id" json:"metaalarm_rule_id"`

	MetaAlarmParents  *[]string `bson:"ma_parents" json:"ma_parents"`
	MetaAlarmChildren *[]string `bson:"ma_children" json:"ma_children"`
}

Event represents a canopsis event.

func NewEventFromAlarm

func NewEventFromAlarm(alarm Alarm) Event

func NewEventFromJSON

func NewEventFromJSON(body []byte) (Event, error)

NewEventFromJSON create an Event from a raw json

func (*Event) Format

func (e *Event) Format()

Format an event

"timestamp" is fill with time.Now()
"event_type" is fill with EventTypeCheck
if "entity" is not null, "impacts" and "depends" are ensured to be initialized

func (*Event) GenerateContextInformations

func (e *Event) GenerateContextInformations() []ContextInformation

GenerateContextInformations generate connector, component and resource entity informations. First element is always connector Second element is always component Third element doesnt exists if event is not SourceTypeResource, otherwise it is resource

func (*Event) GetCompatRK

func (e *Event) GetCompatRK() string

GetCompatRK returns the event routing key. For compatibility only with old engines.

func (*Event) GetEID

func (e *Event) GetEID() string

GetEID generates an eid from an event

func (*Event) GetLockID

func (e *Event) GetLockID() string

GetLockID returns lock name that used to block alarm

func (*Event) GetRequiredKeys

func (e *Event) GetRequiredKeys() []string

GetRequiredKeys read all declared json tags in the struct

func (*Event) InjectExtraInfos

func (e *Event) InjectExtraInfos(source []byte) error

InjectExtraInfos takes the raw JSON event document and puts any unknown field into Event.ExtraInfos

func (Event) IsContextable

func (e Event) IsContextable() bool

IsContextable tells you if the given event can lead to context enrichment.

func (Event) IsMatched

func (e Event) IsMatched(regex string, fields []string) bool

IsMatched tell if an event is catched by a regex

func (Event) IsValid

func (e Event) IsValid() error

IsValid checks if an Event is valid for Canopsis processing. the error returned, if any, is of type errt.UnknownError

func (*Event) SetField

func (e *Event) SetField(name string, value interface{}) (err error)

SetField sets the value of a field of an event given its name.

type GenericEvent

type GenericEvent struct {
	Content interface{}
}

GenericEvent contains an interface so you can do this: body := `<a json document>` var gevent GenericEvent json.Unmarshal(body, &gevent.Content) gevent.PartialID(<rules>)

func (*GenericEvent) JSONUnmarshal

func (e *GenericEvent) JSONUnmarshal(body []byte) error

JSONUnmarshal is a shortcut for this: var event GenericEvent json.Unmarshal(body, &event.Content)

func (*GenericEvent) PartialID

func (e *GenericEvent) PartialID(heartBeatItem heartbeat.Item) (string, error)

PartialID builds the event ID, as a string, from the heartBeatItem configuration. Given this event:

{
	"connector": "zabbix",
	"connector_name": "instance1",
	"component": "localhost",
	...
}

And the given heartBeatItem:

li := NewHeartBeatItem(time.Minute*5) li.AddMapping("connector", "zabbix") li.AddMapping("connector_name", "instance1")

PartialID will return "connector:zabbix.connector_name:instance1" as ID. Keys will alphabetically sorted!

type Info

type Info struct {
	Name        string      `bson:"name,omitempty" json:"name"`
	Description string      `bson:"description,omitempty" json:"description"`
	Value       string      `bson:"-" json:"value"`
	RealValue   interface{} `bson:"value,omitempty"`
}

Info contain extra values for the entity

func NewInfo

func NewInfo(name string, description string, realValue interface{}) Info

NewInfo instanciate a new info struct [sic]

func (*Info) SetBSON

func (info *Info) SetBSON(raw bson.Raw) error

type PBehavior

type PBehavior struct {
	ID            string            `bson:"_id,omitempty" json:"_id,omitempty"`
	Author        string            `bson:"author" json:"author"`
	Comments      PBehaviorComments `bson:"comments,omitempty" json:"comments,omitempty"`
	Connector     string            `bson:"connector" json:"connector"`
	ConnectorName string            `bson:"connector_name" json:"connector_name"`
	Eids          []string          `bson:"eids,omitempty" json:"eids,omitempty"`
	Enabled       bool              `bson:"enabled" json:"enabled"`
	Filter        string            `bson:"filter" json:"filter"`
	Name          string            `bson:"name" json:"name"`
	Reason        string            `bson:"reason" json:"reason"`
	RRule         string            `bson:"rrule" json:"rrule"`
	Start         *CpsTime          `bson:"tstart" json:"tstart"`
	Stop          *CpsTime          `bson:"tstop" json:"tstop"`
	Type          string            `bson:"type_" json:"type_"`
	Timezone      string            `bson:"timezone,omitempty" json:"timezone"`
	Exdate        []CpsTime         `bson:"exdate" json:"exdate"`
}

PBehavior represents a canopsis periodical behavior.

func NewPBehavior

func NewPBehavior(author, filter, name, reason, type_, rrule string, start, stop *CpsTime, timezone string, exdate []CpsTime) PBehavior

NewPBehavior instanciate a new pbehavior

func (PBehavior) IsActive

func (pb PBehavior) IsActive(date time.Time) (bool, error)

IsActive checks if a pbehavior is active at the given time.

func (PBehavior) IsImpacted

func (pb PBehavior) IsImpacted(eid string) bool

IsImpacted checks if an entity id is impacted by a pbehavior

type PBehaviorComment

type PBehaviorComment struct {
	ID        string   `bson:"_id" json:"_id"`
	Author    string   `bson:"author" json:"author"`
	Timestamp *CpsTime `bson:"ts" json:"ts"`
	Message   string   `bson:"message" json:"message"`
}

PBehavior represents a comment in a PBehavior.

type PBehaviorComments

type PBehaviorComments []*PBehaviorComment

type PerfData

type PerfData struct {
	Metric string  `bson:"metric" json:"metric"`
	Unit   string  `bson:"unit" json:"unit"`
	Value  float64 `bson:"value" json:"value"`
}

PerfData represents a perf data array

Jump to

Keyboard shortcuts

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