You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
// Copyright 2018 Felix Kronlage <fkr@hazardous.org>
|
|
|
|
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
|
|
}
|