/
checkcommand.go
94 lines (79 loc) · 2.13 KB
/
checkcommand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// IcingaDB | (c) 2019 Icinga GmbH | GPLv2+
package checkcommand
import (
"github.com/Icinga/icingadb/configobject"
"github.com/Icinga/icingadb/connection"
"github.com/Icinga/icingadb/utils"
)
var (
ObjectInformation configobject.ObjectInformation
Fields = []string{
"id",
"environment_id",
"name_checksum",
"properties_checksum",
"name",
"name_ci",
"zone_id",
"command",
"timeout",
}
)
type CheckCommand struct {
Id string `json:"id"`
EnvId string `json:"environment_id"`
NameChecksum string `json:"name_checksum"`
PropertiesChecksum string `json:"checksum"`
Name string `json:"name"`
NameCi *string `json:"name_ci"`
ZoneId string `json:"zone_id"`
Command string `json:"command"`
Timeout float64 `json:"timeout"`
}
func NewCheckCommand() connection.Row {
c := CheckCommand{}
c.NameCi = &c.Name
return &c
}
func (c *CheckCommand) InsertValues() []interface{} {
v := c.UpdateValues()
return append([]interface{}{utils.EncodeChecksum(c.Id)}, v...)
}
func (c *CheckCommand) UpdateValues() []interface{} {
v := make([]interface{}, 0)
v = append(
v,
utils.EncodeChecksum(c.EnvId),
utils.EncodeChecksum(c.NameChecksum),
utils.EncodeChecksum(c.PropertiesChecksum),
c.Name,
c.NameCi,
utils.EncodeChecksum(c.ZoneId),
c.Command,
c.Timeout,
)
return v
}
func (c *CheckCommand) GetId() string {
return c.Id
}
func (c *CheckCommand) SetId(id string) {
c.Id = id
}
func (c *CheckCommand) GetFinalRows() ([]connection.Row, error) {
return []connection.Row{c}, nil
}
func init() {
name := "checkcommand"
ObjectInformation = configobject.ObjectInformation{
ObjectType: name,
RedisKey: name,
PrimaryMySqlField: "id",
Factory: NewCheckCommand,
HasChecksum: true,
BulkInsertStmt: connection.NewBulkInsertStmt(name, Fields),
BulkDeleteStmt: connection.NewBulkDeleteStmt(name, "id"),
BulkUpdateStmt: connection.NewBulkUpdateStmt(name, Fields),
NotificationListenerType: "checkcommand",
}
}