Skip to content

Latest commit

 

History

History
260 lines (193 loc) · 5.81 KB

03-sensuctl.md

File metadata and controls

260 lines (193 loc) · 5.81 KB

Sensu CLI (sensuctl)

Installation

macOS

Download the latest release.

curl -LO https://storage.googleapis.com/sensu-release/$(curl -s https://storage.googleapis.com/sensu-release/latest.txt)/darwin/amd64/sensuctl

Optionally, if you would like to download a specific release, replace {VERSION} in the command below.

curl -LO https://storage.googleapis.com/sensu-release/{VERSION}/darwin/amd64/sensuctl

Make the sensuctl binary executable.

chmod +x sensuctl

Move the executable into your PATH.

sudo mv sensuctl /usr/local/bin/

Debian / Ubuntu

Add the Sensu prerelease repository (this step can be skipped if you previously added the repository on the backend/agent installation page).

export SENSU_REPO_TOKEN=your_token_here
curl -s https://$SENSU_REPO_TOKEN:@packagecloud.io/install/repositories/sensu/prerelease/script.deb.sh | sudo bash

Install the Sensu CLI package.

sudo apt-get install sensu-cli

RHEL / CentOS

Add the Sensu prerelease repository (this step can be skipped if you previously added the repository on the backend/agent installation page).

export SENSU_REPO_TOKEN=your_token_here
curl -s https://$SENSU_REPO_TOKEN:@packagecloud.io/install/repositories/sensu/prerelease/script.rpm.sh | sudo bash

Install the Sensu CLI package.

sudo yum install sensu-cli

Configure

Sensuctl must be configured before it can connect to your Sensu cluster. Run the configure command to get started.

sensuctl configure

sensu-configure-demo

Default User

By default, your Sensu installation comes with a single user named admin. This user has the password P@ssw0rd! and it is strongly recommended that you change it immediately. To do so, you'll first want to authenticate using the sensuctl tool.

sensuctl configure

? Sensu Base URL: http://my-sensu-host:8080
? Username: admin
? Password:  *********
? ...

Once authenticated, you can use the change-password command.

sensuctl user change-password

? Current Password:  *********
? Password:          *********
? Confirm:           *********

Tweak Values

You can change individual values with the config sub-command.

sensuctl config set-organization default
sensuctl config set-environment prod

Getting Help

All Sensu sub-commands have a --help flag that returns more information on using the command and if applicable any sub-commands it has.

sensuctl:

$ sensuctl --help

sensuctl controls Sensu instances

Usage:    sensuctl COMMAND

Options:
      --api-url string        host URL of Sensu installation
      --cache-dir string      path to directory containing cache & temporary files (default "/Users/deanlearner/Library/Caches/sensu/sensuctl")
      --config-dir string     path to directory containing configuration files (default "/Users/deanlearner/.config/sensu/sensuctl")
  -h, --help                  help for sensuctl
      --organization string   organization in which we perform actions (default "default")

Commands:
  completion   Output shell completion code for the specified shell (bash or zsh)
  configure    Initialize sensuctl configuration
  logout       Logout from sensuctl
  version      Show the sensu-ctl version information
  
Management Commands:
  asset        Manage assets
  check        Manage checks
  config       Modify sensuctl configuration
  entity       Manage entities
  environment  Manage environments
  event        Manage events
  handler      Manage handlers
  organization Manage organizations
  role         Manage roles
  user         Manage users

Import

On top of being able to create new resources interactively and with flags, sensuctl provides import commands for creating & updating resources via STDIN.

{
  "name": "marketing-site",
  "command": "check-http.rb -u https://dean-learner.book",
  "subscriptions": ["demo"],
  "interval": 15,
  "handlers": ["slack"],
  "organization": "default",
  "environment": "default"
}
# cat my-check.json | sensuctl check import
OK

Further API details- including valid parameters- forthcoming.

Output

sensuctl can be configured to return JSON instead of the default human-readable format.

sensuctl check info marketing-site --format json

{
  "name": "marketing-site",
  "interval": 10,
  "subscriptions": [
    "web"
  ],
  "command": "check-http.rb -u https://dean-learner.book",
  "handlers": [
    "slack"
  ],
  "runtime_assets": [],
  "environment": "default",
  "organization": "default"
}

If you do not want to explicitly use the format flag with each command, you can set the global default.

# sensuctl config set-format json
OK

Shell Auto-Completion

Installation (Bash Shell)

Make sure bash completion is installed. If you use a current Linux in a non-minimal installation, bash completion should be available. On a Mac, install with:

brew install bash-completion

Then add the following to your ~/.bash_profile:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi

When bash-completion is available we can add the following to your ~/.bash_profile:

source <(sensuctl completion bash)

You can now source your ~/.bash_profile or launch a new terminal to utilize completion.

source ~/.bash_profile

Installation (ZSH)

Add the following to your ~/.zshrc:

source <(sensuctl completion zsh)

You can now source your ~/.zshrc or launch a new terminal to utilize completion.

source ~/.zshrc

Usage

sensuctl:

$ sensuctl Tab

check       configure   event       user
asset       completion  entity      handler

sensuctl:

$ sensuctl check Tab

create  delete  import  list