mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Improve Downtime & DowntimeHistory
This commit is contained in:
parent
a983238266
commit
9b7b4d6ca8
5 changed files with 29 additions and 31 deletions
|
|
@ -177,9 +177,9 @@ func stateHistoryWorker(super *supervisor.Supervisor) {
|
|||
|
||||
func downtimeHistoryWorker(super *supervisor.Supervisor) {
|
||||
statements := []string{
|
||||
`REPLACE INTO downtime_history (downtime_id, environment_id, endpoint_id, object_type, host_id, service_id, triggered_by_id, entry_time,` +
|
||||
`author, comment, is_flexible, flexible_duration, scheduled_start_time, scheduled_end_time, was_started, actual_start_time, actual_end_time, was_cancelled, is_in_effect, trigger_time, deletion_time)` +
|
||||
`VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
|
||||
`REPLACE INTO downtime_history (downtime_id, environment_id, endpoint_id, triggered_by_id, object_type, host_id, service_id, entry_time,` +
|
||||
`author, comment, is_flexible, flexible_duration, scheduled_start_time, scheduled_end_time, start_time, end_time, has_been_cancelled, trigger_time, cancel_time)` +
|
||||
`VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
|
||||
`REPLACE INTO history (id, environment_id, endpoint_id, object_type, host_id, service_id, notification_history_id,` +
|
||||
`state_history_id, downtime_history_id, comment_history_id, flapping_history_id, event_type, event_time)` +
|
||||
`VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`,
|
||||
|
|
@ -196,10 +196,10 @@ func downtimeHistoryWorker(super *supervisor.Supervisor) {
|
|||
utils.EncodeChecksum(values["downtime_id"].(string)),
|
||||
super.EnvId,
|
||||
utils.DecodeHexIfNotNil(values["endpoint_id"]),
|
||||
triggeredById,
|
||||
values["object_type"].(string),
|
||||
utils.DecodeHexIfNotNil(values["host_id"]),
|
||||
utils.DecodeHexIfNotNil(values["service_id"]),
|
||||
triggeredById,
|
||||
values["entry_time"],
|
||||
values["author"],
|
||||
values["comment"],
|
||||
|
|
@ -207,13 +207,11 @@ func downtimeHistoryWorker(super *supervisor.Supervisor) {
|
|||
values["flexible_duration"],
|
||||
values["scheduled_start_time"],
|
||||
values["scheduled_end_time"],
|
||||
utils.RedisIntToDBBoolean(values["was_started"]),
|
||||
values["actual_start_time"],
|
||||
values["actual_end_time"],
|
||||
utils.RedisIntToDBBoolean(values["was_cancelled"]),
|
||||
utils.RedisIntToDBBoolean(values["is_in_effect"]),
|
||||
values["start_time"],
|
||||
values["end_time"],
|
||||
utils.RedisIntToDBBoolean(values["has_been_cancelled"]),
|
||||
values["trigger_time"],
|
||||
values["deletion_time"],
|
||||
values["cancel_time"],
|
||||
}
|
||||
|
||||
return data
|
||||
|
|
@ -224,12 +222,10 @@ func downtimeHistoryWorker(super *supervisor.Supervisor) {
|
|||
|
||||
var eventTime string
|
||||
switch values["event_type"] {
|
||||
case "downtime_schedule":
|
||||
eventTime = values["entry_time"].(string)
|
||||
case "downtime_start":
|
||||
eventTime = values["actual_start_time"].(string)
|
||||
eventTime = values["start_time"].(string)
|
||||
case "downtime_end":
|
||||
eventTime = values["actual_end_time"].(string)
|
||||
eventTime = values["end_time"].(string)
|
||||
}
|
||||
|
||||
data := []interface{}{
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ func InsertNullRows(super *supervisor.Supervisor) {
|
|||
// downtime_history
|
||||
execFunc(
|
||||
"downtime_history",
|
||||
"REPLACE INTO downtime_history(downtime_id, environment_id, object_type, host_id, service_id, triggered_by_id, entry_time, author, comment, is_flexible, flexible_duration, scheduled_start_time, scheduled_end_time, was_started, actual_start_time, actual_end_time, was_cancelled, is_in_effect, trigger_time, deletion_time) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||
emptyID, super.EnvId, "host", nil, nil, emptyID, 0, "", "", "y", 0, 0, 0, "y", 0, 0, "y", "y", 0, 0,
|
||||
"REPLACE INTO downtime_history(downtime_id, environment_id, triggered_by_id, object_type, host_id, service_id, entry_time, author, comment, is_flexible, flexible_duration, scheduled_start_time, scheduled_end_time, start_time, end_time, has_been_cancelled, trigger_time, cancel_time) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||
emptyID, super.EnvId, emptyID, "host", nil, nil, 0, "", "", "y", 0, 0, 0, 0, 0, "y", 0, 0,
|
||||
)
|
||||
|
||||
// flapping_history
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ var (
|
|||
Fields = []string{
|
||||
"id",
|
||||
"environment_id",
|
||||
"triggered_by_id",
|
||||
"object_type",
|
||||
"host_id",
|
||||
"service_id",
|
||||
|
|
@ -25,8 +26,8 @@ var (
|
|||
"flexible_duration",
|
||||
"is_flexible",
|
||||
"is_in_effect",
|
||||
"actual_start_time",
|
||||
"actual_end_time",
|
||||
"start_time",
|
||||
"end_time",
|
||||
"zone_id",
|
||||
}
|
||||
)
|
||||
|
|
@ -34,6 +35,7 @@ var (
|
|||
type Downtime struct {
|
||||
Id string `json:"id"`
|
||||
EnvId string `json:"environment_id"`
|
||||
TriggeredById string `json:"triggered_by_id"`
|
||||
ObjectType string `json:"object_type"`
|
||||
HostId string `json:"host_id"`
|
||||
ServiceId string `json:"service_id"`
|
||||
|
|
@ -48,8 +50,8 @@ type Downtime struct {
|
|||
FlexibleDuration float64 `json:"flexible_duration"`
|
||||
IsFlexible bool `json:"is_flexible"`
|
||||
IsInEffect bool `json:"is_in_effect"`
|
||||
ActualStartTime float64 `json:"actual_start_time"`
|
||||
ActualEndTime float64 `json:"actual_end_time"`
|
||||
StartTime float64 `json:"start_time"`
|
||||
EndTime float64 `json:"end_time"`
|
||||
ZoneId string `json:"zone_id"`
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +73,7 @@ func (d *Downtime) UpdateValues() []interface{} {
|
|||
v = append(
|
||||
v,
|
||||
utils.EncodeChecksum(d.EnvId),
|
||||
utils.EncodeChecksum(d.TriggeredById),
|
||||
d.ObjectType,
|
||||
utils.EncodeChecksum(d.HostId),
|
||||
utils.EncodeChecksum(d.ServiceId),
|
||||
|
|
@ -85,8 +88,8 @@ func (d *Downtime) UpdateValues() []interface{} {
|
|||
d.FlexibleDuration,
|
||||
utils.Bool[d.IsFlexible],
|
||||
utils.Bool[d.IsInEffect],
|
||||
d.ActualStartTime,
|
||||
d.ActualEndTime,
|
||||
d.StartTime,
|
||||
d.EndTime,
|
||||
utils.EncodeChecksum(d.ZoneId),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ CREATE TABLE downtime (
|
|||
id binary(20) NOT NULL COMMENT 'sha1(environment.name + name)',
|
||||
environment_id binary(20) NOT NULL COMMENT 'environment.id',
|
||||
|
||||
triggered_by_id binary(20) NULL DEFAULT NULL COMMENT 'downtime.id',
|
||||
object_type enum('host', 'service') NOT NULL,
|
||||
host_id binary(20) DEFAULT NULL COMMENT 'host.id',
|
||||
service_id binary(20) DEFAULT NULL COMMENT 'service.id',
|
||||
|
|
@ -22,8 +23,8 @@ CREATE TABLE downtime (
|
|||
is_flexible enum('y', 'n') NOT NULL,
|
||||
|
||||
is_in_effect enum('y', 'n') NOT NULL,
|
||||
actual_start_time bigint(20) unsigned DEFAULT NULL COMMENT 'Time when the host went into a problem state during the downtimes timeframe',
|
||||
actual_end_time bigint(20) unsigned DEFAULT NULL COMMENT 'Problem state assumed: scheduled_end_time if fixed, start_time + flexible_duration otherwise',
|
||||
start_time bigint(20) unsigned DEFAULT NULL COMMENT 'Time when the host went into a problem state during the downtimes timeframe',
|
||||
end_time bigint(20) unsigned DEFAULT NULL COMMENT 'Problem state assumed: scheduled_end_time if fixed, start_time + flexible_duration otherwise',
|
||||
|
||||
zone_id binary(20) DEFAULT NULL COMMENT 'zone.id',
|
||||
|
||||
|
|
|
|||
|
|
@ -49,10 +49,10 @@ CREATE TABLE downtime_history (
|
|||
downtime_id binary(20) NOT NULL COMMENT 'downtime.id',
|
||||
environment_id binary(20) NOT NULL COMMENT 'environment.id',
|
||||
endpoint_id binary(20) NULL DEFAULT NULL COMMENT 'endpoint.id',
|
||||
triggered_by_id binary(20) NULL DEFAULT NULL COMMENT 'downtime.id',
|
||||
object_type enum('host', 'service') NOT NULL,
|
||||
host_id binary(20) NULL DEFAULT NULL COMMENT 'host.id',
|
||||
service_id binary(20) NULL DEFAULT NULL COMMENT 'service.id',
|
||||
triggered_by_id binary(20) NULL DEFAULT NULL COMMENT 'downtime.id',
|
||||
|
||||
entry_time bigint(20) unsigned NOT NULL,
|
||||
author varchar(255) NOT NULL COLLATE utf8mb4_unicode_ci,
|
||||
|
|
@ -61,13 +61,11 @@ CREATE TABLE downtime_history (
|
|||
flexible_duration bigint(20) unsigned NOT NULL,
|
||||
scheduled_start_time bigint(20) unsigned NOT NULL,
|
||||
scheduled_end_time bigint(20) unsigned NOT NULL,
|
||||
was_started enum('y', 'n') NOT NULL,
|
||||
actual_start_time bigint(20) unsigned DEFAULT NULL COMMENT 'Time when the host went into a problem state during the downtimes timeframe',
|
||||
actual_end_time bigint(20) unsigned DEFAULT NULL COMMENT 'Problem state assumed: scheduled_end_time if fixed, start_time + duration otherwise',
|
||||
was_cancelled enum('y', 'n') NOT NULL,
|
||||
is_in_effect enum('y', 'n') NOT NULL,
|
||||
start_time bigint(20) unsigned DEFAULT NULL COMMENT 'Time when the host went into a problem state during the downtimes timeframe',
|
||||
end_time bigint(20) unsigned DEFAULT NULL COMMENT 'Problem state assumed: scheduled_end_time if fixed, start_time + duration otherwise',
|
||||
has_been_cancelled enum('y', 'n') NOT NULL,
|
||||
trigger_time bigint(20) unsigned NOT NULL,
|
||||
deletion_time bigint(20) unsigned NULL DEFAULT NULL,
|
||||
cancel_time bigint(20) unsigned NULL DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY (downtime_id)
|
||||
) ENGINE=InnoDb ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_bin;
|
||||
|
|
|
|||
Loading…
Reference in a new issue