Documentation ¶
Index ¶
- Constants
- func UnmarshalEventStreamResponse(bytes []byte) (any, error)
- type AcknowledgementCleared
- type AcknowledgementSet
- type CheckResult
- type Client
- type Comment
- type CommentAdded
- type CommentRemoved
- type Downtime
- type DowntimeAdded
- type DowntimeRemoved
- type DowntimeStarted
- type DowntimeTriggered
- type HostServiceRuntimeAttributes
- type Launcher
- type ObjectQueriesResult
- type StateChange
- type UnixFloat
Constants ¶
const ( // Acknowledgement* consts are describing an acknowledgement, e.g., from HostServiceRuntimeAttributes. AcknowledgementNone = 0 AcknowledgementNormal = 1 AcknowledgementSticky = 2 // EntryType* consts are describing an entry_type, e.g., from Comment. EntryTypeUser = 1 EntryTypeDowntime = 2 EntryTypeFlapping = 3 EntryTypeAcknowledgement = 4 // StateHost* consts are describing a host state, e.g., from CheckResult. StateHostUp = 0 StateHostDown = 1 // StateService* consts are describing a service state, e.g., from CheckResult. StateServiceOk = 0 StateServiceWarning = 1 StateServiceCritical = 2 StateServiceUnknown = 3 // StateType* consts are describing a state type, e.g., from HostServiceRuntimeAttributes. StateTypeSoft = 0 StateTypeHard = 1 )
The following const values are representing constant integer values, e.g., 0 for an OK state service.
Variables ¶
This section is empty.
Functions ¶
func UnmarshalEventStreamResponse ¶
UnmarshalEventStreamResponse unmarshal a JSON response line from the Icinga 2 API Event Stream.
The function expects an Icinga 2 API Event Stream Response in its JSON form and tries to unmarshal it into one of the implemented types based on its type argument. Thus, the returned any value will be a pointer to such a struct type.
Types ¶
type AcknowledgementCleared ¶
type AcknowledgementCleared struct { Timestamp UnixFloat `json:"timestamp"` Host string `json:"host"` Service string `json:"service"` State int `json:"state"` StateType int `json:"state_type"` }
AcknowledgementCleared represents the Icinga 2 API Event Stream AcknowledgementCleared response for acknowledgements cleared on hosts/services.
NOTE:
- An empty Service field indicates a host acknowledgement.
- State might be StateHost{Up,Down} for hosts or StateService{Ok,Warning,Critical,Unknown} for services.
- StateType might be StateTypeSoft or StateTypeHard.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-acknowledgementcleared
type AcknowledgementSet ¶
type AcknowledgementSet struct { Timestamp UnixFloat `json:"timestamp"` Host string `json:"host"` Service string `json:"service"` State int `json:"state"` StateType int `json:"state_type"` Author string `json:"author"` Comment string `json:"comment"` }
AcknowledgementSet represents the Icinga 2 API Event Stream AcknowledgementSet response for acknowledgements set on hosts/services.
NOTE:
- An empty Service field indicates a host acknowledgement.
- State might be StateHost{Up,Down} for hosts or StateService{Ok,Warning,Critical,Unknown} for services.
- StateType might be StateTypeSoft or StateTypeHard.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-acknowledgementset
type CheckResult ¶
type CheckResult struct { ExitStatus int `json:"exit_status"` Output string `json:"output"` State int `json:"state"` ExecutionStart UnixFloat `json:"execution_start"` ExecutionEnd UnixFloat `json:"execution_end"` }
CheckResult represents the Icinga 2 API CheckResult object.
https://icinga.com/docs/icinga-2/latest/doc/08-advanced-topics/#advanced-value-types-checkresult
type Client ¶
type Client struct { // ApiBaseURL et al. configure where and how the Icinga 2 API can be reached. ApiBaseURL string ApiBasicAuthUser string ApiBasicAuthPass string ApiHttpTransport http.RoundTripper // EventSourceId to be reflected in generated event.Events. EventSourceId int64 // IcingaWebRoot points to the Icinga Web 2 endpoint for generated URLs. IcingaWebRoot string // CallbackFn receives generated event.Event objects. CallbackFn func(*event.Event) // Ctx for all web requests as well as internal wait loops. The CtxCancel can be used to stop this Client. // Both fields are being populated with a new context from the NewClientFromConfig function. Ctx context.Context CtxCancel context.CancelFunc // Logger to log to. Logger *zap.SugaredLogger // contains filtered or unexported fields }
Client for the Icinga 2 Event Stream API with support for other Icinga 2 APIs to gather additional information and perform a catch-up of unknown events either when starting up to or in case of a connection loss.
Within the icinga-notifications scope, one or multiple Client instances can be generated from the configuration by calling NewClientsFromConfig.
A Client must be started by calling its Process method, which blocks until Ctx is marked as done. Reconnections and the necessary state replaying in an internal catch-up-phase from the Icinga 2 API will be taken care off. Internally, the Client executes a worker within its own goroutine, which dispatches event.Event to the CallbackFn and enforces order during catching up after (re-)connections.
func (*Client) Process ¶
func (client *Client) Process()
Process incoming events and reconnect to the Event Stream with catching up on missed objects if necessary.
This method blocks as long as the Client runs, which, unless Ctx is cancelled, is forever. While its internal loop takes care of reconnections, messages are being logged while generated event.Event will be dispatched to the CallbackFn function.
type Comment ¶
type Comment struct { Host string `json:"host_name"` Service string `json:"service_name"` Author string `json:"author"` Text string `json:"text"` EntryTime UnixFloat `json:"entry_time"` EntryType int `json:"entry_type"` }
Comment represents the Icinga 2 API Comment object.
NOTE:
- An empty Service field indicates a host comment.
- The optional EntryType should be represented by one of the EntryType* consts.
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#objecttype-comment
type CommentAdded ¶
type CommentAdded struct { Timestamp UnixFloat `json:"timestamp"` Comment Comment `json:"comment"` }
CommentAdded represents the Icinga 2 API Event Stream CommentAdded response for added host/service comments.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-commentadded
type CommentRemoved ¶
type CommentRemoved struct { Timestamp UnixFloat `json:"timestamp"` Comment Comment `json:"comment"` }
CommentRemoved represents the Icinga 2 API Event Stream CommentRemoved response for removed host/service comments.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-commentremoved
type Downtime ¶
type Downtime struct { Host string `json:"host_name"` Service string `json:"service_name"` Author string `json:"author"` Comment string `json:"comment"` }
Downtime represents the Icinga 2 API Downtime object.
NOTE:
- An empty Service field indicates a host downtime.
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#objecttype-downtime
type DowntimeAdded ¶
type DowntimeAdded struct { Timestamp UnixFloat `json:"timestamp"` Downtime Downtime `json:"downtime"` }
DowntimeAdded represents the Icinga 2 API Event Stream DowntimeAdded response for added downtimes on host/services.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-downtimeadded
type DowntimeRemoved ¶
type DowntimeRemoved struct { Timestamp UnixFloat `json:"timestamp"` Downtime Downtime `json:"downtime"` }
DowntimeRemoved represents the Icinga 2 API Event Stream DowntimeRemoved response for removed downtimes on host/services.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-commentremoved
type DowntimeStarted ¶
type DowntimeStarted struct { Timestamp UnixFloat `json:"timestamp"` Downtime Downtime `json:"downtime"` }
DowntimeStarted represents the Icinga 2 API Event Stream DowntimeStarted response for started downtimes on host/services.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-downtimestarted
type DowntimeTriggered ¶
type DowntimeTriggered struct { Timestamp UnixFloat `json:"timestamp"` Downtime Downtime `json:"downtime"` }
DowntimeTriggered represents the Icinga 2 API Event Stream DowntimeTriggered response for triggered downtimes on host/services.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-downtimetriggered
type HostServiceRuntimeAttributes ¶
type HostServiceRuntimeAttributes struct { Name string `json:"name"` Host string `json:"host_name,omitempty"` Groups []string `json:"groups"` State int `json:"state"` StateType int `json:"state_type"` LastCheckResult CheckResult `json:"last_check_result"` LastStateChange UnixFloat `json:"last_state_change"` DowntimeDepth int `json:"downtime_depth"` Acknowledgement int `json:"acknowledgement"` AcknowledgementLastChange UnixFloat `json:"acknowledgement_last_change"` }
HostServiceRuntimeAttributes are common attributes of both Host and Service objects.
When catching up potentially missed changes, the following fields are holding relevant changes which, fortunately, are identical for Icinga 2 Host and Service objects.
NOTE:
- Name is either the Host or the Service name.
- Host is empty for Host objects; Host contains the Service's Host object name for Services.
- State might be StateHost{Up,Down} for hosts or StateService{Ok,Warning,Critical,Unknown} for services.
- StateType might be StateTypeSoft or StateTypeHard.
- Acknowledgement type might be acknowledgement{None,Normal,Sticky}.
https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#host https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#service
type Launcher ¶
type Launcher struct { Ctx context.Context Logs *logging.Logging Db *icingadb.DB RuntimeConfig *config.RuntimeConfig // contains filtered or unexported fields }
Launcher allows starting a new Icinga 2 Event Stream API Client through a callback from within the config package.
This architecture became kind of necessary to work around circular imports due to the RuntimeConfig's omnipresence.
type ObjectQueriesResult ¶
type ObjectQueriesResult[T Comment | Downtime | HostServiceRuntimeAttributes] struct { Name string `json:"name"` Type string `json:"type"` Attrs T `json:"attrs"` }
ObjectQueriesResult represents the Icinga 2 API Object Queries Result wrapper object.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#object-queries-result
type StateChange ¶
type StateChange struct { Timestamp UnixFloat `json:"timestamp"` Host string `json:"host"` Service string `json:"service"` State int `json:"state"` StateType int `json:"state_type"` CheckResult CheckResult `json:"check_result"` DowntimeDepth int `json:"downtime_depth"` Acknowledgement bool `json:"acknowledgement"` }
StateChange represents the Icinga 2 API Event Stream StateChange response for host/service state changes.
NOTE:
- An empty Service field indicates a host state change.
- State might be StateHost{Up,Down} for hosts or StateService{Ok,Warning,Critical,Unknown} for services.
- StateType might be StateTypeSoft or StateTypeHard.
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#event-stream-type-statechange