summaryrefslogtreecommitdiffstats
path: root/pkg/icingadb/history/sla.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/icingadb/history/sla.go')
-rw-r--r--pkg/icingadb/history/sla.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/icingadb/history/sla.go b/pkg/icingadb/history/sla.go
new file mode 100644
index 0000000..79d22c7
--- /dev/null
+++ b/pkg/icingadb/history/sla.go
@@ -0,0 +1,26 @@
+package history
+
+import (
+ "github.com/go-redis/redis/v8"
+ "github.com/icinga/icingadb/pkg/icingadb/v1/history"
+ "github.com/icinga/icingadb/pkg/structify"
+ "github.com/icinga/icingadb/pkg/types"
+ "reflect"
+)
+
+var slaStateStructify = structify.MakeMapStructifier(reflect.TypeOf((*history.SlaHistoryState)(nil)).Elem(), "json")
+
+func stateHistoryToSlaEntity(entry redis.XMessage) ([]history.UpserterEntity, error) {
+ slaStateInterface, err := slaStateStructify(entry.Values)
+ if err != nil {
+ return nil, err
+ }
+ slaState := slaStateInterface.(*history.SlaHistoryState)
+
+ if slaState.StateType != types.StateHard {
+ // only hard state changes are relevant for SLA history, discard all others
+ return nil, nil
+ }
+
+ return []history.UpserterEntity{slaState}, nil
+}