// Copyright 2018 Felix Kronlage package main import ( "context" "fmt" "github.com/gridscale/gsclient-go/v2" ) type SnapshotsCountCommand struct { Critical int `short:"c" description:"Critical value" required:"yes" description:"how few snapshots must only exist to count as critical"` Warning int `short:"w" description:"Warning value" required:"yes" description:"how few snapshots must only exist to count as warning"` StorageUUID string `short:"u" long:"uuid" description:"uuid of storage to check" optional:"no"` } var snapshotsCountCommand SnapshotsCountCommand func (x *SnapshotsCountCommand) Execute(args []string) error { config(Checker.ConfigFile) ctx := context.Background() snapshots, error := Config.Client.GetStorageSnapshotList(ctx, x.StorageUUID) if error != nil { Unknown("Error retrieving snapshots") } count(snapshots, x.Warning, x.Critical) return nil } func init() { } func count(snapshots []gsclient.StorageSnapshot, warning int, critical int) error { snapshotsCount := len(snapshots) if snapshotsCount < critical { Critical(fmt.Sprintf("not enough snapshots - found %d snapshots", snapshotsCount)) } if snapshotsCount < warning { Warning(fmt.Sprintf("not enough snapshots - found %d snapshots", snapshotsCount)) } Ok(fmt.Sprintf("%d snapshots exist", snapshotsCount)) // never reached return nil }