MyNixOS website logo
Description

A tool to send command execution results to Sensu.

sensu-run is a command line tool to send command execution results to Sensu monitoring server.

sensu-run

Hackage Hackage-Deps 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] [--no-lock] [--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
  --no-lock                Do not create a lock file to allow multiple instances
                           to run
  --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 codestatus field
00 (OK)
non-zero2 (CRITICAL)
command timed out3 (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

Handling signals on UNIX systems

sensu-run traps the following signals and resends them to the monitored process:

  • SIGHUP
  • SIGINT
  • SIGQUIT
  • SIGTERM.
Metadata

Version

0.7.0.5

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows