check-diff

command module
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

check-diff

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.

Installation

Download the latest binary from the releases page, or install it with the Mackerel CLI:

mkr plugin install monitoring-forge/check-diff

Usage

% ./check-diff -h
Usage:
  check-diff [OPTIONS] -- command args1 args2

Application Options:
  -w, --warn        Set the error level to warning
      --invert      Alert when there is no difference instead of when there is a difference
      --identifier= Identify the file used to store the command result with the given string
      --workdir=    Set the working directory
  -j, --json        Calculate the diff treating the command output as JSON
      --json-ignore= jq query to ignore structures in the JSON output
  -v, --version     Show version

Help Options:
  -h, --help        Show this help message
Basic usage

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/file
First run

On 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'
Detecting differences

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

Options

-w, --warn

Report alerts as WARNING instead of CRITICAL.

./check-diff -w -- cat /path/to/file
--invert

Report CRITICAL when the output is unchanged and OK when it differs. Use -w to report WARNING instead of CRITICAL. The first run still returns OK, and errors are still reported as CRITICAL.

./check-diff --invert -- cat /path/to/file
--identifier

Use 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/passwd
--workdir

Change 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/passwd
-j, --json

Calculate the diff treating the command output as JSON. The output is normalized to sorted, compact JSON before comparison, so differences in formatting or key order are ignored.

./check-diff -j -- cat /path/to/file.json
--json-ignore

Specify a jq query to ignore parts of the JSON structure when comparing. Only values selected by the query are excluded from the diff; the rest of the output is still compared as JSON. This option requires --json.

./check-diff -j --json-ignore='.timestamp' -- some-json-command

Mackerel configuration example

Add 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"

License

See LICENSE.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址