Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// IcingaDB | (c) 2019 Icinga GmbH | GPLv2+

package notificationrecipient

import (
"github.com/Icinga/icingadb/configobject"
"github.com/Icinga/icingadb/connection"
"github.com/Icinga/icingadb/utils"
"github.com/sirupsen/logrus"
)

var (
ObjectInformation configobject.ObjectInformation
Fields = []string{
"id",
"notification_id",
"user_id",
"usergroup_id",
"environment_id",
}
)

type NotificationRecipient struct {
Id string `json:"id"`
NotificationId string `json:"notification_id"`
UserId interface{} `json:"user_id"`
UserGroupId interface{} `json:"usergroup_id"`
EnvId string `json:"environment_id"`
}

func NewNotificationRecipient() connection.Row {
n := NotificationRecipient{}
return &n
}

func (n *NotificationRecipient) InsertValues() []interface{} {
v := n.UpdateValues()

return append([]interface{}{utils.EncodeChecksum(n.Id)}, v...)
}

func (n *NotificationRecipient) UpdateValues() []interface{} {
v := make([]interface{}, 0)

logrus.Info(n.UserId)
logrus.Info(n.UserGroupId)

v = append(
v,
utils.EncodeChecksum(n.NotificationId),
utils.DecodeHexIfNotNil(n.UserId),
utils.DecodeHexIfNotNil(n.UserGroupId),
utils.EncodeChecksum(n.EnvId),
)

return v
}

func (n *NotificationRecipient) GetId() string {
return n.Id
}

func (n *NotificationRecipient) SetId(id string) {
n.Id = id
}

func (n *NotificationRecipient) GetFinalRows() ([]connection.Row, error) {
return []connection.Row{n}, nil
}

func init() {
name := "notification_recipient"
ObjectInformation = configobject.ObjectInformation{
ObjectType: name,
RedisKey: "notification:recipient",
PrimaryMySqlField: "id",
Factory: NewNotificationRecipient,
HasChecksum: false,
BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields),
BulkDeleteStmt: connection.NewBulkDeleteStmt(name, "id"),
BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields),
NotificationListenerType: "notification",
}
}
10 changes: 10 additions & 0 deletions etc/schema/mysql/mysql.schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,16 @@ CREATE TABLE notification_usergroup (
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE notification_recipient (
id binary(20) NOT NULL COMMENT 'sha1(environment.name + notification_id + (user_id | usergroup_id))',
environment_id binary(20) NOT NULL COMMENT 'environment.id',
notification_id binary(20) NOT NULL COMMENT 'notification.id',
user_id binary(20) NULL COMMENT 'user.id',
usergroup_id binary(20) NULL COMMENT 'usergroup.id',

PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

CREATE TABLE notification_customvar (
id binary(20) NOT NULL COMMENT 'sha1(environment.name + notification_id + customvar_id)',
environment_id binary(20) NOT NULL COMMENT 'sha1(environment.name)',
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/Icinga/icingadb/configobject/objecttypes/notesurl"
"github.com/Icinga/icingadb/configobject/objecttypes/notification"
"github.com/Icinga/icingadb/configobject/objecttypes/notification/notificationcustomvar"
"github.com/Icinga/icingadb/configobject/objecttypes/notification/notificationrecipient"
"github.com/Icinga/icingadb/configobject/objecttypes/notification/notificationuser"
"github.com/Icinga/icingadb/configobject/objecttypes/notification/notificationusergroup"
"github.com/Icinga/icingadb/configobject/objecttypes/notificationcommand"
Expand Down Expand Up @@ -169,6 +170,7 @@ func startConfigSyncOperators(super *supervisor.Supervisor, haInstance *ha.HA) {
&notificationcustomvar.ObjectInformation,
&notificationuser.ObjectInformation,
&notificationusergroup.ObjectInformation,
&notificationrecipient.ObjectInformation,

&customvar.ObjectInformation,
&customvarflat.ObjectInformation,
Expand Down