Cron – Best way to verify that a cronjob executed with Nagios notification on failure

cronnagios

I have a cron job that runs every morning that produces an output file when run successfully. I'd like to have a follow up process that verifies that the job executed properly or fire off a Nagios alert if it didn't.

I feel like I could make this work with a Nagios check_file_age service check that restricts the check to occur only once every morning through careful construction of the check_interval and check_period in the service def, but I'm wondering if there is a simpler way?

Best Answer

A couple of options spring to mind:

  1. Use passive check results to have the verification script tell Nagios to go alert, and if you want to know if the verification script doesn't run, then set a freshness interval of a little over 24 hours and have an active check command that always goes critical; or
  2. Have the cron job itself submit an OK passive check result when it finishes successfully, but not do anything when it fails. Then, again, freshness check with an auto-critical active check command to alert when all is not well.