diff --git a/README.md b/README.md index 4b9da5d..e78c744 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,11 @@ Global Flags: ``` $ check_cloud_aws ec2 instances -CRITICAL - 4 Instances found - 2 running - 2 stopped - -[CRITICAL] i-0f38c870feae9c593 "(none)" stopped (no status) -[OK] i-06378c1b63a42384f "IcingaMaster" running instance=ok system=ok -[CRITICAL] i-0d5c0ad646be4610e "IcingaAgent" stopped (no status) -[OK] i-0a1b3143ae11565fc "IcingaSatellit" running instance=ok system=ok +CRITICAL - 4 Instances: 2 running - 2 stopped + \_[CRITICAL] i-0f38c870feae9c593 "(none)" stopped (no status) + \_[OK] i-06378c1b63a42384f "IcingaMaster" running instance=ok system=ok + \_[CRITICAL] i-0d5c0ad646be4610e "IcingaAgent" stopped (no status) + \_[OK] i-0a1b3143ae11565fc "IcingaSatellit" running instance=ok system=ok ``` #### ec2 instance @@ -86,10 +85,9 @@ Global Flags: ``` $ check_cloud_aws ec2 instance --name IcingaMaster OK - "IcingaMaster" running instance=ok system=ok - -ID: i-06378c1b63a42384f -Type: t2.micro -AutoScaling: (none) + \_ID: i-06378c1b63a42384f + \_Type: t2.micro + \_AutoScaling: (none) ``` ### S3 @@ -119,10 +117,10 @@ Global Flags: ```` ``` -$ check_cloud_aws s3 bucket -w 100mb -c 200mb -OK - Found 2 buckets - critical 0 - warning 0 -[OK] my-aws-test-bucket1: 50MiB -[OK] my-aws-test-bucket2: 60MiB | my-aws-test-bucket1=50MB;100;200 my-aws-test-bucket2=60MB;100;200 +$ check_cloud_aws s3 bucket -C ~/.aws/credentials -w 100mb -c 200mb +OK - 2 Buckets: 0 Critical - 0 Warning - 2 Ok + \_[OK] my-aws-test-bucket1 - value: 50MiB + \_[OK] my-aws-test-bucket2 - value: 20MiB | my-aws-test-bucket1=50MB;100;200 my-aws-test-bucket2=60MB;100;200 ``` ### s3 object @@ -150,9 +148,14 @@ Global Flags: ```` ```` -$ check_cloud_aws s3 object --perfdata --prefix 'test' -b 'my-aws-testbucket1' -OK - Found 3 objects - critical 0 - warning 0 | test-file2.jpg=20MB;800;1024 test-file3.gif=10MB;800;1024 test-file5.rtf=10MB;800;1024 - +$ check_cloud_aws s3 object -C ~/.aws/credentials --perfdata --prefix 'test' +OK - 2 Objects: 0 Critical - 0 Warning - 3 Ok + \_[y-aws-testbucket1]: + \_[OK] test-file4.txt: 20MiB + \_[y-aws-testbucket2]: + \_[OK] test-file3.gif: 10MiB + \_[OK] test-file5.rtf: 20MiB + | test-file4.txt=20MB;800;1024 test-file3.gif=10MB;800;1024 test-file5.gif=20MB;800;1024 ```` ### Cloudfront @@ -176,12 +179,10 @@ Global Flags: ```` ```` -$ check_cloud_aws cloudfront -CRITICAL - Found 2 Distributions - critical 1 - warning 1 - -[WARNING] E32127W2BLH4SR status=InProgress enabled=true -[CRITICAL] E16D3ZI1743SVJ status=Deployed enabled=false - | E32127W2BLH4SR=InProgress E16D3ZI1743SVJ=Deployed +$ check_cloud_aws cloudfront -C ~/.aws/credentials +WARNING - 1 Distributions: 0 Disabled - 1 InProgress - 0 Enabled + \_[WARNING] E2BD5GDFJZXKWC status=InProgress enabled=true + | E2BD5GDFJZXKWC=inprogress ```` ## Authentication diff --git a/cmd/cloudfront.go b/cmd/cloudfront.go index 4f253c8..2602e9e 100644 --- a/cmd/cloudfront.go +++ b/cmd/cloudfront.go @@ -24,6 +24,7 @@ var cloudfrontCmd = &cobra.Command{ summary string totalCrit int totalWarn int + totalOk int rc int states []int distributions []*c.GetDistributionOutput @@ -57,48 +58,38 @@ var cloudfrontCmd = &cobra.Command{ } } - summary += fmt.Sprintf("Found %d Distributions - ", len(distributions)) + summary += fmt.Sprintf("%d Distributions: ", len(distributions)) for _, distribution := range distributions { + var val string + if *distribution.Distribution.DistributionConfig.Enabled == false { + val = "disabled" rc = 2 totalCrit++ } else if *distribution.Distribution.Status == "InProgress" { + val = "inprogress" rc = 1 totalWarn++ } else { + val = "enabled" rc = 0 + totalOk++ } states = append(states, rc) - if rc != 0 { - output += client.GetOutput(rc, distribution) - } + output += client.GetOutput(rc, distribution) p := perfdata.Perfdata{ Label: *distribution.Distribution.Id, - Value: *distribution.Distribution.Status, + Value: val, } perf.Add(&p) - - if len(distributions) > 1 { - output += "\n" - } } - if result.WorstState(states...) == 0 { - output = fmt.Sprintf("") - } - - summary += fmt.Sprintf("critical %d - warning %d\n", totalCrit, totalWarn) - - if len(distributions) > 1 { - if result.WorstState(states...) != 0 { - summary += "\n" - } - } + summary += fmt.Sprintf("%d Disabled - %d InProgress - %d Enabled\n", totalCrit, totalWarn, totalOk) check.ExitRaw(result.WorstState(states...), summary+output, "|", perf.String()) }, diff --git a/cmd/ec2_instance.go b/cmd/ec2_instance.go index 6e27af9..8082f08 100644 --- a/cmd/ec2_instance.go +++ b/cmd/ec2_instance.go @@ -40,7 +40,7 @@ var ec2InstanceCmd = &cobra.Command{ } output := instance.GetOutput() - output += "\n\n" + instance.GetLongOutput() + output += "\n" + instance.GetLongOutput() check.Exit(instance.GetStatus(), output) }, diff --git a/cmd/ec2_instances.go b/cmd/ec2_instances.go index 65a8126..fdf5e61 100644 --- a/cmd/ec2_instances.go +++ b/cmd/ec2_instances.go @@ -43,13 +43,18 @@ var ec2InstancesCmd = &cobra.Command{ states[*instance.Instance.State.Name]++ } - summary := fmt.Sprintf("%d Instances found", len(instances.Instances)) + summary := fmt.Sprintf("%d Instances:", len(instances.Instances)) + ctr := 0 for state, count := range states { - summary += fmt.Sprintf(" - %d %s", count, state) + summary += fmt.Sprintf(" %d %s ", count, state) + ctr += count + if ctr != len(instances.Instances) { + summary += fmt.Sprintf("-") + } } - check.Exit(instances.GetStatus(), summary+"\n\n"+instances.GetOutput()) + check.Exit(instances.GetStatus(), summary+"\n"+instances.GetOutput()) }, } diff --git a/cmd/s3_buckets.go b/cmd/s3_buckets.go index 4417d41..9f0222d 100644 --- a/cmd/s3_buckets.go +++ b/cmd/s3_buckets.go @@ -28,6 +28,7 @@ var s3BucketCmd = &cobra.Command{ states []int totalCrit int totalWarn int + totalOk int rc int perf perfdata.PerfdataList ) @@ -86,6 +87,7 @@ var s3BucketCmd = &cobra.Command{ totalWarn++ } else { rc = 0 + totalOk++ } states = append(states, rc) @@ -107,7 +109,7 @@ var s3BucketCmd = &cobra.Command{ perf.Add(&p) } - summary += fmt.Sprintf("Found %d buckets - critical %d - warning %d\n", len(buckets.Buckets), totalCrit, totalWarn) + summary += fmt.Sprintf("%d Buckets: %d Critical - %d Warning - %d Ok\n", len(buckets.Buckets), totalCrit, totalWarn, totalOk) check.ExitRaw(result.WorstState(states...), summary+output, "|", perf.String()) }, diff --git a/cmd/s3_objects.go b/cmd/s3_objects.go index 5cf1310..c113280 100644 --- a/cmd/s3_objects.go +++ b/cmd/s3_objects.go @@ -30,6 +30,7 @@ var s3ObjectCmd = &cobra.Command{ states []int totalCrit int totalWarn int + totalOk int totalObjects int64 rc int perf perfdata.PerfdataList @@ -79,7 +80,7 @@ var s3ObjectCmd = &cobra.Command{ check.ExitError(err) } - output += fmt.Sprintf("[%s]:\n", *bucket.Name) + output += fmt.Sprintf(" \\_[%s]:\n", *bucket.Name) for _, content := range objectsOutput.V2Output.Contents { if crit.DoesViolate(float64(*content.Size)) { @@ -90,13 +91,12 @@ var s3ObjectCmd = &cobra.Command{ totalWarn++ } else { rc = 0 + totalOk++ } states = append(states, rc) - if rc != 0 { - output += objectsOutput.GetObjectOutput(*content.Size, rc, *content.Key) - } + output += objectsOutput.GetObjectOutput(*content.Size, rc, *content.Key) p := perfdata.Perfdata{ Label: *content.Key, @@ -112,17 +112,7 @@ var s3ObjectCmd = &cobra.Command{ } } - if result.WorstState(states...) == 0 { - output = fmt.Sprintf("") - } - - summary += fmt.Sprintf("Found %d objects - critical %d - warning %d", totalObjects, totalCrit, totalWarn) - - if len(buckets.Buckets) > 1 { - if result.WorstState(states...) != 0 { - summary += "\n" - } - } + summary += fmt.Sprintf("%d Objects: %d Critical - %d Warning - %d Ok\n", totalObjects, totalCrit, totalWarn, totalOk) if ShowPerfdata { check.ExitRaw(result.WorstState(states...), summary+output, "|", perf.String()) diff --git a/internal/cloudfront/cloudfront.go b/internal/cloudfront/cloudfront.go index 4080237..9514c7c 100644 --- a/internal/cloudfront/cloudfront.go +++ b/internal/cloudfront/cloudfront.go @@ -11,7 +11,7 @@ type GetDistributionOutput struct { } func (c *CloudfrontClient) GetOutput(rc int, distribution *cloudfront.GetDistributionOutput) (output string) { - output = fmt.Sprintf("[%s] %s status=%s enabled=%t", + output = fmt.Sprintf(" \\_[%s] %s status=%s enabled=%t\n", check.StatusText(rc), *distribution.Distribution.Id, *distribution.Distribution.Status, diff --git a/internal/ec2/instance.go b/internal/ec2/instance.go index 496268d..3cafc63 100644 --- a/internal/ec2/instance.go +++ b/internal/ec2/instance.go @@ -52,21 +52,21 @@ func (i *Instance) GetLongOutput() (out string) { } } - out += "ID: " + *i.Instance.InstanceId + "\n" - out += "Type: " + *i.Instance.InstanceType + "\n" - out += "AutoScaling: " + autoscaling + "\n" + out += " \\_ID: " + *i.Instance.InstanceId + "\n" + out += " \\_Type: " + *i.Instance.InstanceType + "\n" + out += " \\_AutoScaling: " + autoscaling + "\n" return } -// * instance-state-name - The state of the instance (pending | running | -// shutting-down | terminated | stopping | stopped). +// * instance-state-name - The state of the instance (pending | running | +// shutting-down | terminated | stopping | stopped). // -// * instance-status.status - The status of the instance (ok | impaired | -// initializing | insufficient-data | not-applicable). +// * instance-status.status - The status of the instance (ok | impaired | +// initializing | insufficient-data | not-applicable). // -// * system-status.status - The system status of the instance (ok | impaired -// | initializing | insufficient-data | not-applicable). +// * system-status.status - The system status of the instance (ok | impaired +// | initializing | insufficient-data | not-applicable). func (i *Instance) GetStatus() int { states := []int{3, 3, 3} diff --git a/internal/ec2/instances.go b/internal/ec2/instances.go index f7db66f..7ef5fd1 100644 --- a/internal/ec2/instances.go +++ b/internal/ec2/instances.go @@ -22,7 +22,7 @@ func (i Instances) GetStatus() int { func (i Instances) GetOutput() (output string) { for _, instance := range i.Instances { - output += fmt.Sprintf("[%s] %s %s\n", + output += fmt.Sprintf(" \\_[%s] %s %s\n", check.StatusText(instance.GetStatus()), *instance.Instance.InstanceId, instance.GetOutput()) diff --git a/internal/s3/bucket.go b/internal/s3/bucket.go index b962cb6..4cbb5bc 100644 --- a/internal/s3/bucket.go +++ b/internal/s3/bucket.go @@ -16,7 +16,7 @@ type V2Output struct { } func (v *V2Output) GetBucketOutput(size int64, status int) (output string) { - output = fmt.Sprintf("[%s] %s: %s", + output = fmt.Sprintf(" \\_[%s] %s - value: %s", check.StatusText(status), *v.V2Output.Name, convert.BytesIEC(size)) diff --git a/internal/s3/object.go b/internal/s3/object.go index 7c2a6f4..c0df579 100644 --- a/internal/s3/object.go +++ b/internal/s3/object.go @@ -7,7 +7,7 @@ import ( ) func (v *V2Output) GetObjectOutput(size int64, status int, path string) (output string) { - output += fmt.Sprintf(" \\_[%s] %s: %s\n", + output += fmt.Sprintf(" \\_[%s] %s: %s\n", check.StatusText(status), path, convert.BytesIEC(size))