0

When a Nagios host object is added to multiple host templates (each with a different timeperiod assigned) Nagios only seems to select the first template in that use list.

Can you give a host a different check_interval based on what time it is?

  • The description about adding a host to multiple host templates seems (to me!) to be an aside here; it doesn't seem related to the title or the question in your Question. Could you replace it with some more background on what you're trying to do? Also, I might be out of date, but I didn't think Nagios did host health checks unless a service on it failed. Are you asking about scheduling service health checks or host health checks? – Jeff Schaller Oct 29 '19 at 13:43
  • Thanks for querying this Jeff. I am trying to apply less frequent host check in the evenings while applying more frequent host checks in the afternoon. – Pete Oct 29 '19 at 23:33
  • I can't test at the moment, but one idea to consider would be to define a custom check_command for the host(s) that checks the time of day; it would have to assume a certain check_interval. Based on the time of day, it could either return zero/success (without checking) or run the actual check. – Jeff Schaller Oct 30 '19 at 0:47
  • Just to clarify, are you thinking along the lines of creating custom fields such as described here? – Pete Nov 1 '19 at 20:30
0

When a Nagios host object is added to multiple host templates (each with a different timeperiod assigned) Nagios only seems to select the first template in that use list.

A host object is not "added to" a template, rather that template is read and applied to the host object, merging any settings unless they are "locally" overridden by the object itself (or another template). Values cannot be changed during runtime.

Can you give a host a different check_interval based on what time it is?

This is a typical XY problem. Don't assume that what you describe is the correct way of doing it, instead explain what your fundamental issue is that you want to resolve. Why do you want to run checks less often during certain periods? This is not a common usage of Nagios, so please start by explaining what actual problem are you trying to resolve -- there is likely a better way to do it.

0

Can you give a host a different check_interval based on what time it is?

No. A host (ends up with, through any template inheritance) one check_interval and check_period.

I am trying to apply less frequent host check in the evenings while applying more frequent host checks in the afternoon.

I would not recommend doing this. Nagios checks the status of a host:

  • At regular intervals, as defined by the check_interval and retry_interval options in your host definitions.
  • On-demand when a service associated with the host changes state.
  • On-demand as needed as part of the host reachability logic.
  • On-demand as needed for predictive host dependency checks.

The only one under your control is the regularly-scheduled check, via the check_interval and retry_interval. The check_command runs at the check_interval, so you could create a custom check_command for that host or hosts which then checks the time of day to decide whether to run (and what to do if it decides not to run? Return "UNKNOWN"?), but you don't want that host check to be skipped (or have it return bogus data) for the other instances where Nagios might want to check the host.

I'm not sure why you'd want to check less often, since the check_command is usually just a ping. If the ping traffic is causing concerns in the evening hours for some other reason, that's perhaps a different problem to solve. If you don't want host alerts off-hours, you can define a downtime window or set up a custom notification_period for the host. Note that both downtime windows and custom notification periods might also inhibit service alerts on that host.

If you really, really want to, you could externally schedule a manual configuration-file change; for example, a sed script that changes the check_interval for the host(s), or one that copies in a "daytime" hosts.cfg vs an "evening" hosts.cfg, and then reloads Nagios.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.