mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Merge pull request #96 from Icinga/feature/add-status-information-to-heartbeat
HA: Add missing Icinga 2 status information to heartbeat/icingadb_instance
This commit is contained in:
commit
6db60669de
3 changed files with 87 additions and 18 deletions
|
|
@ -312,6 +312,12 @@ CREATE TABLE icingadb_instance (
|
|||
|
||||
icinga2_version varchar(255) NOT NULL,
|
||||
icinga2_start_time bigint(20) unsigned NOT NULL,
|
||||
icinga2_notifications_enabled enum('y','n') NOT NULL,
|
||||
icinga2_active_service_checks_enabled enum('y','n') NOT NULL,
|
||||
icinga2_active_host_checks_enabled enum('y','n') NOT NULL,
|
||||
icinga2_event_handlers_enabled enum('y','n') NOT NULL,
|
||||
icinga2_flap_detection_enabled enum('y','n') NOT NULL,
|
||||
icinga2_performance_data_enabled enum('y','n') NOT NULL,
|
||||
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
|
||||
|
|
|
|||
59
ha/ha.go
59
ha/ha.go
|
|
@ -69,9 +69,22 @@ func (h *HA) updateOwnInstance(env *Environment) error {
|
|||
_, err := h.super.Dbw.SqlExec(
|
||||
mysqlObservers.updateIcingadbInstanceById,
|
||||
"UPDATE icingadb_instance SET endpoint_id = ?, heartbeat = ?,"+
|
||||
" icinga2_version = ?, icinga2_start_time = ? WHERE id = ?",
|
||||
env.Icinga2.EndpointId, h.lastHeartbeat, env.Icinga2.Version,
|
||||
int64(env.Icinga2.ProgramStart*1000), h.uid[:])
|
||||
" icinga2_version = ?, icinga2_start_time = ?, icinga2_notifications_enabled = ?,"+
|
||||
" icinga2_active_service_checks_enabled = ?, icinga2_active_host_checks_enabled = ?,"+
|
||||
" icinga2_event_handlers_enabled = ?, icinga2_flap_detection_enabled = ?,"+
|
||||
" icinga2_performance_data_enabled = ? WHERE id = ?",
|
||||
env.Icinga2.EndpointId,
|
||||
h.lastHeartbeat,
|
||||
env.Icinga2.Version,
|
||||
int64(env.Icinga2.ProgramStart*1000),
|
||||
utils.Bool[env.Icinga2.NotificationsEnabled],
|
||||
utils.Bool[env.Icinga2.ActiveServiceChecksEnabled],
|
||||
utils.Bool[env.Icinga2.ActiveHostChecksEnabled],
|
||||
utils.Bool[env.Icinga2.EventHandlersEnabled],
|
||||
utils.Bool[env.Icinga2.FlapDetectionEnabled],
|
||||
utils.Bool[env.Icinga2.PerformanceDataEnabled],
|
||||
h.uid[:],
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -79,9 +92,23 @@ func (h *HA) takeOverInstance(env *Environment) error {
|
|||
_, err := h.super.Dbw.SqlExec(
|
||||
mysqlObservers.updateIcingadbInstanceByEnvironmentId,
|
||||
"UPDATE icingadb_instance SET id = ?, endpoint_id = ?, heartbeat = ?,"+
|
||||
" icinga2_version = ?, icinga2_start_time = ? WHERE environment_id = ?",
|
||||
h.uid[:], env.Icinga2.EndpointId, h.lastHeartbeat, env.Icinga2.Version,
|
||||
int64(env.Icinga2.ProgramStart*1000), h.super.EnvId)
|
||||
" icinga2_version = ?, icinga2_start_time = ?, icinga2_notifications_enabled = ?,"+
|
||||
" icinga2_active_service_checks_enabled = ?, icinga2_active_host_checks_enabled = ?,"+
|
||||
" icinga2_event_handlers_enabled = ?, icinga2_flap_detection_enabled = ?,"+
|
||||
" icinga2_performance_data_enabled = ? WHERE environment_id = ?",
|
||||
h.uid[:],
|
||||
env.Icinga2.EndpointId,
|
||||
h.lastHeartbeat,
|
||||
env.Icinga2.Version,
|
||||
int64(env.Icinga2.ProgramStart*1000),
|
||||
utils.Bool[env.Icinga2.NotificationsEnabled],
|
||||
utils.Bool[env.Icinga2.ActiveServiceChecksEnabled],
|
||||
utils.Bool[env.Icinga2.ActiveHostChecksEnabled],
|
||||
utils.Bool[env.Icinga2.EventHandlersEnabled],
|
||||
utils.Bool[env.Icinga2.FlapDetectionEnabled],
|
||||
utils.Bool[env.Icinga2.PerformanceDataEnabled],
|
||||
h.super.EnvId,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -89,9 +116,23 @@ func (h *HA) insertInstance(env *Environment) error {
|
|||
_, err := h.super.Dbw.SqlExec(
|
||||
mysqlObservers.insertIntoIcingadbInstance,
|
||||
"INSERT INTO icingadb_instance(id, environment_id, endpoint_id, heartbeat, responsible,"+
|
||||
" icinga2_version, icinga2_start_time) VALUES (?, ?, ?, ?, 'y', ?, ?)",
|
||||
h.uid[:], h.super.EnvId, env.Icinga2.EndpointId,
|
||||
h.lastHeartbeat, env.Icinga2.Version, int64(env.Icinga2.ProgramStart*1000))
|
||||
" icinga2_version, icinga2_start_time, icinga2_notifications_enabled,"+
|
||||
" icinga2_active_service_checks_enabled, icinga2_active_host_checks_enabled,"+
|
||||
" icinga2_event_handlers_enabled, icinga2_flap_detection_enabled,"+
|
||||
" icinga2_performance_data_enabled) VALUES (?, ?, ?, ?, 'y', ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
h.uid[:],
|
||||
h.super.EnvId,
|
||||
env.Icinga2.EndpointId,
|
||||
h.lastHeartbeat,
|
||||
env.Icinga2.Version,
|
||||
int64(env.Icinga2.ProgramStart*1000),
|
||||
utils.Bool[env.Icinga2.NotificationsEnabled],
|
||||
utils.Bool[env.Icinga2.ActiveServiceChecksEnabled],
|
||||
utils.Bool[env.Icinga2.ActiveHostChecksEnabled],
|
||||
utils.Bool[env.Icinga2.EventHandlersEnabled],
|
||||
utils.Bool[env.Icinga2.FlapDetectionEnabled],
|
||||
utils.Bool[env.Icinga2.PerformanceDataEnabled],
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,15 @@ type Environment struct {
|
|||
}
|
||||
|
||||
type Icinga2Info struct {
|
||||
Version string
|
||||
ProgramStart float64
|
||||
EndpointId []byte
|
||||
Version string
|
||||
ProgramStart float64
|
||||
EndpointId []byte
|
||||
NotificationsEnabled bool
|
||||
ActiveServiceChecksEnabled bool
|
||||
ActiveHostChecksEnabled bool
|
||||
EventHandlersEnabled bool
|
||||
FlapDetectionEnabled bool
|
||||
PerformanceDataEnabled bool
|
||||
}
|
||||
|
||||
// Sha1bytes computes SHA1.
|
||||
|
|
@ -61,11 +67,17 @@ func IcingaHeartbeatListener(rdb *connection.RDBWrapper, chEnv chan *Environment
|
|||
Status struct {
|
||||
IcingaApplication struct {
|
||||
App struct {
|
||||
Environment string `json:"environment"`
|
||||
NodeName string `json:"node_name"`
|
||||
Version string `json:"version"`
|
||||
ProgramStart float64 `json:"program_start"`
|
||||
EndpointId string `json:"endpoint_id"`
|
||||
Environment string `json:"environment"`
|
||||
NodeName string `json:"node_name"`
|
||||
Version string `json:"version"`
|
||||
ProgramStart float64 `json:"program_start"`
|
||||
EndpointId string `json:"endpoint_id"`
|
||||
NotificationsEnabled bool `json:"enable_notifications"`
|
||||
ActiveServiceChecksEnabled bool `json:"enable_service_checks"`
|
||||
ActiveHostChecksEnabled bool `json:"enable_host_checks"`
|
||||
EventHandlersEnabled bool `json:"enable_event_handlers"`
|
||||
FlapDetectionEnabled bool `json:"enable_flapping"`
|
||||
PerformanceDataEnabled bool `json:"enable_perfdata"`
|
||||
} `json:"app"`
|
||||
} `json:"icingaapplication"`
|
||||
} `json:"status"`
|
||||
|
|
@ -82,7 +94,17 @@ func IcingaHeartbeatListener(rdb *connection.RDBWrapper, chEnv chan *Environment
|
|||
Name: app.Environment,
|
||||
ID: Sha1bytes([]byte(app.Environment)),
|
||||
NodeName: app.NodeName,
|
||||
Icinga2: Icinga2Info{app.Version, app.ProgramStart, nil},
|
||||
Icinga2: Icinga2Info{
|
||||
app.Version,
|
||||
app.ProgramStart,
|
||||
nil,
|
||||
app.NotificationsEnabled,
|
||||
app.ActiveServiceChecksEnabled,
|
||||
app.ActiveHostChecksEnabled,
|
||||
app.EventHandlersEnabled,
|
||||
app.FlapDetectionEnabled,
|
||||
app.PerformanceDataEnabled,
|
||||
},
|
||||
}
|
||||
|
||||
if app.EndpointId != "" {
|
||||
|
|
|
|||
Loading…
Reference in a new issue