Page 1 of 1

Scheduling a weekly check

Posted: Mon Nov 18, 2013 6:05 pm
by cunningrat
Got a problem configuring a check: I'm not sure how to implement it.

A file arrives on the server on Friday, some time between 4 and 6 PM. What I need to do is as follows:
* Look for the file's presence. If it's not present, don't panic yet: it may arrive later.
* If the file is present, scan it for certain strings. If they're not present, panic.
* If the file isn't present by 6 PM, panic.

I can script most of the logic on the monitored server side, that's not an issue.
Running the script only on Friday between 4 and 6 PM is not an issue either, I can use the timeperiod definitions to do that.
The question is, how can I configure Nagios to keep checking, but only send out an alert if the file doesn't contain the right strings OR if it's not present by 6 PM?

One way to do it that I've thought of is to make my script that scans the file also check the time, and return a CRITICAL result if the file's not there by 6 PM. Any other ways anyone can think of?

Re: Scheduling a weekly check

Posted: Tue Nov 19, 2013 11:28 am
by sreinhardt
I would 100% agree with having the script handle all of the logic for alerting. My thought would be:

Code: Select all

if file is present { (file is present)
 are certain strings there{ (strings are present)
        echo "File is there, and strings are present"
        exit 0
  } (end strings yes)
  else { (strings are not there)
       echo "File present, strings are missing"
       exit 2
     } (end strings no)
} (end file present yes)
elseif, is past 6pm { (file is not present, is past 6)
  echo "File not present, and is past 6pm"
  exit 2
} (end file present no, and past 6)
else { (file not present, not past 6)
  echo "File not present, not past 6pm"
  exit 0
} (end file not present, not past 6) 
echo "Script did not complete correctly"
exit 3 (message and exit code for unknown in the case of script failure)
does that make sense for what you would like to do?
edit: hopefully it is clear that this is pseudo code and will not actually function. :D