Most of us use Icinga 2 to monitor network services, host resources or server components – but wait, there is more! Why not ask Icinga 2 to watch items in your favourite online shop and send out notifications as soon as the price has dropped below a certain amount? Antony Stone has written a slightly unusual check to track the price of Amazon items with Icinga 2.

Here is how it works:

  1. The monitoring plugin is a simple shell script (check_amazon) that accepts the Amazon product ID (Amazon Standard Identification Number, ASIN) as a mandatory parameter.
  2. Next, it uses the text-based web browser lynx to fetch the Amazon page for that item. Somewhere in the lynx-output is the information about the full name and the price of the product.
  3. Various grep commands filter the output, cut and tr remove sections and characters. As a result, the script prints the name of the item and the current price:terminal window with the check_amazon plugin output
  4. The check_amazon plugin accepts two optional parameters: -w for the warning threshold (= the price is near to what you’d like to pay for it) and -c for the critical threshold (= the price is now below the maximum price you’re prepared to pay).

We’ve copied the plugin to /opt/monitoring/plugins and made it executable (chmod +x check_amazon). In the file /etc/icinga2/constants.conf we’ve created a new global constant CustomPluginDir:

/* My own check plugins live in /opt/monitoring/plugins: */
const CustomPluginDir = "/opt/monitoring/plugins"

The new configuration file /etc/icinga2/conf.d/amazon.conf defines a host group for all Amazon items, so they all get the same check. It also contains various host objects for all the items we want to monitor. They have no address, since it’s not possible to ping Amazon items. Icinga 2 insists on having a check_command, so we’re using dummy which does nothing. For the host objects we’ve also defined a few more variables for the alert thresholds:

object HostGroup "Amazon" {
  display_name = "Amazon Items to Watch"

object Host "Bottle-o-gin" {
        check_command   = "dummy"
        groups          += [ "Amazon" ]
        vars.asin       = "B00G3Z92CI"
        vars.price1     = 20.00
        vars.price2     = 15.00

object Host "Tonic" {
        check_command   = "dummy"
        groups          += [ "Amazon" ]
        vars.asin       = "B00H2WX11E"
        vars.price1     = 25.00
        vars.price2     = 20.00


We also need to tell Icinga 2 how to run the plugin, so we’ve defined the CheckCommand like this:

object CheckCommand "check_amazon" {
        import          "plugin-check-command"
        command         = [ CustomPluginDir + "/check_amazon" ]
        arguments       = {
                "-p"    = "$host.vars.asin$"
                "-w"    = "$host.vars.price1$"
                "-c"    = "$host.vars.price2$"

Last, we define the check to run for all items in the group. We’ve applied a standard service definition (which is then linked to a command) to anything in the Amazon group:

apply Service "Price" {
        import                  "generic-service"
        assign where            "Amazon" in host.groups
        check_command           = "check_amazon"
        check_interval          = 24h
        retry_interval          = 1h
        max_check_attempts      = 3

That’s it – we’re now able to monitor the hosts (the Amazon items) and their services (the price). Got any suggestions or ideas for improvement? Drop us an email or get in touch via GitHub, Twitter, Facebook, or Google+!

Firefox showing Icinga Web 2