agent462 / sensu-cli Goto Github PK
View Code? Open in Web Editor NEWA Sensu CLI for getting and deleting information from Sensu.
A Sensu CLI for getting and deleting information from Sensu.
from @joemiller:
what do you think about extending it beyond just the rest api and providing interfaces to other things like the sensu client socket? eg: sensu event create NAME STATUS OUTPUT (options) would be equiv to: echo '{"name": "some_check", "status": 2, "output": "check output"}' | nc 127.0.0.1 3030
When I pipe sensu-cli through something that kills the sensu-cli proc mid-stream, it gets a broken-pipe exception:
$ sensu-cli client list -f json | grep -q something
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.1/lib/sensu-cli/pretty.rb:39:in `write': Broken pipe - <STDOUT> (Errno::EPIPE)
from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.1/lib/sensu-cli/pretty.rb:39:in `puts'
from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.1/lib/sensu-cli/pretty.rb:39:in `puts'
from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.1/lib/sensu-cli/pretty.rb:39:in `json'
from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.1/lib/sensu-cli/base.rb:59:in `make_call'
from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.1/lib/sensu-cli/base.rb:7:in `setup'
from /opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.1/bin/sensu-cli:6:in `<top (required)>'
from /usr/bin/sensu-cli:23:in `load'
from /usr/bin/sensu-cli:23:in `<main>'
But only if I have grep -q?
Can you try to repo this on a setup you have to confirm it is not just me?
I would like to add bash completion to your tool to make it easier to tab out. (I'm so lazy)
Would you accept such a contribution? If so, I'm not sure where it would fit in a gem. contrib folder?
There isn't a specific unsilence command. I'm guessing this could be done with a stash delete of silence/{client,check}, based on a cursory look at the code.
But it would be cool if that were rolled into a command to unsilence a client or check, since the end user isn't necessarily going to know the stash path (and I haven't tested that the above works).
Some thoughts for commands:
sensu client list
sensu client show (client)
sensu client silence (client)
sensu client delete (client)
sensu check list
sensu check silence (check)
sensu event list ("sensu events/sensu status"?)
sensu event show (event)
The documentation about the setting.rb is too simples. For example:
The documentation still advocates using the old stash-based approach to deleting silencers older than N number of hours. I'd like to use the new silenced subcommand but notice that --format is not supported. This makes me sad.
Hi,
First of all, great tool!
Would it be possible to switch the silence functionality to use the new silence API, available since 0.26.x
? https://sensuapp.org/docs/0.26/api/silenced-api.html
The older stash method of silencing alerts is deprecated from this version onwards.
sensu/sensu#1328
sensu-cli makes interacting with the Sensu API simple and fairly painless, unless you want to apply some action to multiple results. I've got a script I threw together that I've been using to help automate some of the actions surrounding this. I figure they may be of use to others.
https://gist.github.com/yacn/6453047
It's pretty hacky and could definitely be cleaned up and refined, but I figured I may as well get it out there so others could benefit.
Installed sensu-cli, and no executable is being found:
$ sudo gem install sensu-cli
Successfully installed rainbow-1.1.4
Successfully installed mixlib-config-1.1.2
Successfully installed sensu-cli-0.0.10
3 gems installed
Installing ri documentation for rainbow-1.1.4...
Installing ri documentation for mixlib-config-1.1.2...
Installing ri documentation for sensu-cli-0.0.10...
Installing RDoc documentation for rainbow-1.1.4...
Installing RDoc documentation for mixlib-config-1.1.2...
Installing RDoc documentation for sensu-cli-0.0.10...
$ sensu-cli
-bash: sensu-cli: command not found
Uchiwa has the concept of datacentre, it would be great if the sensu-cli was able to set this field during stash creation. The use case I've currently got: creating silence stashes for EC2 instances that are coming up during instance creation, in a different datacentre to the Jenkins master that I'm creating the silence stashes from.
Sorry, I made a mistake
I would like to trigger an event on a client. 5672 is one of the few ports that is open on the sensu-server.
Using version 0.6.3 of sensu-cli and running 'sensu event list' shows an erubis error message. Other sensu-cli commands seem to work fine.
~ ᐅ cat ~/.sensu/settings.rb
environment = ENV['SENSU_ENV']
port "4567"
ssl false
host case environment
when 'dev-ue1'
'sensu-ue1.gin-dev.com'
when 'dev-uw1'
'sensu-uw1.gin-dev.com'
when 'prod-ue1'
'sensu-ue1.s-gin.com'
when 'prod-uw1'
'sensu-uw1.s-gin.com'
else
puts "#{environment} is not a valid environment"
exit 1
end
~ ᐅ SENSU_ENV=prod-ue1 sensu event list
(erubis:2:in `result': undefined local variable or method `id' for #<Erubis::Eruby:0x007ffd312cbbf0> (NameError)
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:65:in `eval'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:65:in `result'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.3/lib/sensu-cli/pretty.rb:16:in `block in print'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.3/lib/sensu-cli/pretty.rb:15:in `each'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.3/lib/sensu-cli/pretty.rb:15:in `print'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.3/lib/sensu-cli/base.rb:61:in `make_call'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.3/lib/sensu-cli/base.rb:7:in `setup'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/sensu-cli-0.6.3/bin/sensu:6:in `<top (required)>'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/bin/sensu:23:in `load'
from /Users/j.alberts/.rbenv/versions/2.0.0-p576/bin/sensu:23:in `<main>'
~ ᐅ SENSU_ENV=prod-ue1 sensu info
sensu: {"version"=>"0.12.6"}
rabbitmq: {"keepalives"=>{"messages"=>0, "consumers"=>4}, "results"=>{"messages"=>84, "consumers"=>4}, "connected"=>true}
redis: {"connected"=>true}
3 total items
~ ᐅ gem list | grep erubis
erubis (2.7.0)
~ ᐅ SENSU_ENV=prod-ue1 sensu -v
sensu-cli version: 0.6.3
Ubuntu 14.04.1
Sensu 0.14 installed from the omnibus packages on the apt repository
sensu-cli 0.6.3
I'm using the Ruby and Gem embedded with Sensu:
# cat /etc/profile.d/sensu.sh
export PATH=/opt/sensu/embedded/bin:/etc/sensu/plugins:$PATH
# which gem
/opt/sensu/embedded/bin/gem
I did 'gem install sensu-cli' and ran it once.
# sensu-cli info
We created the configuration file for you at /root/.sensu/settings.rb. You can also place this in /etc/sensu/sensu-cli. Edit the settings as needed.
# sensu-cli info
The request requires user authentication.
Okay, I put the user and password there and it worked fine.
# sensu-cli info
sensu: {"version"=>"0.14.0"}
transport: {"keepalives"=>{"messages"=>0, "consumers"=>1}, "results"=>{"messages"=>2, "consumers"=>1}, "connected"=>true}
redis: {"connected"=>true}
3 total items
Then I moved the config file into /etc/sensu, based on the warning during the first run, but the cli doesn't seem to use the system-level config file:
# cat .sensu/settings.rb > /etc/sensu/sensu-cli
# rm -rf .sensu/
# sensu-cli info
We created the configuration file for you at /root/.sensu/settings.rb. You can also place this in /etc/sensu/sensu-cli. Edit the settings as needed.
I have a bunch of checks that use 'source' for devices on my network that can't run a sensu client (SANs, switches, firewalls, etc). I'd like to be able to use sensu-cli to amend the address and subscriptions for these clients.
asking nicely rather than creating a pull request (let me know whether you prefer that i will submit a pull request)...
please update the rubygems in the project.
Bundler could not find compatible versions for gem "rainbow":
In Gemfile:
rubocop (= 0.50.0) was resolved to 0.50.0, which depends on
rainbow (< 3.0, >= 2.2.2)
sensu-cli (~> 0) was resolved to 0.0.7, which depends on
rainbow (= 1.1.4)
It would be nice if the sensu event list would output the subscription information.
The coloured output is really helpful, but in some situations it makes it difficult to integrate the tool in scripts.. for example we run this during instance startup in AWS:
sensu-cli client history $(facter fqdn) | grep last_status | \
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | awk '{print $2}' | egrep '(1|2|3)'
That nasty sed is there to parse the coloured output ASCII codes, otherwise we can't properly grep for last_status
codes
Is there a simpler way to do this within the shell output?
Alternatively, would you consider adding an option which allows --nocolour
?
sensu-cli socket create -n bla -s 2 -o haha
results in:
UDP Socket Message Sent
but no check appeared in uchiwa
After installing and running sensu-cli it states a deprecation Warning:
root@sensu02:/etc/sensu/sensu-cli# /opt/sensu/embedded/bin/gem install sensu-cli
Fetching: sensu-cli-0.10.0.gem (100%)
Successfully installed sensu-cli-0.10.0
Parsing documentation for sensu-cli-0.10.0
Installing ri documentation for sensu-cli-0.10.0
Done installing documentation for sensu-cli after 0 seconds
1 gem installed
root@sensu02:/etc/sensu/sensu-cli# sensu-cli
[DEPRECATION] This gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
#
# Welcome to the sensu-cli.
# ______
# .-' '-.
# .' __ '.
# / / \ \
# ------------------
# /\
# '--'
# SENSU-CLI
#
Will you switch to trollop in the near future or do we have to live with this Deprecation warning? :)
sensu-cli requires that the CWD be in the gem location in order to find event.erb:
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.1/lib/sensu-cli/pretty.rb:13:in `read': No such file or directory - lib/sensu-cli/templates/event.erb (Errno::ENOENT)
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.1/lib/sensu-cli/pretty.rb:13:in `print'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.1/lib/sensu-cli/base.rb:61:in `make_call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.1/lib/sensu-cli/base.rb:7:in `setup'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.1/bin/sensu-cli:6:in `<top (required)>'
from /opt/chef/embedded/bin/sensu-cli:23:in `load'
from /opt/chef/embedded/bin/sensu-cli:23:in `<main>'
sensu-cli check list
An HTTP error occurred. Check your settings. Connection refused - connect(2)
/home/user/.sensu/settings.rb.
host "company.sheva.io"
port "4567"
ssl false
read_timeout 20
open_timeout 20
user ""
password ""
uchiwa.json contains an empty pass and username as well
I'm using sensu-cli version 0.7.1 and ruby version 2.1.5
> sensu-cli stash list
/Users/therobot/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/json-1.8.3/lib/json/common.rb:155:in `parse': 757: unexpected token at 'null (JSON::ParserError)
'
from /Users/therobot/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/json-1.8.3/lib/json/common.rb:155:in `parse'
from /Users/therobot/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/sensu-cli-0.7.1/lib/sensu-cli/api.rb:39:in `response'
from /Users/therobot/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/sensu-cli-0.7.1/lib/sensu-cli/base.rb:60:in `make_call'
from /Users/therobot/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/sensu-cli-0.7.1/lib/sensu-cli/base.rb:11:in `setup'
from /Users/therobot/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/sensu-cli-0.7.1/bin/sensu:6:in `<top (required)>'
from /Users/therobot/.rbenv/versions/2.1.5/bin/sensu:23:in `load'
from /Users/therobot/.rbenv/versions/2.1.5/bin/sensu:23:in `<main>'
The sensu-client connects to the RabbitMQ server instead of the API directly. Would it be possible to let the sensu-cli connect to the messagebroker instead of the api directly?
Hi,
I have some custom values in my event-data on which i would like to do some filtering. Looking at the code, i figured that i would need to add my custom field to templates/event.erb file for it to display in the output.
Shouldn't it by default display all the fields which are part of the event ? or maybe its possible to print in the output and i'm missing something.
Thanks
Can we get a new version of the gem released with the latest patch please? It would really help unblock me.
Config is:
host '[SNIP]'
port '4567'
I enabled http debugging, stack traces, and output of 'opts'. result is:
{:path=>"/clients?limit=&offset=",
:method=>"Get",
:payload=>false,
:host=>"[SNIP]",
:port=>"4567",
:ssl=>false,
:user=>nil,
:read_timeout=>15,
:open_timeout=>5,
:password=>nil,
:proxy_address=>:ENV,
:proxy_port=>nil}
opening connection to ENV...
An HTTP error occurred. Check your settings. can't convert Symbol into String ["/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:763:in `initialize'", "/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:763:in `open'", "/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:763:in `block in connect'", "/opt/chef/embedded/lib/ruby/1.9.1/timeout.rb:69:in `timeout'", "/opt/chef/embedded/lib/ruby/1.9.1/timeout.rb:100:in `timeout'", "/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:763:in `connect'", "/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:756:in `do_start'", "/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:745:in `start'", "/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:1285:in `request'", "/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.0/lib/sensu-cli/api.rb:31:in `request'", "/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.0/lib/sensu-cli/base.rb:47:in `make_call'", "/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.0/lib/sensu-cli/base.rb:7:in `setup'", "/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/sensu-cli-0.6.0/bin/sensu-cli:6:in `<top (required)>'", "/opt/chef/embedded/bin/sensu-cli:23:in `load'", "/opt/chef/embedded/bin/sensu-cli:23:in `<main>'"]
Note the opening connection to ENV...
.
It looks like the issue is in lib/sensu-cli/base.rb where it defaults proxy_address to :ENV. Most places where environmental variables are used for proxies will specify the address and port together, so I don't think it makes sense in this structure to pull it from ENV.
Switching it to default to nil resolves the issue.
Earlier today I tried the sensu-cli and used:
sensu-cli event delete NODE CHECK
I initially thought that it would remove the check from the list of checks known to a certain client, but looks like I was wrong. The check was still shown on e.g. the list of checks on the client - but now without the results.
What I was looking for, was to clear any check results etc. for a certain check on a specific client, as it was removed from my configuration due to a new check with a new name.
To clear / remove trace of the check on the device, I ended up doing a curl
directly to the Sensu API based on this: https://sensuapp.org/docs/0.26/api/results-api.html#resultsclientcheck-delete
Any chance this type of action could be added to sensu-cli?
The team wants the ability to filter results of at least clients by some given parameter. This would be client side filtering today. Potential pull request to sensu api?
sensu-cli
throws errors when tab-completing commands. The error is -bash: COMP_WORDS: bad array subscript
and appears to be caused by https://github.com/agent462/sensu-cli/blob/47cee1b569/contrib/sensu-cli.bash#L27-L28, which attempt to reference array elements less than 0.
How about adding an option to sensu event list to pull down the subscription information.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.