sensu-run

A tool to send command execution results to Sensu https://github.com/maoe/sensu-run#readme

Version on this page:0.2.0
LTS Haskell 11.10:0.4.0.5
Stackage Nightly 2018-03-12:0.4.0.4
Latest on Hackage:0.5.0.1

See all snapshots sensu-run appears in

BSD3 licensed by Mitsutoshi Aoe
Maintained by maoe@foldr.in

Module documentation for 0.2.0

There are no documented modules for this package.

sensu-run

Hackage Hackage-Deps Stackage LTS Stackage Nightly Build Status Build status

sensu-run runs a command and send its result to Sensu server using the client socket input or via the Sensu API. It is useful to monitor cron jobs for example.

Installation

NOTE: Currently sensu-run doesn't work on Windows. See #16.

Binary releases are available at GitHub Releases. Currently supported platforms for the binary releases are:

  • Ubuntu (64bit)
  • macOS
  • Windows (x64, x86)

You can also build it yourself using stack:

stack install sensu-run

will install the sensu-run command in ~/.local/bin.

Usage

% sensu-run --help
Usage: sensu-run ([-n|--name NAME] [--source SOURCE] [--ttl SECONDS]
                 [--timeout SECONDS] [--handler HANDLER] ([--port PORT] |
                 [--server URL]) [--redirect] [--dry|--dry-run] [-s|--shell]
                 [COMMAND] | [-v|--version])

Available options:
  -h,--help                Show this help text
  -n,--name NAME           The name of the check
  --source SOURCE          The check source, used to create a JIT Sensu client
                           for an external resource
  --ttl SECONDS            The time to live in seconds until check results are
                           considered stale
  --timeout SECONDS        The check executaion duration timeout in seconds
  --handler HANDLER        Sensu event handler(s) to use for events created by
                           the check
  --port PORT              Send results to the local sensu-client listening on
                           the specified port (default: 3030)
  --server URL             Send results to the specified Sensu server
  --redirect               Redirect command output to sensu-run's output
  --dry,--dry-run          Dump the JSON object which is supposed to be sent
  -s,--shell               Execute the command using the shell

--dry-run option is useful to check the JSON output:

% sensu-run --name check-home-src-size --handler foo --dry-run -- du -s $HOME/src | jq .
{
  "name": "check-home-src-size",
  "command": "du -s /home/maoe/src",
  "issued": 1501041549,
  "executed": 1501041549,
  "duration": 1.674895,
  "status": 0,
  "output": "55513524\t/home/maoe/src\n",
  "handlers": [
    "foo"
  ],
  "user": "maoe"
}

Use the --shell option if you want to use shell functions:

% sensu-run --name check-home-src-size --handler foo --dry-run --shell -- "cd $HOME/src; du -s ." | jq .
{
  "name": "check-home-src-size",
  "command": "cd /home/maoe/src; du -s .",
  "issued": 1501041568,
  "executed": 1501041568,
  "duration": 1.224157,
  "status": 0,
  "output": "55513524\t.\n",
  "handlers": [
    "foo"
  ],
  "user": "maoe"
}

Without the --dry-run option, sensu-run sends the output to localhost:PORT, which is expected to be listened by sensu-client.

sensu-run sets the status field depending on the command exit code and timeout:

| command exit code | status field | |-------------------|----------------| | 0 | 0 (OK) | | non-zero | 2 (CRITICAL) | | command timed out | 3 (UNKNOWN) |

Sensu API

sensu-run supports posting check results via Sensu API as well. Use --server option to specify Sensu server addresses. If multiple servers are specified, sensu-run tries them one by one until it succeeds.

sensu-run --name check-true --handler foo --server sensu1.example.com --server sensu2.example.com --dry-run -- du -s $HOME/src

Changes

Revision history for sensu-run

0.5.0.1 -- 2018-04-30

  • Relax upper version bound for network and fix a warning

0.5.0 -- 2018-04-20

  • Add support for HTTPS (#18)
  • Do not append new line to the output when the command was successful
  • Add --redirect option (#12)
  • Relax upper version bound for temporary
  • Tighten upper version bound for unix

0.4.0.5 -- 2018-04-09

  • Relax upper version bounds for base and aeson

0.4.0.4 -- 2018-01-30

  • Relax upper version bounds for http-types, lens and time

0.4.0.3 -- 2017-11-07

  • Relax upper version bound for http-types

0.4.0.2 -- 2017-11-07

  • Relax upper version bound for unix-compat

0.4.0.1 -- 2017-10-26

  • Relax upper version bound for http-types

0.4.0 -- 2017-08-03

  • Include command output in response even on timeout/failure (#14)

0.3.0 -- 2017-07-25

  • Add user field to result JSON (#7)
  • Handle missing executable properly (#10)

0.2.0 -- 2017-07-12

  • Relax upper version bound for base
  • Kill child process(es) when timeout occurs

0.1.1.3 -- 2017-06-11

  • Relax upper version bound for optparse-applicative
  • Binary releases

0.1.1 -- 2017-06-09

  • Add --version option

0.1.0 -- 2017-06-07

  • Fix a bug that ignores --handle option by accident
  • Small documentation fixes
  • Enable AppVeyor builds

0.0.0 -- 2017-05-16

  • Initial release
comments powered byDisqus