summaryrefslogtreecommitdiffstats
path: root/pkg/icingaredis/v1
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:36:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:36:04 +0000
commitb09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch)
treed2caec2610d4ea887803ec9e9c3cd77136c448ba /pkg/icingaredis/v1
parentInitial commit. (diff)
downloadicingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.tar.xz
icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.zip
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pkg/icingaredis/v1')
-rw-r--r--pkg/icingaredis/v1/icinga_status.go21
-rw-r--r--pkg/icingaredis/v1/stats_message.go51
2 files changed, 72 insertions, 0 deletions
diff --git a/pkg/icingaredis/v1/icinga_status.go b/pkg/icingaredis/v1/icinga_status.go
new file mode 100644
index 0000000..d94d3d6
--- /dev/null
+++ b/pkg/icingaredis/v1/icinga_status.go
@@ -0,0 +1,21 @@
+package v1
+
+import (
+ "github.com/icinga/icingadb/pkg/types"
+)
+
+// IcingaStatus defines Icinga status information.
+type IcingaStatus struct {
+ // Note: Icinga2Environment is not related to the environment_id used throughout Icinga DB.
+ Icinga2Environment string `json:"environment"`
+ NodeName string `json:"node_name"`
+ Version string `json:"version"`
+ ProgramStart types.UnixMilli `json:"program_start"`
+ EndpointId types.Binary `json:"endpoint_id"`
+ NotificationsEnabled types.Bool `json:"enable_notifications"`
+ ActiveServiceChecksEnabled types.Bool `json:"enable_service_checks"`
+ ActiveHostChecksEnabled types.Bool `json:"enable_host_checks"`
+ EventHandlersEnabled types.Bool `json:"enable_event_handlers"`
+ FlapDetectionEnabled types.Bool `json:"enable_flapping"`
+ PerformanceDataEnabled types.Bool `json:"enable_perfdata"`
+}
diff --git a/pkg/icingaredis/v1/stats_message.go b/pkg/icingaredis/v1/stats_message.go
new file mode 100644
index 0000000..5b04629
--- /dev/null
+++ b/pkg/icingaredis/v1/stats_message.go
@@ -0,0 +1,51 @@
+package v1
+
+import (
+ "github.com/icinga/icingadb/internal"
+ "github.com/icinga/icingadb/pkg/types"
+ "github.com/pkg/errors"
+)
+
+// StatsMessage represents a message from the Redis stream icinga:stats.
+type StatsMessage map[string]interface{}
+
+// Raw returns the key-value pairs of the message.
+func (m StatsMessage) Raw() map[string]interface{} {
+ return m
+}
+
+// IcingaStatus extracts Icinga status information from the message into IcingaStatus and returns it.
+func (m StatsMessage) IcingaStatus() (*IcingaStatus, error) {
+ if s, ok := m["IcingaApplication"].(string); ok {
+ var envelope struct {
+ Status struct {
+ IcingaApplication struct {
+ IcingaStatus `json:"app"`
+ } `json:"icingaapplication"`
+ } `json:"status"`
+ }
+
+ if err := internal.UnmarshalJSON([]byte(s), &envelope); err != nil {
+ return nil, err
+ }
+
+ return &envelope.Status.IcingaApplication.IcingaStatus, nil
+ }
+
+ return nil, errors.Errorf(`bad message %#v. "IcingaApplication" missing`, m)
+}
+
+// Time extracts the timestamp of the message into types.UnixMilli and returns it.
+func (m StatsMessage) Time() (*types.UnixMilli, error) {
+ if s, ok := m["timestamp"].(string); ok {
+ var t types.UnixMilli
+
+ if err := internal.UnmarshalJSON([]byte(s), &t); err != nil {
+ return nil, err
+ }
+
+ return &t, nil
+ }
+
+ return nil, errors.Errorf(`bad message %#v. "timestamp" missing`, m)
+}