From 2161ce88fa49966514a58dcf9b6d8d0d1477832d Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Mon, 29 Jul 2019 10:36:26 +0200 Subject: [PATCH] Add host and service downtimes and comments --- .../host/hostcomment/hostcomment.go | 97 ++++++++++++++++ .../host/hostdowntime/hostdowntime.go | 109 ++++++++++++++++++ .../service/servicecomment/servicecomment.go | 97 ++++++++++++++++ .../servicedowntime/servicedowntime.go | 109 ++++++++++++++++++ main.go | 8 ++ 5 files changed, 420 insertions(+) create mode 100644 configobject/objecttypes/host/hostcomment/hostcomment.go create mode 100644 configobject/objecttypes/host/hostdowntime/hostdowntime.go create mode 100644 configobject/objecttypes/service/servicecomment/servicecomment.go create mode 100644 configobject/objecttypes/service/servicedowntime/servicedowntime.go diff --git a/configobject/objecttypes/host/hostcomment/hostcomment.go b/configobject/objecttypes/host/hostcomment/hostcomment.go new file mode 100644 index 00000000..df074185 --- /dev/null +++ b/configobject/objecttypes/host/hostcomment/hostcomment.go @@ -0,0 +1,97 @@ +package hostcomment + +import ( + "git.icinga.com/icingadb/icingadb-main/configobject" + "git.icinga.com/icingadb/icingadb-main/connection" + "git.icinga.com/icingadb/icingadb-main/utils" +) + +var ( + ObjectInformation configobject.ObjectInformation + Fields = []string{ + "id", + "env_id", + "host_id", + "name_checksum", + "properties_checksum", + "name", + "author", + "text", + "entry_type", + "entry_time", + "is_persistent", + "expire_time", + "zone_id", + } +) + +type HostComment struct { + Id string `json:"id"` + EnvId string `json:"env_id"` + HostId string `json:"host_id"` + NameChecksum string `json:"name_checksum"` + PropertiesChecksum string `json:"checksum"` + Name string `json:"name"` + Author string `json:"author"` + Text string `json:"text"` + EntryType float64 `json:"entry_type"` + EntryTime float64 `json:"entry_time"` + IsPersistent bool `json:"is_persistent"` + ExpireTime float64 `json:"expire_time"` + ZoneId string `json:"zone_id"` +} + +func NewHostComment() connection.Row { + h := HostComment{} + + return &h +} + +func (h *HostComment) InsertValues() []interface{} { + v := h.UpdateValues() + + return append([]interface{}{utils.Checksum(h.Id)}, v...) +} + +func (h *HostComment) UpdateValues() []interface{} { + v := make([]interface{}, 0) + + v = append( + v, + utils.Checksum(h.EnvId), + utils.Checksum(h.HostId), + utils.Checksum(h.NameChecksum), + utils.Checksum(h.PropertiesChecksum), + h.Name, + h.Author, + h.Text, + h.EntryType, + h.EntryTime, + utils.Bool[h.IsPersistent], + h.ExpireTime, + utils.Checksum(h.ZoneId), + ) + + return v +} + +func (h *HostComment) GetId() string { + return h.Id +} + +func (h *HostComment) SetId(id string) { + h.Id = id +} + +func init() { + name := "host_comment" + ObjectInformation = configobject.ObjectInformation{ + ObjectType: name, + RedisKey: "hostcomment", + Factory: NewHostComment, + HasChecksum: true, + BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields), + BulkDeleteStmt: connection.NewBulkDeleteStmt(name), + BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields), + } +} \ No newline at end of file diff --git a/configobject/objecttypes/host/hostdowntime/hostdowntime.go b/configobject/objecttypes/host/hostdowntime/hostdowntime.go new file mode 100644 index 00000000..c682523f --- /dev/null +++ b/configobject/objecttypes/host/hostdowntime/hostdowntime.go @@ -0,0 +1,109 @@ +package hostdowntime + +import ( + "git.icinga.com/icingadb/icingadb-main/configobject" + "git.icinga.com/icingadb/icingadb-main/connection" + "git.icinga.com/icingadb/icingadb-main/utils" +) + +var ( + ObjectInformation configobject.ObjectInformation + Fields = []string{ + "id", + "env_id", + "host_id", + "name_checksum", + "properties_checksum", + "name", + "author", + "comment", + "entry_time", + "scheduled_start_time", + "scheduled_end_time", + "duration", + "is_fixed", + "is_in_effect", + "actual_start_time", + "actual_end_time", + "zone_id", + } +) + +type HostDowntime struct { + Id string `json:"id"` + EnvId string `json:"env_id"` + HostId string `json:"host_id"` + NameChecksum string `json:"name_checksum"` + PropertiesChecksum string `json:"checksum"` + Name string `json:"name"` + Author string `json:"author"` + Comment string `json:"comment"` + EntryTime float64 `json:"entry_time"` + ScheduledStartTime float64 `json:"scheduled_start_time"` + ScheduledEndTime float64 `json:"scheduled_end_time"` + Duration float64 `json:"duration"` + IsFixed bool `json:"is_fixed"` + IsInEffect bool `json:"is_in_effect"` + ActualStartTime float64 `json:"actual_start_time"` + ActualEndTime float64 `json:"actual_end_time"` + ZoneId string `json:"zone_id"` +} + +func NewHostDowntime() connection.Row { + h := HostDowntime{} + + return &h +} + +func (h *HostDowntime) InsertValues() []interface{} { + v := h.UpdateValues() + + return append([]interface{}{utils.Checksum(h.Id)}, v...) +} + +func (h *HostDowntime) UpdateValues() []interface{} { + v := make([]interface{}, 0) + + v = append( + v, + utils.Checksum(h.EnvId), + utils.Checksum(h.HostId), + utils.Checksum(h.NameChecksum), + utils.Checksum(h.PropertiesChecksum), + h.Name, + h.Author, + h.Comment, + h.EntryTime, + h.ScheduledStartTime, + h.ScheduledEndTime, + h.Duration, + utils.Bool[h.IsFixed], + utils.Bool[h.IsInEffect], + h.ActualStartTime, + h.ActualEndTime, + utils.Checksum(h.ZoneId), + ) + + return v +} + +func (h *HostDowntime) GetId() string { + return h.Id +} + +func (h *HostDowntime) SetId(id string) { + h.Id = id +} + +func init() { + name := "host_downtime" + ObjectInformation = configobject.ObjectInformation{ + ObjectType: name, + RedisKey: "hostdowntime", + Factory: NewHostDowntime, + HasChecksum: true, + BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields), + BulkDeleteStmt: connection.NewBulkDeleteStmt(name), + BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields), + } +} \ No newline at end of file diff --git a/configobject/objecttypes/service/servicecomment/servicecomment.go b/configobject/objecttypes/service/servicecomment/servicecomment.go new file mode 100644 index 00000000..784b51a1 --- /dev/null +++ b/configobject/objecttypes/service/servicecomment/servicecomment.go @@ -0,0 +1,97 @@ +package servicecomment + +import ( + "git.icinga.com/icingadb/icingadb-main/configobject" + "git.icinga.com/icingadb/icingadb-main/connection" + "git.icinga.com/icingadb/icingadb-main/utils" +) + +var ( + ObjectInformation configobject.ObjectInformation + Fields = []string{ + "id", + "env_id", + "service_id", + "name_checksum", + "properties_checksum", + "name", + "author", + "text", + "entry_type", + "entry_time", + "is_persistent", + "expire_time", + "zone_id", + } +) + +type ServiceComment struct { + Id string `json:"id"` + EnvId string `json:"env_id"` + ServiceId string `json:"service_id"` + NameChecksum string `json:"name_checksum"` + PropertiesChecksum string `json:"checksum"` + Name string `json:"name"` + Author string `json:"author"` + Text string `json:"text"` + EntryType float64 `json:"entry_type"` + EntryTime float64 `json:"entry_time"` + IsPersistent bool `json:"is_persistent"` + ExpireTime float64 `json:"expire_time"` + ZoneId string `json:"zone_id"` +} + +func NewServiceComment() connection.Row { + s := ServiceComment{} + + return &s +} + +func (s *ServiceComment) InsertValues() []interface{} { + v := s.UpdateValues() + + return append([]interface{}{utils.Checksum(s.Id)}, v...) +} + +func (s *ServiceComment) UpdateValues() []interface{} { + v := make([]interface{}, 0) + + v = append( + v, + utils.Checksum(s.EnvId), + utils.Checksum(s.ServiceId), + utils.Checksum(s.NameChecksum), + utils.Checksum(s.PropertiesChecksum), + s.Name, + s.Author, + s.Text, + s.EntryType, + s.EntryTime, + utils.Bool[s.IsPersistent], + s.ExpireTime, + utils.Checksum(s.ZoneId), + ) + + return v +} + +func (s *ServiceComment) GetId() string { + return s.Id +} + +func (s *ServiceComment) SetId(id string) { + s.Id = id +} + +func init() { + name := "service_comment" + ObjectInformation = configobject.ObjectInformation{ + ObjectType: name, + RedisKey: "servicecomment", + Factory: NewServiceComment, + HasChecksum: true, + BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields), + BulkDeleteStmt: connection.NewBulkDeleteStmt(name), + BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields), + } +} \ No newline at end of file diff --git a/configobject/objecttypes/service/servicedowntime/servicedowntime.go b/configobject/objecttypes/service/servicedowntime/servicedowntime.go new file mode 100644 index 00000000..7cf52334 --- /dev/null +++ b/configobject/objecttypes/service/servicedowntime/servicedowntime.go @@ -0,0 +1,109 @@ +package servicedowntime + +import ( + "git.icinga.com/icingadb/icingadb-main/configobject" + "git.icinga.com/icingadb/icingadb-main/connection" + "git.icinga.com/icingadb/icingadb-main/utils" +) + +var ( + ObjectInformation configobject.ObjectInformation + Fields = []string{ + "id", + "env_id", + "service_id", + "name_checksum", + "properties_checksum", + "name", + "author", + "comment", + "entry_time", + "scheduled_start_time", + "scheduled_end_time", + "duration", + "is_fixed", + "is_in_effect", + "actual_start_time", + "actual_end_time", + "zone_id", + } +) + +type ServiceDowntime struct { + Id string `json:"id"` + EnvId string `json:"env_id"` + ServiceId string `json:"service_id"` + NameChecksum string `json:"name_checksum"` + PropertiesChecksum string `json:"checksum"` + Name string `json:"name"` + Author string `json:"author"` + Comment string `json:"comment"` + EntryTime float64 `json:"entry_time"` + ScheduledStartTime float64 `json:"scheduled_start_time"` + ScheduledEndTime float64 `json:"scheduled_end_time"` + Duration float64 `json:"duration"` + IsFixed bool `json:"is_fixed"` + IsInEffect bool `json:"is_in_effect"` + ActualStartTime float64 `json:"actual_start_time"` + ActualEndTime float64 `json:"actual_end_time"` + ZoneId string `json:"zone_id"` +} + +func NewServiceDowntime() connection.Row { + s := ServiceDowntime{} + + return &s +} + +func (s *ServiceDowntime) InsertValues() []interface{} { + v := s.UpdateValues() + + return append([]interface{}{utils.Checksum(s.Id)}, v...) +} + +func (s *ServiceDowntime) UpdateValues() []interface{} { + v := make([]interface{}, 0) + + v = append( + v, + utils.Checksum(s.EnvId), + utils.Checksum(s.ServiceId), + utils.Checksum(s.NameChecksum), + utils.Checksum(s.PropertiesChecksum), + s.Name, + s.Author, + s.Comment, + s.EntryTime, + s.ScheduledStartTime, + s.ScheduledEndTime, + s.Duration, + utils.Bool[s.IsFixed], + utils.Bool[s.IsInEffect], + s.ActualStartTime, + s.ActualEndTime, + utils.Checksum(s.ZoneId), + ) + + return v +} + +func (s *ServiceDowntime) GetId() string { + return s.Id +} + +func (s *ServiceDowntime) SetId(id string) { + s.Id = id +} + +func init() { + name := "service_downtime" + ObjectInformation = configobject.ObjectInformation{ + ObjectType: name, + RedisKey: "servicedowntime", + Factory: NewServiceDowntime, + HasChecksum: true, + BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields), + BulkDeleteStmt: connection.NewBulkDeleteStmt(name), + BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields), + } +} \ No newline at end of file diff --git a/main.go b/main.go index efc20300..33a693df 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,9 @@ import ( "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/eventcommand/eventcommandcustomvar" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/eventcommand/eventcommandenvvar" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/host" + "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/host/hostcomment" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/host/hostcustomvar" + "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/host/hostdowntime" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/hostgroup" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/hostgroup/hostgroupcustomvar" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/hostgroup/hostgroupmember" @@ -32,7 +34,9 @@ import ( "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/notificationcommand/notificationcommandcustomvar" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/notificationcommand/notificationcommandenvvar" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/service" + "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/service/servicecomment" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/service/servicecustomvar" + "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/service/servicedowntime" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/servicegroup" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/servicegroup/servicegroupcustomvar" "git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/servicegroup/servicegroupmember" @@ -119,9 +123,13 @@ func startConfigSyncOperators(super *supervisor.Supervisor, haInstance *ha.HA) { objectTypes := []*configobject.ObjectInformation{ &host.ObjectInformation, &hostcustomvar.ObjectInformation, + &hostdowntime.ObjectInformation, + &hostcomment.ObjectInformation, &service.ObjectInformation, &servicecustomvar.ObjectInformation, + &servicedowntime.ObjectInformation, + &servicecomment.ObjectInformation, &hostgroup.ObjectInformation, &hostgroupcustomvar.ObjectInformation,