A pluggable CLI utility to send alerts if a given command failed.
A pluggable CLI utility to send an alert if a given command failed.
I use alerty
to run commands in cron to send alerts if cron commands fail.
0 * * * * alerty -c /etc/alerty/alerty.yml -- /path/to/script --foo FOO --bar
gem install alerty
You can write a configuration file located at /etc/alerty/alerty.yml
(You can configure this path by ALERTY_CONFIG_FILE
environment variable, or -c
option):
log_path: /var/tmp/alerty.log
log_level: 'info'
log_shift_age: 10
log_shift_size: 10485760
timeout: 10
lock_path: /tmp/lock
retry_limit: 2
retry_wait: 10
plugins:
- type: stdout
$ alerty -c example.yml -- ls -l /something_not_exist
Usage: alerty [options] -- command
-c, --config CONFIG_FILE config file path (default: /etc/alerty/alerty.yml)
--log LOG_FILE log file path (default: STDOUT)
-l, --log-level LOG_LEVEL log level (default: warn)
--log-shift-age SHIFT_AGE Number of old log files to keep (default: 0 which means no log rotation)
--log-shift-size SHIFT_SIZE Maximum logfile size in bytes (default: 1048576)
-t, --timeout SECONDS timeout the command (default: no timeout)
--lock LOCK_FILE exclusive lock file to prevent running a command duplicatedly (default: no lock)
--retry-limit NUMBER number of retries (default: 0)
--retry-wait SECONDS retry interval = retry wait +/- 12.5% randomness (default: 1.0)
-d, --debug debug mode
--dotenv Load environment variables from .env file with dotenv
This interface allows us to send notification even if a command does not fail.
CLI Example:
$ echo 'this is a test' | alerty -c example.yml
Following plugins are available:
You must follow following naming conventions:
What you have to implement is #initialize
and #alert
methods. Here is an example of file
plugin:
require 'json'
class Alerty
class Plugin
class File
def initialize(config)
raise ConfigError.new('file: path is not configured') unless config.path
@path = config.path
end
def alert(record)
::File.open(@path, 'a') do |io|
io.puts record.to_json
end
end
end
end
end
config
is created from the configuration file:
plugins:
- type: foobar
key1: val1
key2: val2
config.key1
and config.key2
are availabe in the above config.
record
is a hash whose keys are symbols of followings:
See CHANGELOG.md for details.
See LICENSE