Skip to content

Commit

Permalink
Add Icinga states to pod
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed Apr 25, 2024
1 parent 230491b commit 4d3c703
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/schema/v1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Pod struct {
NominatedNodeName string
Ip string
Phase string
IcingaState string
CpuLimits int64
CpuRequests int64
MemoryLimits int64
Expand Down Expand Up @@ -135,6 +136,31 @@ func (p *Pod) Obtain(k8s kmetav1.Object) {
containerState.Valid = true
}

lastState, lastStateDetails, err := MarshalFirstNonNilStructFieldToJSON(containerStatuses[k8sContainer.Name].LastTerminationState)
if err != nil {
panic(err)
}
var lastContainerState sql.NullString
if lastState != "" {
lastContainerState.String = strcase.Snake(lastState)
lastContainerState.Valid = true
}

if containerState.String == "running" || (containerState.String == "terminated" && strings.Contains(stateDetails, "\"reason\":\"Completed\"")) {
p.IcingaState = "ok"
} else if containerState.String == "waiting" {
if strings.Contains(lastStateDetails, "\"reason\":\"Error\"") && containerStatuses[k8sContainer.Name].RestartCount >= 3 ||
strings.Contains(stateDetails, "\"reason\":\"ErrImageNeverPull\"") {
p.IcingaState = "critical"
} else {
p.IcingaState = "warning"
}
} else if containerState.String == "terminated" && containerStatuses[k8sContainer.Name].State.Terminated.ExitCode != 0 {
p.IcingaState = "critical"
} else {
p.IcingaState = "unknown"
}

container := Container{
ContainerMeta: ContainerMeta{
Id: types.Checksum(pod.Namespace + "/" + pod.Name + "/" + k8sContainer.Name),
Expand Down
1 change: 1 addition & 0 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ CREATE TABLE pod (
memory_limits bigint unsigned NOT NULL,
memory_requests bigint unsigned NOT NULL,
phase enum('pending', 'running', 'succeeded', 'failed') COLLATE utf8mb4_unicode_ci NOT NULL,
icinga_state enum('ok', 'warning', 'critical', 'unknown') COLLATE utf8mb4_unicode_ci NOT NULL,
reason varchar(255) NULL DEFAULT NULL,
message varchar(255) NULL DEFAULT NULL,
qos enum('guaranteed', 'burstable', 'best_effort') COLLATE utf8mb4_unicode_ci NOT NULL,
Expand Down

0 comments on commit 4d3c703

Please sign in to comment.