Monitoring::Sneck

SYNOPSIS

sneck -u [-C <cache file>] [-f <config file>] [-p] [-i] [-d] [-q] [-l] [-r]

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

sneck [-f <config file>] [-p] [-i] [-r]

sneck -t [-f <config file>]

FLAGS

-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 it in a nicely formatted format.

-C cache_file

The cache file to use.

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.

-u

Update the cache file. Will also print the 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.

-b

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

-i

Includes the config file used.

-d

Print debugging info if called with -u.

-q

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

-l

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

-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 -l with this to make sure two runs can't restart things at the same time.

-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.

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.

Variable, check, debug check, and restart names may not be redefined.

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

The first line sets the %ENV 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_mirror with the variable supplied to it being the value specified by the variable GEOM_DEV.

The fith is a example of an error that will show what will happen when you call to a file that does not exit.

The sixth line will be ignored as it is blank.

The seventh is a example of another command erroring.

When you run it, you will notice that errors for lines 4 and 5 are printed to STDERR. For this reason you should use '2> /dev/null' when calling it from snmpd or '2> /dev/null > /dev/null' when calling 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
debugs:
  routes: netstat -rn

Any other top level key is an error. Any section may be left out or empty.

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.

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.

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.

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 should be configured as below.

extend sneck /usr/bin/env PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin /usr/local/bin/sneck -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.

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

INSTALLING

FreeBSD

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

Debian

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

YAML Support

For YAML configs, also install YAML::XS.

# FreeBSD
pkg install p5-YAML-LibYAML

# Debian
apt-get install libyaml-libyaml-perl

From Src

perl Makefile.PL
make
make test
make install