mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Add notification
This commit is contained in:
parent
583289280e
commit
fb804bd4e3
5 changed files with 332 additions and 0 deletions
116
configobject/objecttypes/notification/notification.go
Normal file
116
configobject/objecttypes/notification/notification.go
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
package notification
|
||||
|
||||
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",
|
||||
"name_checksum",
|
||||
"properties_checksum",
|
||||
"customvars_checksum",
|
||||
"users_checksum",
|
||||
"usergroups_checksum",
|
||||
"name",
|
||||
"name_ci",
|
||||
"host_id",
|
||||
"service_id",
|
||||
"command_id",
|
||||
"times_begin",
|
||||
"times_end",
|
||||
"notification_interval",
|
||||
"period_id",
|
||||
"states",
|
||||
"types",
|
||||
"zone_id",
|
||||
}
|
||||
)
|
||||
|
||||
type Notification struct {
|
||||
Id string `json:"id"`
|
||||
EnvId string `json:"env_id"`
|
||||
NameChecksum string `json:"name_checksum"`
|
||||
PropertiesChecksum string `json:"checksum"`
|
||||
CustomvarsChecksum string `json:"customvars_checksum"`
|
||||
UsersChecksum string `json:"users_checksum"`
|
||||
UsergroupsChecksum string `json:"usergroups_checksum"`
|
||||
Name string `json:"name"`
|
||||
NameCi *string `json:"name_ci"`
|
||||
HostId string `json:"host_id"`
|
||||
ServiceId string `json:"service_id"`
|
||||
CommandId string `json:"command_id"`
|
||||
TimesBegin float32 `json:"times_begin"`
|
||||
TimesEnd float32 `json:"times_end"`
|
||||
NotificationInterval float32 `json:"notification_interval"`
|
||||
PeriodId string `json:"period_id"`
|
||||
States []string `json:"states"`
|
||||
Types []string `json:"types"`
|
||||
ZoneId string `json:"zone_id"`
|
||||
}
|
||||
|
||||
func NewNotification() connection.Row {
|
||||
n := Notification{}
|
||||
n.NameCi = &n.Name
|
||||
|
||||
return &n
|
||||
}
|
||||
|
||||
func (n *Notification) InsertValues() []interface{} {
|
||||
v := n.UpdateValues()
|
||||
|
||||
return append([]interface{}{utils.Checksum(n.Id)}, v...)
|
||||
}
|
||||
|
||||
func (n *Notification) UpdateValues() []interface{} {
|
||||
v := make([]interface{}, 0)
|
||||
|
||||
v = append(
|
||||
v,
|
||||
utils.Checksum(n.EnvId),
|
||||
utils.Checksum(n.NameChecksum),
|
||||
utils.Checksum(n.PropertiesChecksum),
|
||||
utils.Checksum(n.CustomvarsChecksum),
|
||||
utils.Checksum(n.UsersChecksum),
|
||||
utils.Checksum(n.UsergroupsChecksum),
|
||||
n.Name,
|
||||
n.NameCi,
|
||||
utils.Checksum(n.HostId),
|
||||
utils.Checksum(n.ServiceId),
|
||||
utils.Checksum(n.CommandId),
|
||||
n.TimesBegin,
|
||||
n.TimesEnd,
|
||||
n.NotificationInterval,
|
||||
utils.Checksum(n.PeriodId),
|
||||
utils.NotificationStatesToBitMask(n.States),
|
||||
utils.NotificationTypesToBitMask(n.Types),
|
||||
utils.Checksum(n.ZoneId),
|
||||
)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (n *Notification) GetId() string {
|
||||
return n.Id
|
||||
}
|
||||
|
||||
func (n *Notification) SetId(id string) {
|
||||
n.Id = id
|
||||
}
|
||||
|
||||
func init() {
|
||||
name := "notification"
|
||||
ObjectInformation = configobject.ObjectInformation{
|
||||
ObjectType: name,
|
||||
RedisKey: name,
|
||||
Factory: NewNotification,
|
||||
HasChecksum: true,
|
||||
BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields),
|
||||
BulkDeleteStmt: connection.NewBulkDeleteStmt(name),
|
||||
BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields),
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package notificationcustomvar
|
||||
|
||||
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",
|
||||
"notification_id",
|
||||
"customvar_id",
|
||||
"env_id",
|
||||
}
|
||||
)
|
||||
|
||||
type NotificationCustomvar struct {
|
||||
Id string `json:"id"`
|
||||
NotificationId string `json:"object_id"`
|
||||
CustomvarId string `json:"customvar_id"`
|
||||
EnvId string `json:"env_id"`
|
||||
}
|
||||
|
||||
func NewNotificationCustomvar() connection.Row {
|
||||
c := NotificationCustomvar{}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c *NotificationCustomvar) InsertValues() []interface{} {
|
||||
v := c.UpdateValues()
|
||||
|
||||
return append([]interface{}{utils.Checksum(c.Id)}, v...)
|
||||
}
|
||||
|
||||
func (c *NotificationCustomvar) UpdateValues() []interface{} {
|
||||
v := make([]interface{}, 0)
|
||||
|
||||
v = append(
|
||||
v,
|
||||
utils.Checksum(c.NotificationId),
|
||||
utils.Checksum(c.CustomvarId),
|
||||
utils.Checksum(c.EnvId),
|
||||
)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (c *NotificationCustomvar) GetId() string {
|
||||
return c.Id
|
||||
}
|
||||
|
||||
func (c *NotificationCustomvar) SetId(id string) {
|
||||
c.Id = id
|
||||
}
|
||||
|
||||
func init() {
|
||||
name := "notification_customvar"
|
||||
ObjectInformation = configobject.ObjectInformation{
|
||||
ObjectType: name,
|
||||
RedisKey: "notification:customvar",
|
||||
Factory: NewNotificationCustomvar,
|
||||
HasChecksum: false,
|
||||
BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields),
|
||||
BulkDeleteStmt: connection.NewBulkDeleteStmt(name),
|
||||
BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields),
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package notificationuser
|
||||
|
||||
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",
|
||||
"notification_id",
|
||||
"user_id",
|
||||
"env_id",
|
||||
}
|
||||
)
|
||||
|
||||
type NotificationUser struct {
|
||||
Id string `json:"id"`
|
||||
NotificationId string `json:"notification_id"`
|
||||
UserId string `json:"user_id"`
|
||||
EnvId string `json:"env_id"`
|
||||
}
|
||||
|
||||
func NewNotificationUser() connection.Row {
|
||||
n := NotificationUser{}
|
||||
return &n
|
||||
}
|
||||
|
||||
func (n *NotificationUser) InsertValues() []interface{} {
|
||||
v := n.UpdateValues()
|
||||
|
||||
return append([]interface{}{utils.Checksum(n.Id)}, v...)
|
||||
}
|
||||
|
||||
func (n *NotificationUser) UpdateValues() []interface{} {
|
||||
v := make([]interface{}, 0)
|
||||
|
||||
v = append(
|
||||
v,
|
||||
utils.Checksum(n.NotificationId),
|
||||
utils.Checksum(n.UserId),
|
||||
utils.Checksum(n.EnvId),
|
||||
)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (n *NotificationUser) GetId() string {
|
||||
return n.Id
|
||||
}
|
||||
|
||||
func (n *NotificationUser) SetId(id string) {
|
||||
n.Id = id
|
||||
}
|
||||
|
||||
func init() {
|
||||
name := "notification_user"
|
||||
ObjectInformation = configobject.ObjectInformation{
|
||||
ObjectType: name,
|
||||
RedisKey: "notification:user",
|
||||
Factory: NewNotificationUser,
|
||||
HasChecksum: false,
|
||||
BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields),
|
||||
BulkDeleteStmt: connection.NewBulkDeleteStmt(name),
|
||||
BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields),
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package notificationusergroup
|
||||
|
||||
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",
|
||||
"notification_id",
|
||||
"usergroup_id",
|
||||
"env_id",
|
||||
}
|
||||
)
|
||||
|
||||
type NotificationUsergroup struct {
|
||||
Id string `json:"id"`
|
||||
NotificationId string `json:"notification_id"`
|
||||
UsergroupId string `json:"usergroup_id"`
|
||||
EnvId string `json:"env_id"`
|
||||
}
|
||||
|
||||
func NewNotificationUsergroup() connection.Row {
|
||||
n := NotificationUsergroup{}
|
||||
return &n
|
||||
}
|
||||
|
||||
func (n *NotificationUsergroup) InsertValues() []interface{} {
|
||||
v := n.UpdateValues()
|
||||
|
||||
return append([]interface{}{utils.Checksum(n.Id)}, v...)
|
||||
}
|
||||
|
||||
func (n *NotificationUsergroup) UpdateValues() []interface{} {
|
||||
v := make([]interface{}, 0)
|
||||
|
||||
v = append(
|
||||
v,
|
||||
utils.Checksum(n.NotificationId),
|
||||
utils.Checksum(n.UsergroupId),
|
||||
utils.Checksum(n.EnvId),
|
||||
)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (n *NotificationUsergroup) GetId() string {
|
||||
return n.Id
|
||||
}
|
||||
|
||||
func (n *NotificationUsergroup) SetId(id string) {
|
||||
n.Id = id
|
||||
}
|
||||
|
||||
func init() {
|
||||
name := "notification_usergroup"
|
||||
ObjectInformation = configobject.ObjectInformation{
|
||||
ObjectType: name,
|
||||
RedisKey: "notification:usergroup",
|
||||
Factory: NewNotificationUsergroup,
|
||||
HasChecksum: false,
|
||||
BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields),
|
||||
BulkDeleteStmt: connection.NewBulkDeleteStmt(name),
|
||||
BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields),
|
||||
}
|
||||
}
|
||||
9
main.go
9
main.go
|
|
@ -15,6 +15,10 @@ import (
|
|||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/hostgroup/hostgroupmember"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/iconimage"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/notesurl"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/notification"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/notification/notificationcustomvar"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/notification/notificationuser"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/notification/notificationusergroup"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/service"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/service/servicecustomvar"
|
||||
"git.icinga.com/icingadb/icingadb-main/configobject/objecttypes/servicegroup"
|
||||
|
|
@ -117,6 +121,11 @@ func startConfigSyncOperators(super *supervisor.Supervisor, haInstance *ha.HA) {
|
|||
&usergroupcustomvar.ObjectInformation,
|
||||
&usergroupmember.ObjectInformation,
|
||||
|
||||
¬ification.ObjectInformation,
|
||||
¬ificationcustomvar.ObjectInformation,
|
||||
¬ificationuser.ObjectInformation,
|
||||
¬ificationusergroup.ObjectInformation,
|
||||
|
||||
&customvar.ObjectInformation,
|
||||
|
||||
&zone.ObjectInformation,
|
||||
|
|
|
|||
Loading…
Reference in a new issue