Package: check-json
check_jsonCheck_json is aNagios/Icinga2plugin for monitoring JSON files withJqfilters.Requires Python 3.6+InstallationYou can install withpip:python3-mpipinstallcheck-jsonOr install from source:gitclonehttps://gitlab.com/cspeterson/check_json.gitcheck_json.git
pipinstallcheck_json.gitUsagePass the plugin any number of Jq filters (with thresholds) and a JSON file.Essentially, any valid Jq filter you can formulate which returns a numerical value for comparison against its thresholds will work.The plugin will test the result of each filter against its thresholds and report accordingly.# usage: check_json [-h] [--filter LABEL FILTER THRESHOLDS] [--verbose] jsonfilecheck_json--filter'LABEL1''FILTER1''wRANGE,cRANGE'--filter'LABEL2''FILTER2''wRANGE,cRANGE'/path/to/jsonfileFor example, this will warn if the value ofkeyis more than 10, and will crit if it is more than 20:check_json--filter'my_label''.key''w~:10,c~:20'Or to report numerical{1,0}for perfdata if a string is present:check_json--filter'my_label''if .key == "some_string" then 1 else 0 end''w10,c20'For more on Jq filters, refer to theJQ Manualfor for your version of libjq.For more on Nagios plugin ranges, thresholds, perfdata, and return codes, seeNagios Plugin Development Guidelines.Icinga2Here is an Icinga2CheckCommandobject for this plugin:object CheckCommand "check_json" {
  command = [ PluginDir + "/check_json", ]
  arguments = {
    # It appears the only way to get Icinga to repeat a particular key *and*
    # pass it multiple separate arguments is to define it multiple times (as
    # below), give them all the same key, and just increment the number for
    # each subsequent usage of the key ¯\_(ツ)_/¯
    "--filter" = {
      description = "Defines a filter, its name, and thresholds."
      key = "--filter"
      repeat_key = false
      value = "$check_json_filter$"
    }
    "--filter0" = {
      description = "Defines a filter, its name, and thresholds."
      key = "--filter"
      repeat_key = false
      value = "$check_json_filter0$"
    }
    "--filter1" = {
      description = "Defines a filter, its name, and thresholds."
      key = "--filter"
      repeat_key = false
      value = "$check_json_filter1$"
    }
    "--filter2" = {
      description = "Defines a filter, its name, and thresholds."
      key = "--filter"
      repeat_key = false
      value = "$check_json_filter2$"
    }
    "--filter3" = {
      description = "Defines a filter, its name, and thresholds."
      key = "--filter"
      repeat_key = false
      value = "$check_json_filter3$"
    }
    "--filter4" = {
      description = "Defines a filter, its name, and thresholds."
      key = "--filter"
      repeat_key = false
      value = "$check_json_filter4$"
    }
    "--filter5" = {
      description = "Defines a filter, its name, and thresholds."
      key = "--filter"
      repeat_key = false
      value = "$check_json_filter5$"
    }
    "--filter6" = {
      description = "Defines a filter, its name, and thresholds."
      key = "--filter"
      repeat_key = false
      value = "$check_json_filter6$"
    }
    jsonfile = {
      description = "The path to the file to inspect"
      required = true
      skip_key = true
      value = "$check_json_jsonfile$"
    }
  }
}And a minimal example Icinga Service:object Service "host.domain.tld_check" {
  import "generic-service"
  display_name = "Jq JSON filter"
  host_name = "host.domain.tld"
  check_command = "check_json"
  command_endpoint = "host.domain.tld"
  notes = "The `check_json` command is a custom plugin to run Jq filters against JSON files."
  notes_url = "https://gitlab.com/cspeterson/check_json"

  vars.check_json_filter = ["mylabel1". ".somefilter1", "w@0"]
  vars.check_json_filter2 = ["mylabel2". ".somefilter2", "w@0"]
  vars.check_json_jsonfile = "/path/to/file.json"
}NOTE on the command path: the above Icinga2 configuration object points to thecheck_jsoncommand in Icinga2's configuredPluginDir, but this can be configured however you like. For instance:point it to wherever it is installed by its full pathsymlink from the specified path to the actual script.or take the kludge route, leave it as-is, and copycheck_json/__main__.pyfrom this repo intoPluginDir + "/check_json"Up to you!LimitationsWhat this plugin isnotfor:Exceptionally huge JSON files - this plugin loads the entire JSON file into memory.Keeping place in a log file over time. For that (though with admittedly simpler pattern matching), seecheck_logfiles.ContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.To run the test suite:# Up to you to create virtual environments etc# make dependenciesmakePlease make sure to update tests as appropriate.LicenseMIT