• Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 13 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A framework for writing Sensu plugins & handlers with Ruby.

Sensu Plugin

Build Status Gem Version Dependency Status pullreminders

This is a framework for writing your own Sensu plugins and handlers. It's not required to write a plugin (most Nagios plugins will work without modification); it just makes it easier.

Examples of plugins written with and without it can be found in the sensu-plugins organization.

Checks and Metrics

To implement your own check, subclass Sensu::Plugin::Check::CLI, like this:

require 'sensu-plugin/check/cli'

class MyCheck < Sensu::Plugin::Check::CLI

  check_name 'my_awesome_check' # defaults to class name
  option :foo, :short => '-f' # Mixlib::CLI is included

  def run
    ok "All is well"
  end

end

This will output the string "my_awesome_check OK: All is well" (like a Nagios plugin), and exit with a code of 0. The available exit methods, which will immediately end the process, are:

  • ok
  • warning
  • critical
  • unknown

You can also call message first to set the message, then call an exit method without any arguments (for example, if you want to choose between WARNING and CRITICAL based on a threshold, but use the same message in both cases).

For a metric, you can subclass one of the following:

  • Sensu::Plugin::Metric::CLI::JSON
  • Sensu::Plugin::Metric::CLI::Graphite
  • Sensu::Plugin::Metric::CLI::Statsd
  • Sensu::Plugin::Metric::CLI::Dogstatsd
  • Sensu::Plugin::Metric::CLI::Influxdb
  • Sensu::Plugin::Metric::CLI::Generic

Instead of outputting a Nagios-style line of text, these classes will output differently formated messages depending on the class you chose.

require 'sensu-plugin/metric/cli'

class MyJSONMetric < Sensu::Plugin::Metric::CLI::JSON

  def run
    ok 'foo' => 1, 'bar' => 'anything'
  end

end
require 'sensu-plugin/metric/cli'

class MyGraphiteMetric < Sensu::Plugin::Metric::CLI::Graphite

  def run
    ok 'sensu.baz', 42
  end

end
require 'sensu-plugin/metric/cli'

class MyStatsdMetric < Sensu::Plugin::Metric::CLI::Statsd

  def run
    ok 'sensu.baz', 42, 'g'
  end

end
require 'sensu-plugin/metric/cli'

class MyDogstatsdMetric < Sensu::Plugin::Metric::CLI::Dogstatsd

  def run
    ok 'sensu.baz', 42, 'g', 'env:prod,myservice,location:us-midwest'
  end

end
require 'sensu-plugin/metric/cli'

class MyInfluxdbMetric < Sensu::Plugin::Metric::CLI::Influxdb

  def run
    ok 'sensu', 'baz=42', 'env=prod,location=us-midwest'
  end

end
require 'sensu-plugin/metric/cli'

class MyInfluxdbMetric < Sensu::Plugin::Metric::CLI::Generic

  def run
    ok metric_name: 'metric.name', value: 0
  end

end

JSON output takes one argument (the object), and adds a 'timestamp' key if missing. Graphite output takes two arguments, the metric path and the value, and optionally the timestamp as a third argument. Time.now.to_i is used for the timestamp if it is not specified. Statsd output takes three arguments, the metric path, the value and the type. Dogstatsd output takes three arguments, the metric path, the value, the type and optionally a comma separated list of tags, use colons for key/value tags, i.e. env:prod. Influxdb output takes two arguments, the measurement name and the value or a comma separated list of values, use = for field/value, i.e. value=42, optionally you can also pass a comma separated list of tags and a timestamp Time.now.to_i is used for the timestamp if it is not specified. Generic output takes a dictionary and can provide requested output format with same logic. And inherited class will have a --metric_format option to switch between different output formats.

Exit codes do not affect metric output, but they can still be used by your handlers.

Some metrics may want to output multiple values in a run. To do this, use the output method, with the same arguments as the exit methods, as many times as you want, then call an exit method without any arguments.

For either checks or metrics, you can override output if you want something other than these formats.

Options

For help on setting up options, see the mixlib-cli documentation. Command line arguments that are not parsed as options are available via the argv method.

Utilities

Various utility methods will be collected under Sensu::Plugin::Util. These won't depend on any extra gems or include actual CLI checks; it's just for common things that many checks might want to do.

Handlers

For your own handler, subclass Sensu::Handler. It looks much like checks and metrics; see the handlers directory for examples. Your class should implement handle. The instance variable @event will be set for you if a JSON event can be read from stdin; otherwise, the handler will abort. Output to stdout will go to the log.

You can decide if you want to handle the event by overriding the filter method; but this also isn't documented yet (see the source; the built in method does some important filtering, so you probably want to call it with super).

Important!

Filtering of events is now deprecated in Sensu::Handler and disabled by default as of version 2.0.

Event filtering in this library may be enabled on a per-check basis by setting the value of the check's enable_deprecated_filtering attribute to true.

These built-in filters will be removed in a future release. See this blog post for more detail.

Mutator

For your own mutator, subclass Sensu::Mutator. It looks much like checks and metrics; Your class should implement mutate. The instance variable @event will be set for you if a JSON event can be read from stdin; otherwise, the mutator will abort. Output to stdout will then be piped through to the handler. As described in the docs if a mutator fails to run the event will not be handled.

The example mutator found here will look like so:

require 'sensu-mutator'

class MyMutator < Sensu::Mutator

  def mutate
    @event.merge!(:mutated => true)
  end

end

Plugin settings

Whether you are writing a check, handler or mutator, Sensu's configuration settings are available with the settings method (loaded automatically when the plugin runs). We recommend you put your custom plugin settings in a JSON file in /etc/sensu/conf.d, with a unique top-level key, e.g. my_custom_plugin:

{
  "my_custom_plugin": {
    "foo": true,
    "bar": false
  }
}

And access them in your plugin like so:

def foo_enabled?
  settings['my_custom_plugin']['foo']
end

Sensu Go enablement

This plugin provides basic Sensu Go enablement support to make it possible to continue to use existing Sensu plugin handlers and mutators for Sensu Core 1.x event model in a backwards compatible fashion.

Sensu Go event mapping

The provided mutator command mutator-sensu-go-into-ruby.rb will mutate the Sensu Go event into a form compatible for handlers written to consume Sensu Core 1.x events. Users may find this mutator useful until such time that community plugin handler are updated to support Sensu Go event model directly.

Sensu plugins which provide either mutators or handlers can benefit from provided Sensu Go enablement support in the form of mixin commandline option support. Once plugins update to the latest sensu-plugin version, all mutator and handler commands will automatically grow an additional commandline argument --map_go_event_into_ruby

Custom attributes

For backwards compatibility, you can store custom entity and check attributes as a json string in a specially named annotation. By default the annotation key is sensu.io.json_attributes, but can be overridden using the environment variable MAP_ANNOTATION. The json string stored in the MAP_ANNOTATION key will be converted into a ruby hash and merged into the ruby event hash object as part of the event mapping.

Contributing

  • Fork repository
  • Add functionality and any applicable tests
  • Ensure all tests pass by executing bundle exec rake test
  • Open a pull request

You may run individual tests by executing bundle exec rake test TEST=test/external_handler_test.rb

License

Copyright 2011 Decklin Foster

Released under the same terms as Sensu (the MIT license); see LICENSE for details.

More Repositories

1

sensu-plugins-aws

This plugin provides native AWS instrumentation for monitoring and metrics collection, including: health and metrics for various AWS services, such as EC2, RDS, ELB, and more, as well as handlers for EC2, SES, and SNS.
Ruby
81
star
2

sensu-plugin-python

A framework for writing Sensu plugins & handlers with Python.
Python
64
star
3

sensu-plugins-docker

This plugin provides native Docker instrumentation for monitoring and metrics collection, including: container status, container number, and container metrics via `docker ps`.
Ruby
36
star
4

sensu-plugins-elasticsearch

This plugin provides native ElasticSearch instrumentation for monitoring and metrics collection, including: service health and metrics for cluster, node, and more.
Ruby
32
star
5

sensu-plugins-http

This plugin provides native HTTP instrumentation for monitoring and metrics collection, including: response code, JSON response, HTTP last modified, SSL expiry, and metrics via `curl`.
Ruby
30
star
6

sensu-plugins-slack

Sensu Slack chat handlers
Ruby
30
star
7

sensu-plugins-network-checks

This plugin provides native network instrumentation for monitoring and metrics collection, including: hardware, TCP response, RBLs, whois, port status, and more.
Ruby
30
star
8

sensu-plugins-kubernetes

Sensu plugins for Kubernetes
Ruby
28
star
9

sensu-plugins-disk-checks

This plugin provides native disk instrumentation for monitoring and metrics collection, including: health, usage, and various metrics.
Ruby
27
star
10

sensu-plugins-rabbitmq

This plugin provides native RabbitMQ instrumentation for monitoring and metrics collection, including: service health, message, consumer, and queue health/metrics via `rabbitmq_management`, and more.
Ruby
23
star
11

sensu-plugins-windows

Sensu Windows Plugins
PowerShell
22
star
12

sensu-plugins-graphite

This plugin provides native Graphite instrumentation for monitoring, including: replication status, various Graphite data queries, mutators, and handlers
Ruby
22
star
13

community

Your place to contribute to Sensu plugins and their maintainers
21
star
14

sensu-plugins-process-checks

This plugin provides native process instrumentation for monitoring and metrics collection, including: process status, uptime, thread count, and others.
Ruby
20
star
15

sensu-plugins-pagerduty

This plugin provides a Sensu handler for PagerDuty.
Ruby
20
star
16

sensu-plugins-influxdb

This plugin provides native InfluxDB instrumentation for monitoring and metrics collection, including: service health via `/ping`, running queries, and service metrics.
Ruby
18
star
17

sensu-plugins-mysql

This plugin provides native MySQL instrumentation for monitoring and metrics collection, including: service health, database connectivity, `InnoDB` locks, replication status, metrics collection, and sending metrics to a MySQL database.
Ruby
18
star
18

sensu-plugins-mailer

This plugin is an email handler for Sensu.
Ruby
17
star
19

sensu-plugins-ssl

This plugin provides native SSL instrumentation for monitoring, including: hostname and chain verification, cert expiry, and Qualys SSL Labs reporting
Ruby
16
star
20

sensu-plugins-memory-checks

This plugin provides native memory instrumentation for monitoring and metrics collection, including: memory usage via `free` and `vmstat`, including metrics. Note that this plugin may have cross-platform issues.
Ruby
15
star
21

sensu-plugins-postgres

This plugin provides native PostgreSQL instrumentation for monitoring and metrics collection, including: service health, database connectivity, database locks, replication status, database size, `pg_stat_bgwriter` metrics, and more.
Ruby
15
star
22

sensu-plugins-cpu-checks

This plugin provides native CPU instrumentation for monitoring and metrics collection, including: CPU usage and metrics for user, nice, system, idle, iowait, irq, softirq, steal, and guest.
Ruby
13
star
23

sensu-plugins-consul

This plugin provides native instrumentation for monitoring Consul, including: Consul server service and cluster health, and querying the Consul API to check for passing/critical services.
Ruby
13
star
24

sensu-plugins-sensu

This plugin provides monitoring and metrics for Sensu.
Ruby
12
star
25

sensu-plugins-redis

This plugin provides native Redis instrumentation for monitoring and metrics collection, including: service health, database connectivity, replication status, `INFO` metrics, key counts, list lengths, and more.
Ruby
12
star
26

sensu-plugins-haproxy

This plugin provides native HAProxy instrumentation for monitoring and metrics collection, including: service health and backend server metrics.
Ruby
11
star
27

sensu-plugins-logstash

This plugin provides native logstash instrumentation for monitoring, including: a handler for sending events to logstash.
Ruby
10
star
28

sensu-plugins-jenkins

This plugin provides native Jenkins instrumentation for monitoring and metrics collection, including: health, job status, metrics via `JQS`, and others.
Ruby
9
star
29

sensu-plugins-mongodb

This plugin provides native MongoDB instrumentation for monitoring and metrics collection, including: service health, database connectivity, replication lag/status, `oplog` monitoring, collection-specific metrics, and more.
Python
9
star
30

sensu-plugins-filesystem-checks

This plugin provides native instrumentation for monitoring and metrics collection, including:health, usage, and various metrics of filesystem attributes.
Ruby
8
star
31

sensu-plugins-logs

This plugin provides native instrumentation for monitoring log files or system logs via journald for regular expressions, and a Sensu handler for logging Sensu events to log files.
Ruby
8
star
32

sensu-extensions-influxdb2

Ruby
7
star
33

sensu-plugins-cassandra

This plugin provides native Cassandra instrumentation for monitoring and metrics collection, including: service health, database connectivity, and various `nodetool` checks (e.g. schema disagreement, `tpstats` metrics, etc) and more.
Ruby
7
star
34

sensu-plugins-load-checks

This plugin provides native load instrumentation for monitoring and metrics collection, including: load health, and total or per core metrics.
Ruby
7
star
35

sensu-plugins-telegram

Telegram handler for sensu
Ruby
6
star
36

sensu-plugins-ansible

Handlers for the Ansible infrastructure automation engine.
Ruby
6
star
37

sensu-plugins-postfix

This plugin provides native Postfix instrumentation for monitoring and metrics collection of the mail queue via `mailq`.
Ruby
6
star
38

sensu-extensions-statsd

Check extension to run a StatsD implementation
Ruby
6
star
39

sensu-plugins-chef

This plugin provides native instrumentation for monitoring Chef, including service health checks (via chef-server-ctl) and chef node status, and a Sensu handler for removing stale Sensu clients.
Ruby
6
star
40

sensu-plugins-hardware

This plugin provides instrumentation for hardware monitoring via checking the system message buffer for "Hardware Error" entries using `dmesg`.
Ruby
6
star
41

sensu-plugins-sidekiq

Sensu plugins for Sidekiq
Ruby
6
star
42

sensu-plugins-java

Sensu Java Plugins
Ruby
5
star
43

sensu-plugins-dns

This plugin provides native DNS instrumentation for monitoring, including: record resolution
Ruby
5
star
44

sensu-plugins-sentry

Sensu Sentry Plugins
Ruby
5
star
45

sensu-plugins-serverspec

Sensu plugins for Severspec
Ruby
5
star
46

sensu-plugins-rspec

Sensu Plugins for running and alerting on rspec tests
Ruby
4
star
47

sensu-plugins-dashing

Sensu plugins for dashing
Ruby
4
star
48

sensu-plugins-systemd

Sensu plugins for Systemd
Ruby
4
star
49

sensu-extensions-snmp-trap

Check extension to receive SNMP traps and translate them into check results
Ruby
4
star
50

sensu-plugins-opsgenie

Sensu plugins for OpsGenie
Ruby
4
star
51

handler-mattermost

mattermost plugin for sensu
Ruby
4
star
52

sensu-plugins-datadog

Datadog handlers for Sensu
Ruby
4
star
53

sensu-plugins-statuspage

Sensu plugins for Statuspage
Ruby
4
star
54

sensu-plugins-skel

A skeleton repository to be used for creating new plugin repos.
Ruby
4
star
55

sensu-plugins-supervisor

Sensu plugins for Supervisor
Ruby
4
star
56

sensu-plugins-openstack

This plugin provies native OpenStack instrumentation for monitoring and metrics collection, including: service health and metrics from Ceilometer, Keystone, Neutron, and Nova.
Python
4
star
57

documentation

The home for all sensu-plugins standalone docs. NOTE: Get your edits in here before the migration to sensuapp.org
4
star
58

sensu-plugins-ntp

This plugin provides native NTP instrumentation for monitoring and metrics collection, including: server drift, and metrics via `ntpdate` and `ntpstats`.
Ruby
4
star
59

sensu-plugins-snmp

This plugin provides native SNMP instrumentation for monitoring and metrics collection, including: generic OID single/bulk query for status and metrics, and ifTable metrics.
Ruby
4
star
60

sensu-plugins-nginx

This plugin provides native nginx instrumentation for metrics collection, including: metrics via `stub_status`.
Ruby
4
star
61

sensu-plugins-syslog-ng

Sensu plugins for Syslog-NG
Ruby
3
star
62

sensu-plugins-zfs

Sensu ZFS Plugin
Ruby
3
star
63

sensu-plugins-ubiquiti

Sensu plugins for Ubiquiti devices
Ruby
3
star
64

sensu-plugins-splunk

Sensu Splunk Plugins
Ruby
3
star
65

sensu-plugins-zookeeper

Sensu Zookeeper Plugins
Ruby
3
star
66

sensu-plugins-victorops

Sensu VictorOps Handlers
Ruby
3
star
67

sensu-plugins-solr

This plugin provides native Apache Solr instrumentation for monitoring and metrics collection, including: service health, service connetivity, replication status, and a variety of metrics including memory consumption, open file counts, and more.
Ruby
3
star
68

sensu-plugins-ipmi

Sensu IPMI Plugins
Ruby
3
star
69

sensu-plugins-stackstorm

Sensu plugins for StackStorm
Python
3
star
70

sensu-plugins-uptime-checks

This plugin provides native instrumentation for collecting uptime and idletime metrics.
Ruby
3
star
71

sensu-plugins-azurerm

This plugin provides native Azure instrumentation for monitoring and metrics collection, including: health and metrics for various Azure services
Ruby
3
star
72

sensu-plugins-puppet

This plugin provides native Puppet instrumentation for monitoring and collecting metrics from Puppet runs.
Ruby
3
star
73

GIR

Sensu-Plugins development framework and tooling
Ruby
3
star
74

sensu-plugins-cgroups

Metrics for kernel control groups
Ruby
3
star
75

sensu-plugins-mesos

This plugin provides navite Mesos instrumentation for monitoring and metrics collection, including: service health and metrics for Mesos, Chronos, and Marathon.
Ruby
3
star
76

sensu-plugins-rocket-chat

Sensu plugin for interfacing with RocketChat (based on sensu-plugins-telegram)
Ruby
2
star
77

sensu-plugins-wordpress

Sensu Wordpress Plugins
Ruby
2
star
78

sensu-plugins-twemproxy

Add a description
Ruby
2
star
79

sensu-plugins-openldap

Sensu OpenLDAP Plugins
Ruby
2
star
80

sensu-plugins-couchbase

Sensu Couchbase Plugins
Python
2
star
81

sensu-plugins-newrelic

Sensu NewRelic Plugins
Ruby
2
star
82

sensu-plugins-ups

Ruby
2
star
83

sensu-plugins-sms

Sensu SMS plugins
Ruby
2
star
84

sensu-plugins-etcd

Sensu etcd Plugins
Ruby
2
star
85

sensu-plugins-sip

Sensu plugins for SIP
Ruby
2
star
86

sensu-plugins-kafka2

Sensu Plugins for kafka
Ruby
2
star
87

sensu-plugins-ceph

Monitors and metrics for the Ceph Storage System
Ruby
2
star
88

sensu-plugins-vault

Sensu Plugins for hashicorp vault
Ruby
2
star
89

sensu-plugins-couchdb

Ruby
2
star
90

sensu-plugins-riemann

Sensu plugins for Riemann monitoring framework
Ruby
2
star
91

sensu-plugins-percona

Add a description
Ruby
2
star
92

sensu-plugins-hubot

Sensu Hubot Plugins
Ruby
2
star
93

sensu-plugins-unicorn

Sensu Plugins for the Unicorn Server
Ruby
2
star
94

sensu-plugins-go

Sensu library designed for golang plugins [Expermental WIP]
Go
2
star
95

sensu-plugins-monit

Sensu Monit Plugins
Ruby
2
star
96

sensu-plugins-memcached

This plugin provides native memcached instrumentation for monitoring and metrics collection, including: service health and metrics via the memcached stats command.
Ruby
2
star
97

sensu-plugins-dcos

Sensu plugins for DCOS
Ruby
2
star
98

sensu-plugins-microsoft-teams

Sensu plugins for Microsoft Teams
Ruby
2
star
99

sensu-plugins-apache

This plugin provides native Apache instrumentation for metrics collection, including: `mod_status` metrics.
Ruby
2
star
100

sensu-plugins-vmstats

This plugin provides native vmstat instrumentation for metrics collection, including: processes waiting, interrupts per second, and more.
Ruby
2
star