Implementing threshold checks in a plugin

You'll note that many of the plugins included in the Nagios Plugins set allow you to specify thresholds for different aspects of the tests that they perform, allowing custom configuration of which levels are ok, which need a warning, and which are critical. For example, the check_ping plugin requires us to specify thresholds with -w and -c options that define limits for round-trip-time and packet loss:

$ /usr/local/nagios/libexec/check_ping -H -w 100,20% -c 200,40%
PING OK - Packet loss = 0%, RTA=0.20 ms|rta=0.200000ms;100.000000;100.000000;0.000000 pl=0%;10;20;0

In this case, the plugin's options are set only to raise a WARNING state if the round-trip-time for the check exceeds 100 milliseconds ...

Get Nagios Core Administration Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.