This gem provides a Logger-like interface to Nagios plugin output. It allows you to "write" Nagios plugin output messages, including long output, using the Logger interface. It also provides additional methods to record perfdata.
This is unlike many Nagios helper modules, in that it doesn't help you run or interpret your check. It doesn't parse command-line arguments, determine critical or warning thresholds automatically or work declaratively. What it does do is enable you to turn many things using a standard Logger class into a Nagios plugin, and use a Logger style to create a Nagios plugin with a minimum of Nagios-isms.
The exit status of your plugin will be set by Logger::Nagios using the Kernel#at_exit call. You don't need to do anything special. The status (and output) will always be the "worst" of any Logger::Nagios objects created.
If your plugin exits unexpectedly due to an exception, the first plugin's output will be used and the exit code will be set to UNKNOWN.
- ::
Logger::Nagios.new(servicename, options={})
Creates a new Logger::Nagios object with the given Nagios service name. The plugin always produces Nagios-compatible output of the form:
service status - summary|perfdata
long output
The long output is derived from all the log messages passed to the object. The service is the name of the service as given to the logger, the status is a string representation of the Nagios service status (OK, WARNING, CRITICAL, UNKNOWN), the summary is the plugin summary string (given as the last message logged that is info or higher and equal to or higher than the logger level; or given as an argument to close(), or assigned to the summary attribute).
The perfdata is provided using the add_perfdata method.
The initial status of the plugin is UNKNOWN, i.e., something must be logged in order to make the status meaningful.
This determines which messages are added to a plugin's long output. Messages logged at this level or above are added, messages below this threshold are not.
Mostly a no-op, but if an argument is given, sets the summary line to it.
Logs a message at the DEBUG level and leaves the status and summary alone.
Logs a message at the ERROR level, replaces the summary with the message, and updates the plugin status to CRITICAL.
Logs a message at the FATAL level, replaces the summary with the message, and updates the plugin status to CRITICAL.
Logs a message at the INFO level, replaces the summary with the message if level is INFO or lower, and updates the plugin status to OK if it is UNKNOWN.
Logs a message at the appropriate level, following the logic described in the method for that level. Synonym for add.
Logs a message unconditionally, replaces the summary with the message, and updates the plugin status to UNKNOWN. This is also what happens when the plugin exits unexpectedly. Synonym for <<.
Logs a message at the WARN level, replaces the summary with the message if level is WARN or lower, and updates the plugin status to WARNING if is not CRITICAL.
The methods debug?, info?, warn?, error? and fatal? can be used to query whether a given level is to be logged in the plugin's long output.
The numeric Nagios plugin status (assignable).
The current summary line (assignable).
Add a perfdata item:
add_perfdata(label, value, tags={})
Add a labeled perfdata item. Optional tags include:
- unit
The unit of the value
- warn
The warning level of the value
- crit
The critical level of the value
- min
The minimum possible value
- max
The maximum possible value
Performance data is given in nagios plugins format.
Return just the perfdata portion of output.
Return plugin output (this happens automatically upon exit).