Skip to content

Instantly share code, notes, and snippets.

@john-auld
Last active March 13, 2019 19:48
Show Gist options
  • Save john-auld/13243616273fcea6c95300517ccc1ae7 to your computer and use it in GitHub Desktop.
Save john-auld/13243616273fcea6c95300517ccc1ae7 to your computer and use it in GitHub Desktop.
Sensu Go
@john-auld
Copy link
Author

john-auld commented Mar 10, 2019

Subscribe agent to checks

agent configuration

On the host running the agent; edit the subscriptions to match the desired checks.

sudo vi /etc/sensu/agent.yml

# agent configuration
##
name: "server.example.com"
namespace: "default"
subscriptions:
  - linux
  - cpu

sudo systemctl restart sensu-agent

round robin checks

In Sensu core, adding the prefix "roundrobin:" to the subscription will make it a round robin check. E.g. roundrobin:webserver.

See round_robin on https://docs.sensu.io/sensu-go/5.3/reference/checks/#spec-attributes

Sensu-core docs: https://docs.sensu.io/sensu-core/1.1/reference/clients/#round-robin-client-subscriptions

@john-auld
Copy link
Author

Publish / Unpublish checks

Published checks are run on a schedule by the sensu scheduler.

Un-published checks are ignored by the scheduler, but they can be run on demand using the API or by another check as part of it's remediation configuration. See automating triage

@john-auld
Copy link
Author

Firewall ports

The Sensu backend uses:

  • 2379 (HTTP/HTTPS) Sensu storage client: Required for Sensu backends using an external etcd instance
  • 2380 (HTTP/HTTPS) Sensu storage peer: Required for other Sensu backends in a cluster
  • 3000 (HTTP/HTTPS) Sensu dashboard: Required for all Sensu backends using a Sensu dashboard
  • 8080 (HTTP/HTTPS) Sensu API: Required for all users accessing the Sensu API
  • 8081 (WS/WSS) Agent API: Required for all Sensu agents connecting to a Sensu backend

The Sensu agent uses:

  • 3030 (TCP/UDP) Sensu agent socket: Required for Sensu agents using the agent socket
  • 3031 (HTTP) Sensu agent API: Required for all users accessing the agent API
  • 8125 (UDP, TCP on Windows) StatsD listener: Required for all Sensu agents using the StatsD listener

source

@john-auld
Copy link
Author

john-auld commented Mar 10, 2019

Sensu checks

Bonsai is the registry of checks and handlers.

Create check from a script

sudo curl https://raw.githubusercontent.com/sensu-plugins/sensu-plugins-cpu-checks/03a99bab0237c81121ce702b0c5a5a3b44908535/bin/check-cpu.sh \
-o /usr/local/bin/check-cpu.sh && \
sudo chmod +x /usr/local/bin/check-cpu.sh
sensuctl check create check-cpu \
--command 'check-cpu.sh -w 75 -c 90' \
--interval 60 \
--subscriptions linux

source

Monitor an external resource (proxy entity)

sudo curl https://raw.githubusercontent.com/sensu/sensu-go/5.1.0/examples/checks/http_check.sh \
-o /usr/local/bin/http_check.sh && \
sudo chmod +x /usr/local/bin/http_check.sh

check.json

{
  "type": "CheckConfig",
  "api_version": "core/v2",
  "metadata": {
    "name": "check-http",
    "namespace": "default"
  },
  "spec": {
    "command": "http_check.sh https://sensu.io",
    "interval": 60,
    "proxy_entity_name": "sensu-site",
    "publish": true,
    "subscriptions": [
      "proxy"
    ]
  }
}

sensuctl create --file check.json

Add the subscription to an agent.

subscriptions:
  - "proxy"

sudo service sensu-agent restart

source

Sensu ruby plugin install

https://packagecloud.io/sensu/community

curl -s https://packagecloud.io/install/repositories/sensu/community/script.rpm.sh | sudo bash

sudo yum install sensu-plugins-ruby-0.2.0-1.el7.x86_64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment