Monitoring::Sneck

SYNOPSIS

sneck -u [-C <cache file>] [-f <config file>] [-p] [-i] [-d] [-q] [-l|-L] [-P <pid dir>] [-r] [-T <seconds>] [-s <signal>] [-k|-K]

sneck -c [-C <cache file>] [-f <config file>] [-b]

sneck [-f <config file>] [-p] [-i] [-d] [-q] [-r] [-T <seconds>] [-s <signal>] [-k|-K]

sneck -t [-f <config file>]

sneck -h

sneck -v

FLAGS

The cache file, PID dir, locking, and check timeout settings may also be set in the config file. Flags override those. See OPTIONS.

-f config_file

The config file to use.

Files ending in .yaml or .yml are read as YAML, which needs YAML::XS.

Default :: /usr/local/etc/sneck.conf

-p

Pretty print the JSON.

-C cache_file

The cache file to use.

Overrides cache_file in the config.

Default :: /var/cache/sneck.cache

A secondary cache file based on this name is also created. By default it is /var/cache/sneck.cache.snmp and always holds the GZip+BASE64 compressed version.

Compliance check state, used for interval, is kept in the cache file name with .compliance added, so by default /var/cache/sneck.cache.compliance. It is only used if a compliance check has a interval.

-u

Update the cache file. Will also print what was written to it.

-c

Print the cache file. Please note that -p or -i won't affect this as this flag only reads/prints the cache file.

If the cache file does not exist or can't be read, error JSON saying so is printed and it exits 3.

-b

When used with -c, print the LibreNMS style GZip+BASE64 compressed cache instead.

-i

Includes the config file used.

-d

Print debugging info to stderr.

-q

Don't print the results. Exit quietly. Meant for use with -u.

-l

Enable locking for -u so more than one instance can't run at a time. Overrides locking in the config.

The PID file is sneck.pid in the directory set by -P.

-L

Disable locking, overriding locking in the config. Can not be used with -l.

-P pid_dir

The directory for the PID file used by -l. The user running sneck must be able to write to it.

Overrides pid_dir in the config.

Default :: /var/run

-r

Run any restarts whose checks failed. Without this, restarts are only reported as restarts disabled. Meant to be used with -u from cron. Never use it from snmpd.

Restart state, used for min_interval and max_retries, is kept in the cache file name with .restarts added, so by default /var/cache/sneck.cache.restarts.

Use locking with this to make sure two runs can't restart things at the same time. Without it, a warning saying so is printed to stderr.

-T seconds

Seconds to wait on each check before giving up on it. Overrides check_timeout in the config.

Default :: 30

-s signal

Signal to send a check on timeout, such as TERM. Overrides check_timeout_signal in the config. none sends no signal, even if the config sets one.

Default :: none

-k

Also send the timeout signal to all child processes of a check. Overrides check_kill_sub_pids in the config. Does nothing without a timeout signal. This is the default.

-K

Do not send the timeout signal to child processes of a check. Overrides check_kill_sub_pids in the config. Can not be used with -k.

-t

Test the config file. Prints any errors and warnings, then exits 0 if there are no errors and 1 if there are or the file can't be read. Warnings, such as a check using a undefined variable, do not affect the exit code.

-h, --help

Print the help.

-v, --version

Print the version.

CONFIG FORMAT

The sneck format is described below. Files ending in .yaml or .yml use the YAML format instead, described under YAML CONFIG.

Each line has leading spaces and tabs removed before it is looked at. A trailing \r is also removed, so files with CRLF line endings work.

Blank lines are ignored.

Lines starting with # are comments and are ignored.

Names are made up of A-Z, a-z, 0-9, and _.

Any other sort of line is an error. Every bad line is reported, along with its line number.

Variables are used in commands in the form %NAME%. A reference to a variable that is not defined is left as written and produces a warning, as it may just be part of the command, such as date +%Y%m%d. Use -t to see warnings.

Option, variable, check, debug check, compliance check, and restart names may not be redefined. A compliance check may share a name with a check or debug check.

Checks, debug checks, and compliance checks starting with perl: are perl checks, run in process. See PERL CHECKS.

EXAMPLE CONFIG

env PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
# this is a comment
GEOM_DEV=foo
geom_foo|/usr/local/libexec/nagios/check_geom mirror %GEOM_DEV%
does_not_exist|/bin/this_will_error yup... that it will

does_not_exist_2|/usr/bin/env /bin/this_will_also_error

#includes route info
%routes|netstat -rn

php_check|/usr/local/libexec/nagios/check_procs -C php-fpm -c 1:
@php_fpm|checks=php_check|/usr/sbin/service php_fpm restart

The first line sets the environment variable PATH.

The second is ignored as it is a comment.

The third sets the variable GEOM_DEV to 'foo'.

The fourth creates a check named geom_foo that calls check_geom with the value of the variable GEOM_DEV.

The fifth is an example of a check that calls a file that does not exist.

The sixth line is ignored as it is blank.

The seventh is an example of another command erroring.

The eighth is ignored as it is blank.

The ninth is ignored as it is a comment.

The tenth creates a debug check named routes.

The eleventh is ignored as it is blank.

The twelfth creates a check named php_check.

The thirteenth creates a restart named php_fpm that runs the command when php_check is critical, if restarts are enabled.

When it is run, errors for the fifth and seventh lines are printed to STDERR. For this reason, use 2> /dev/null when calling it from snmpd or 2> /dev/null > /dev/null when calling it from cron.

YAML CONFIG

YAML configs need YAML::XS, which is optional and only loaded when a YAML config is used.

env:
  PATH: /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
vars:
  GEOM_DEV: foo
checks:
  geom_foo: /usr/local/libexec/nagios/check_geom mirror %GEOM_DEV%
  does_not_exist: /bin/this_will_error yup... that it will
  php_check: '/usr/local/libexec/nagios/check_procs -C php-fpm -c 1:'
debugs:
  routes: netstat -rn
restarts:
  php_fpm:
    command: /usr/sbin/service php_fpm restart
    checks: [php_check]

Any other top level key is an error. Any section may be left out or empty. An empty file is a valid config with nothing in it.

Names, variables, and undefined variable warnings work the same as the sneck format. Errors and warnings point to a path, such as checks.geom_foo, as YAML::XS does not give line numbers.

Values must be strings or numbers. An empty value is an empty string for env and vars and an error for checks and debugs.

Some things to watch for.

OPTIONS

Options are settings for sneck itself. Flags override them.

Any other option is an error.

$cache_file=/var/db/sneck/sneck.cache
$pid_dir=/var/run/sneck
$locking=1
$check_timeout=60
$check_timeout_signal=TERM
options:
  cache_file: /var/db/sneck/sneck.cache
  pid_dir: /var/run/sneck
  locking: true
  check_timeout: 60
  check_timeout_signal: TERM

COMPLIANCE

A compliance check is a nagios style check for how a system is set up, such as root logins being off or a file having the right mode, rather than if something is working. They run the same as checks, but are counted separately and set .data.compliance_alert instead of .data.alert. Set the compliance_alert option to have them set .data.alert as well.

!ssh_no_root|control=CIS-5.2.10 framework=CIS severity=high|sshd -T | grep -qi '^permitrootlogin no$'
!pkg_vulns|control=VULN-1 severity=high interval=86400 timeout=300|/usr/local/libexec/nagios/check_pkg_audit
!telnet_off|control=CIS-2.2.18 framework=CIS waived_until=2026-12-31 waiver="legacy box, ticket 1234"|/usr/local/libexec/sneck/check_telnet_off
compliance:
  ssh_no_root:
    command: sshd -T | grep -qi '^permitrootlogin no$'
    control: CIS-5.2.10
    framework: CIS
    severity: high
  pkg_vulns:
    command: /usr/local/libexec/nagios/check_pkg_audit
    control: VULN-1
    severity: high
    interval: 86400
    timeout: 300
  telnet_off:
    command: /usr/local/libexec/sneck/check_telnet_off
    control: CIS-2.2.18
    framework: CIS
    waived_until: 2026-12-31
    waiver: legacy box, ticket 1234

All options are optional.

Restarts can't watch compliance checks.

State for interval is kept in the cache file name with .compliance added, so by default /var/cache/sneck.cache.compliance. It is only used if a compliance check has a interval.

PERL CHECKS

A check, debug check, or compliance check in the form perl:$name $args runs the check $name from Monitoring::Sneck::Checks inside of sneck, instead of starting a program for it. Each is a module, such as Monitoring::Sneck::Checks::http, whose POD lists its args.

www|perl:http -H www.example.org -S -w 1 -c 2
www_cert|perl:https_cert -H www.example.org -w 30 -c 14
!hosts_file|control=LOCAL-1|perl:hosts -e db.example.org=%DB_IP%

Variables are put in place first, then the args are split as a shell would, so quote args with spaces in them.

The name must be a-z, 0-9, and _, starting with a letter, which is checked along with the args having balanced quotes when the config is read. Whether the check is there is only known when it is run.

The exit is what the check returns, as for any other command, with two differences. A exit of -1, which is errored, means the check, or Monitoring::Sneck::Checks, could not be loaded, such as it not being installed or the name being base. Running past check_timeout, or the timeout of a compliance check, is UNKNOWN, a exit of 3, as nothing is forked to be killed. Each check passes the timeout on to what it talks to the network through, so this is rare. check_timeout_signal and check_kill_sub_pids do not apply.

Monitoring::Sneck::Checks is optional and only loaded once a perl check is run.

Restarts can't be perl checks, as they are commands to run, not checks. A restart command starting with perl: is a error. Restarts may watch perl checks though, and check_restart reruns them in process.

RESTARTS

A restart is a command run when enough of the checks it watches fail. They only run with -r. Otherwise they are just reported.

The command can't be a perl check. See PERL CHECKS.

http_check|/usr/local/libexec/nagios/check_http -H localhost
php_check|/usr/local/libexec/nagios/check_procs -C php-fpm -c 1:
@php_fpm|checks=php_check|/usr/sbin/service php_fpm restart
@httpd|checks=http_check,php_check threshold=2 depends=php_fpm cascade=1 timeout=60|/usr/sbin/service apache24 restart
restarts:
  php_fpm:
    command: /usr/sbin/service php_fpm restart
    checks: [php_check]
  httpd:
    command: /usr/sbin/service apache24 restart
    checks: [http_check, php_check]
    threshold: 2
    depends: [php_fpm]
    cascade: true
    timeout: 60

Critical always counts as failed. Ok and warning never do.

The 0/1 options also take true and false in YAML.

Restart commands get variables put in place the same as checks. A restart does not wait for its output to be closed once its command has exited, so a daemon started by it holding stdout open is fine.

The command is also given the environment variables below, describing why it is running.

@php_fpm|checks=php_check timeout=60 timeout_signal=TERM check_restart=1|/usr/sbin/service php_fpm restart
@php_fpm|checks=php_check not_every="* 2-3 * * 0"|/usr/sbin/service php_fpm restart
restarts:
  php_fpm:
    command: /usr/sbin/service php_fpm restart
    checks: [php_check]
    timeout: 60
    timeout_signal: TERM
    check_restart: true
    not_every: '* 2-3 * * 0'

The last two never restart between 02:00 and 03:59 on Sundays.

A restart that ran and failed sets .data.alert and adds a line to .data.alertString, along with any output from the command.

USAGE

snmpd just needs to print the cache. The simplest way is to cat the GZip+BASE64 compressed cache, which avoids starting perl at all.

extend sneck /bin/cat /var/cache/sneck.cache.snmp

sneck -c may be used instead. It reports a missing cache file as error JSON instead of printing nothing, but has to start perl and read the config on each poll.

extend sneck /usr/bin/env PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin /usr/local/bin/sneck -c

If the cache file is changed via cache_file or -C, cat its .snmp file instead, or give -c the same -C.

Then just setup a entry in like cron such as below.

*/5 * * * * /usr/bin/env PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin /usr/local/bin/sneck -u 2> /dev/null > /dev/null

Most likely want to run it once per polling interval.

You can use it in a non-cached manner with out cron, but this will result in a longer polling time for LibreNMS or the like when it queries it.

RETURN HASH/JSON

The generated JSON/hash is as below in jpath notation.

For the following $name is the name of the check ran.

For the following $name is the name of the debug check ran. Debug checks are run the same as checks, including check_timeout, check_timeout_signal, and check_kill_sub_pids.

For the following $name is the name of the compliance check. They are run the same as checks, except timeout may override check_timeout.

For the following $name is the name of the restart. Every restart has an entry, even when restarts are disabled.

The rest are only present if it ran.

A restart that ran and failed, including timing out or its checks still failing with check_restart, sets .data.alert and adds a line to .data.alertString along with any output from the command. Check results, counts, and .data.alertString reflect any checks rerun by check_restart.

INSTALLING

FreeBSD

pkg install p5-JSON p5-JSON-XS p5-File-Slurp p5-Proc-PID-File p5-DateTime-Event-Cron p5-App-cpanminus
cpanm Monitoring::Sneck

Debian

apt-get install libjson-perl libjson-xs-perl libfile-slurp-perl libproc-pid-file-perl libdatetime-event-cron-perl cpanminus
cpanm Monitoring::Sneck

YAML Support

For YAML configs, also install YAML::XS.

# FreeBSD
pkg install p5-YAML-LibYAML

# Debian
apt-get install libyaml-libyaml-perl

Perl Checks

For perl: checks, run in process instead of as a program, also install Monitoring::Sneck::Checks. See PERL CHECKS.

www|perl:http -H www.example.org -S -w 1 -c 2

From Source

perl Makefile.PL
make
make test
make install