check-diff is a Mackerel check plugin that detects changes in the output of a command by comparing it with the previous execution.
This is a rewrite of kazeburo/diff-detector with the same functionality.
Download the latest binary from the releases page, or install it with the Mackerel CLI:
mkr plugin install monitoring-forge/check-diff% ./check-diff -h
Usage:
check-diff [OPTIONS] -- command args1 args2
Application Options:
-w, --warn Set the error level to warning
--identifier= Identify the file used to store the command result with the given string
--workdir= Set the working directory
-v, --version Show version
Help Options:
-h, --help Show this help message
Place -- between options and the command to run. The plugin executes the command, compares its output with the previous run, and reports the result.
./check-diff -- cat /path/to/fileOn the first execution, check-diff stores the command output and returns OK because there is nothing to compare with.
% ./check-diff -- cat date.txt
check-diff OK: first time execution command: 'cat date.txt'On subsequent runs, check-diff compares the current output with the stored output. If the output is unchanged, it returns OK; otherwise, it returns CRITICAL (or WARNING if -w is used).
% echo "Wed Aug 12 00:39:23 JST 2020" > date.txt
% ./check-diff -- cat date.txt
check-diff OK: no difference: ```Wed Aug 12 00:39:23 JST 2020```
% echo "Wed Aug 12 00:39:40 JST 2020" > date.txt
% ./check-diff -- cat date.txt
check-diff CRITICAL: found difference: ```@@ -1 +1 @@
-Wed Aug 12 00:39:23 JST 2020
+Wed Aug 12 00:39:40 JST 2020```Report differences as WARNING instead of CRITICAL.
./check-diff -w -- cat /path/to/fileUse a custom identifier for the file that stores the command result. This is useful when you want to run the same command multiple times with different identities.
./check-diff --identifier=production -- cat /etc/passwd
./check-diff --identifier=staging -- cat /etc/passwdChange the directory where the previous output is stored. By default, the plugin uses Mackerel's plugin working directory.
./check-diff --workdir=/var/lib/check-diff -- cat /etc/passwdAdd entries to mackerel-agent.conf to monitor file or command output changes:
[plugin.checks.uname-changed]
command = "/usr/local/bin/check-diff -- uname -a"
[plugin.checks.passwd-changed]
command = "/usr/local/bin/check-diff -- cat /etc/passwd"See LICENSE.