first real working version
parent
3cada8ac1f
commit
9d978adbc9
@ -0,0 +1,23 @@
|
||||
Copyright 2018 - Felix Kronlage <fkr@hazardous.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
@ -1,7 +1,39 @@
|
||||
#
|
||||
# gridscale-check
|
||||
|
||||
gridscale-check snapshots count -w 2 -c 1
|
||||
A variety of commands to check various aspects of your IaaS-assetts at [gridscale](https://gridscale.io).
|
||||
This check makes use of [libretto](https://github.com/apcera/libretto). However, since the
|
||||
gridscale-support has not been merged yet, it imports libretto from here:
|
||||
|
||||
gridscale-check snapshots age -w 1 -c 2
|
||||
[https://g.hazardous.org/fkr/libretto](https://g.hazardous.org/fkr/libretto)
|
||||
|
||||
## commands
|
||||
|
||||
### snapshots
|
||||
|
||||
```
|
||||
$ gridscale-check snapshots count -w 2 -c 1 -u <uuid-of-storage>
|
||||
```
|
||||
|
||||
```
|
||||
$ gridscale-check snapshots age -w 1 -c 2 -u <uuid-of-storage>
|
||||
```
|
||||
|
||||
### servers
|
||||
|
||||
```
|
||||
$ gridscale-check servers state -s active -u <uuid-of-server>
|
||||
```
|
||||
|
||||
### helper commands
|
||||
|
||||
There are some helper commands, such as listing servers and storages:
|
||||
|
||||
```
|
||||
$ gridscale-check servers list
|
||||
```
|
||||
|
||||
```
|
||||
$ gridscale-check storages list
|
||||
```
|
||||
|
||||
|
||||
|
@ -1,51 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/apcera/libretto/virtualmachine/gridscale"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type CountCommand struct {
|
||||
Critical int `short:"c" description:"Critical value" optional:"no"`
|
||||
Warning int `short:"w" description:"Warning value" optional:"no"`
|
||||
StorageUUID string `short:"u" long:"uuid" description:"uuid of storage to check" optional:"no"`
|
||||
}
|
||||
|
||||
var countCommand CountCommand
|
||||
|
||||
func (x *CountCommand) Execute(args []string) error {
|
||||
storage, err := gridscale.GetStorageByUUID(Config.UserId, Config.Token, x.StorageUUID)
|
||||
|
||||
if err != nil {
|
||||
Unknown(fmt.Sprintf("%s: %s", "Error retrieving storage", err))
|
||||
}
|
||||
|
||||
snapshots, error := storage.GetSnapshots(Config.UserId, Config.Token)
|
||||
|
||||
if error != nil {
|
||||
Unknown("Error retrieving snapshots")
|
||||
}
|
||||
|
||||
count(snapshots, countCommand.Warning, countCommand.Critical)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func count(snapshots map[string]*gridscale.Snapshot, warning int, critical int) error {
|
||||
|
||||
if len(snapshots) < critical {
|
||||
Critical("")
|
||||
}
|
||||
|
||||
if len(snapshots) < warning {
|
||||
Warning("");
|
||||
}
|
||||
|
||||
Ok(fmt.Sprintf("%d snapshots exist", len(snapshots)))
|
||||
|
||||
// never reached
|
||||
return nil
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// Copyright 2018 Felix Kronlage <fkr@hazardous.org>
|
||||
|
||||
package main
|
||||
|
||||
type ServersCommand struct {
|
||||
List ListServersCommand `command:"list"`
|
||||
Status ServersStatusCommand `command:"status"`
|
||||
}
|
||||
|
||||
var serversCommand StoragesCommand
|
||||
|
||||
func (x *ServersCommand) Execute(args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
// Copyright 2018 Felix Kronlage <fkr@hazardous.org>
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/apcera/libretto/virtualmachine/gridscale"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ListServersCommand struct {
|
||||
}
|
||||
|
||||
var listServersCommand ListServersCommand
|
||||
|
||||
func (x *ListServersCommand) Execute(args []string) error {
|
||||
|
||||
serversResponse, error := gridscale.GetServers(Config.UserId, Config.Token)
|
||||
|
||||
if error != nil {
|
||||
Unknown(fmt.Sprintf("Error while retrieving storages: %s", error))
|
||||
}
|
||||
|
||||
for key, server := range serversResponse.Servers {
|
||||
fmt.Printf("%s: %v\n\n", key, server)
|
||||
|
||||
}
|
||||
|
||||
Ok((""))
|
||||
|
||||
// never reached
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
// Copyright 2018 Felix Kronlage <fkr@hazardous.org>
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/apcera/libretto/virtualmachine/gridscale"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ServersStatusCommand struct {
|
||||
Status string `short:"s" long:"status" description:"value of status to compare against" choice:"active" choice:"deleted" required:"yes"`
|
||||
ServerUUID string `short:"u" long:"uuid" description:"uuid of server to check" required:"yes"`
|
||||
}
|
||||
|
||||
var serversStatusCommand ServersStatusCommand
|
||||
|
||||
func (x *ServersStatusCommand) Execute(args []string) error {
|
||||
|
||||
server, err := gridscale.GetServer(Config.UserId, Config.Token, x.ServerUUID)
|
||||
|
||||
if err != nil {
|
||||
Unknown(fmt.Sprintf("%s: %s", "Error retrieving server", err))
|
||||
}
|
||||
|
||||
if server.Status != x.Status {
|
||||
Critical(fmt.Sprintf("Server state critical - State required: '%s' - State found: '%s'", x.Status, server.Status))
|
||||
}
|
||||
|
||||
|
||||
Ok(fmt.Sprintf("State required: '%s' - State found: '%s'", x.Status, server.Status))
|
||||
|
||||
// never reached
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
@ -1,18 +1,15 @@
|
||||
package main
|
||||
// Copyright 2018 Felix Kronlage <fkr@hazardous.org>
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
package main
|
||||
|
||||
type SnapshotsCommand struct {
|
||||
Age AgeCommand `command:"age"`
|
||||
Count CountCommand `command:"count"`
|
||||
Age SnapshotsAgeCommand `command:"age" description:"commands relating to the age of snapshots"`
|
||||
Count SnapshotsCountCommand `command:"count" description:"commands relating to the amount of snapshots"`
|
||||
}
|
||||
|
||||
var snapshotsCommand SnapshotsCommand
|
||||
|
||||
func (x *SnapshotsCommand) Execute(args []string) error {
|
||||
fmt.Println("snapshots")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,55 @@
|
||||
// Copyright 2018 Felix Kronlage <fkr@hazardous.org>
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/apcera/libretto/virtualmachine/gridscale"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
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 {
|
||||
storage, err := gridscale.GetStorageByUUID(Config.UserId, Config.Token, x.StorageUUID)
|
||||
|
||||
if err != nil {
|
||||
Unknown(fmt.Sprintf("%s: %s", "Error retrieving storage", err))
|
||||
}
|
||||
|
||||
snapshots, error := storage.GetSnapshots(Config.UserId, Config.Token)
|
||||
|
||||
if error != nil {
|
||||
Unknown("Error retrieving snapshots")
|
||||
}
|
||||
|
||||
count(snapshots, x.Warning, x.Critical)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
}
|
||||
|
||||
func count(snapshots map[string]*gridscale.Snapshot, warning int, critical int) error {
|
||||
|
||||
snapshotCount := len(snapshots)
|
||||
|
||||
if snapshotCount < critical {
|
||||
Critical(fmt.Sprintf("not enough snapshots - found %d snapshots", snapshotCount))
|
||||
}
|
||||
|
||||
if snapshotCount < warning {
|
||||
Warning(fmt.Sprintf("not enough snapshots - found %d snapshots", snapshotCount))
|
||||
}
|
||||
|
||||
Ok(fmt.Sprintf("%d snapshots exist", len(snapshots)))
|
||||
|
||||
// never reached
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue