-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sudhanshu/5009 #5046
Sudhanshu/5009 #5046
Changes from 6 commits
0cc92d0
e0695a2
90be109
6fe811a
6a210ca
926185c
0e95059
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,39 @@ import ( | |
"github.com/sensu/sensu-go/testing/testutil" | ||
) | ||
|
||
//var asset *v2.Asset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you forgot those comments too? |
||
|
||
// sudhanshu- Git issue 5009 | ||
|
||
func TestCleanUp(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create a temporary directory for testing | ||
tmpDir := t.TempDir() | ||
|
||
// Define the SHA and file name | ||
SHAName := "shaAsset.tar" | ||
SHAFilePath := filepath.Join(tmpDir, SHAName) | ||
|
||
// Create a dummy file inside the temporary directory | ||
SHAFile, err := os.Create(SHAFilePath) | ||
if err != nil { | ||
t.Fatalf("Failed to create dummy file: %v", err) | ||
} | ||
SHAFile.Close() | ||
|
||
// Call CleanUp with the SHA of the dummy file and the temporary directory | ||
err = CleanUp(SHAFilePath) | ||
if err != nil { | ||
t.Errorf("CleanUp returned an error: %v", err) | ||
} | ||
|
||
_, err = os.Stat(SHAFilePath) | ||
if !os.IsNotExist(err) { | ||
t.Errorf("CleanUp did not remove the dummy file as expected") | ||
} | ||
} | ||
|
||
func TestExpandValidTar(t *testing.T) { | ||
t.Parallel() | ||
assetPath := getFixturePath("rubby-on-rails.tar") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ func AddCommand(cli *cli.SensuCli) *cobra.Command { | |
|
||
func addCommandExecute(cli *cli.SensuCli) func(cmd *cobra.Command, args []string) error { | ||
return func(cmd *cobra.Command, args []string) error { | ||
//sudhanshu/5009 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: No need to have the bug/pr reference here. |
||
//check if asset.db exits if not then re-create it also delete the SHA associated with it and re-create it. | ||
// | ||
// If no name is present print out usage | ||
if len(args) != 1 { | ||
_ = cmd.Help() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Changelog | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you added this file by accident? |
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic | ||
Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## Unreleased | ||
|
||
## [0.2.2] - 2021-03-31 | ||
|
||
### Changed | ||
- Updated README | ||
|
||
## [0.2.1] - 2021-03-10 | ||
|
||
### Changed | ||
- Change release github action to use macos-latest so that macos cgo build works | ||
|
||
## [0.2.0] - 2021-03-10 | ||
|
||
### Changed | ||
- Updated goreleaser to build macOS version with cgo enabled | ||
|
||
## [0.1.0] - 2020-12-30 | ||
|
||
### Added | ||
- Initial release |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2020 Todd Campbell | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you added this file by accident? |
||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
[](https://bonsai.sensu.io/assets/sensu/check-cpu-usage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you added this file by accident? |
||
 | ||
 | ||
|
||
# Sensu CPU usage check | ||
|
||
## Table of Contents | ||
- [Overview](#overview) | ||
- [Usage examples](#usage-examples) | ||
- [Configuration](#configuration) | ||
- [Asset registration](#asset-registration) | ||
- [Check definition](#check-definition) | ||
- [Installation from source](#installation-from-source) | ||
- [Contributing](#contributing) | ||
|
||
## Overview | ||
|
||
The Sensu CPU usage check is a [Sensu Check][1] that provides alerting and | ||
metrics for CPU usage. Metrics are provided in [nagios_perfdata][5] format. | ||
|
||
**Note:** The macOS binary is built using [cgo][6] and may not be portable | ||
across all versions of macOS. | ||
|
||
## Usage examples | ||
|
||
``` | ||
Check CPU usage and provide metrics | ||
|
||
Usage: | ||
check-cpu-usage [flags] | ||
check-cpu-usage [command] | ||
|
||
Available Commands: | ||
help Help about any command | ||
version Print the version number of this plugin | ||
|
||
Flags: | ||
-c, --critical float Critical threshold for overall CPU usage (default 90) | ||
-w, --warning float Warning threshold for overall CPU usage (default 75) | ||
-s, --sample-interval int Length of sample interval in seconds (default 2) | ||
-h, --help help for check-cpu-usage | ||
|
||
Use "check-cpu-usage [command] --help" for more information about a command. | ||
``` | ||
|
||
## Configuration | ||
|
||
### Asset registration | ||
|
||
[Sensu Assets][2] are the best way to make use of this plugin. If you're not | ||
using an asset, please consider doing so! If you're using sensuctl 5.13 with | ||
Sensu Backend 5.13 or later, you can use the following command to add the asset: | ||
|
||
``` | ||
sensuctl asset add sensu/check-cpu-usage | ||
``` | ||
|
||
If you're using an earlier version of sensuctl, you can find the asset on the | ||
[Bonsai Asset Index][3]. | ||
|
||
### Check definition | ||
|
||
```yml | ||
--- | ||
type: CheckConfig | ||
api_version: core/v2 | ||
metadata: | ||
name: check-cpu-usage | ||
namespace: default | ||
spec: | ||
command: >- | ||
check-cpu-usage | ||
--critical 95 | ||
--warning 85 | ||
--sample-interval 2 | ||
output_metric_format: nagios_perfdata | ||
output_metric_handlers: | ||
- influxdb | ||
subscriptions: | ||
- system | ||
runtime_assets: | ||
- sensu/check-cpu-usage | ||
``` | ||
|
||
## Installation from source | ||
|
||
The preferred way of installing and deploying this plugin is to use it as an | ||
Asset. If you would like to compile and install the plugin from source or | ||
contribute to it, download the latest version or create an executable from this | ||
source. | ||
|
||
From the local path of the check-cpu-usage repository: | ||
|
||
``` | ||
go build | ||
``` | ||
|
||
## Contributing | ||
|
||
For more information about contributing to this plugin, see [Contributing][4]. | ||
|
||
[1]: https://docs.sensu.io/sensu-go/latest/reference/checks/ | ||
[2]: https://docs.sensu.io/sensu-go/latest/reference/assets/ | ||
[3]: https://bonsai.sensu.io/assets/sensu/check-cpu-usage | ||
[4]: https://github.com/sensu/sensu-go/blob/master/CONTRIBUTING.md | ||
[5]: https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-schedule/collect-metrics-with-checks/#supported-output-metric-formats | ||
[6]: https://golang.org/cmd/cgo/ |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you added this file by accident? |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you added this file by accident? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you forgot to clean this up?