Skip to content

Commit

Permalink
Add Icinga states to daemon set
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed May 16, 2024
1 parent 230491b commit 19b557e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/schema/v1/daemon_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"strings"
)

const Ok = "ok"
const Warning = "warning"
const Critical = "critical"
const Unknown = "unknown"

type DaemonSet struct {
Meta
Id types.Binary
Expand All @@ -21,6 +26,7 @@ type DaemonSet struct {
UpdateNumberScheduled int32
NumberAvailable int32
NumberUnavailable int32
IcingaState string
Conditions []DaemonSetCondition `db:"-"`
Labels []Label `db:"-"`
DaemonSetLabels []DaemonSetLabel `db:"-"`
Expand Down Expand Up @@ -59,6 +65,7 @@ func (d *DaemonSet) Obtain(k8s kmetav1.Object) {
d.UpdateNumberScheduled = daemonSet.Status.UpdatedNumberScheduled
d.NumberAvailable = daemonSet.Status.NumberAvailable
d.NumberUnavailable = daemonSet.Status.NumberUnavailable
d.IcingaState = getDaemonSetMonitoringState(d)

for _, condition := range daemonSet.Status.Conditions {
d.Conditions = append(d.Conditions, DaemonSetCondition{
Expand All @@ -85,6 +92,21 @@ func (d *DaemonSet) Obtain(k8s kmetav1.Object) {
}
}

func getDaemonSetMonitoringState(d *DaemonSet) string {
if d.DesiredNumberScheduled < 1 {
return Unknown
}

switch {
case d.NumberAvailable < 1:
return Critical
case d.NumberUnavailable > 1:
return Warning
default:
return Ok
}
}

func (d *DaemonSet) Relations() []database.Relation {
fk := database.WithForeignKey("daemon_set_id")

Expand Down
1 change: 1 addition & 0 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ CREATE TABLE daemon_set (
update_number_scheduled int unsigned NOT NULL,
number_available int unsigned NOT NULL,
number_unavailable int unsigned NOT NULL,
icinga_state enum('ok', 'warning', 'critical', 'unknown') COLLATE utf8mb4_unicode_ci NOT NULL,
created bigint unsigned NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
Expand Down

0 comments on commit 19b557e

Please sign in to comment.