it.jnrpe.plugins
Class PluginBase

java.lang.Object
  extended by it.jnrpe.plugins.PluginBase
All Implemented Interfaces:
IPluginInterface, IPluginInterfaceEx
Direct Known Subclasses:
PluginProxy

public abstract class PluginBase
extends Object
implements IPluginInterfaceEx

This class facilitates the implementation of plugins. If you don't need to extend other classes, than extending PluginBase is the best way. This class gives you out of the box:

Author:
Massimiliano Ziccardi

Constructor Summary
PluginBase()
           
 
Method Summary
 void addListener(IJNRPEEventListener listener)
          Adds a new listener to the list of objects that will receive the messages sent by this class.
 void addListeners(Collection<IJNRPEEventListener> listeners)
          Adds a new collection of listeners.
 void configureThresholdEvaluatorBuilder(ThresholdsEvaluatorBuilder thrb, ICommandLine cl)
          Override this method if you don't use the new threshold syntax.
 ReturnValue execute(ICommandLine cl)
          Executes the plugin.
 Collection<Metric> gatherMetrics(ICommandLine cl)
          This method must be overridden if you don't override the execute(ICommandLine) method.
 void sendEvent(LogEvent evt, String message)
          Sends an event.
 void sendEvent(LogEvent evt, String message, Exception exc)
          Sends an event.
 void sendEvent(String customEventName, EventParam... paramsAry)
          Sends a custom event.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PluginBase

public PluginBase()
Method Detail

addListener

public final void addListener(IJNRPEEventListener listener)
Adds a new listener to the list of objects that will receive the messages sent by this class.

Specified by:
addListener in interface IPluginInterfaceEx
Parameters:
listener - The new listener

addListeners

public final void addListeners(Collection<IJNRPEEventListener> listeners)
Adds a new collection of listeners.

Specified by:
addListeners in interface IPluginInterfaceEx
Parameters:
listeners - The collection of listeners to be added

sendEvent

public final void sendEvent(LogEvent evt,
                            String message)
Sends an event.

Parameters:
evt - The event type
message - The message

sendEvent

public final void sendEvent(LogEvent evt,
                            String message,
                            Exception exc)
Sends an event.

Parameters:
evt - The event type
message - The message
exc - The exception to be attached to the event

sendEvent

public final void sendEvent(String customEventName,
                            EventParam... paramsAry)
Sends a custom event.

Parameters:
customEventName - The custom event identifier
paramsAry - The parameter of the event. Can be null.

configureThresholdEvaluatorBuilder

public void configureThresholdEvaluatorBuilder(ThresholdsEvaluatorBuilder thrb,
                                               ICommandLine cl)
                                        throws BadThresholdException
Override this method if you don't use the new threshold syntax. Here you must tell the threshold evaluator all the threshold it must be able to evaluate. Give a look at the source of the CheckOracle plugin for an example of a plugin that supports both old and new syntax.

Parameters:
thrb - The ThresholdsEvaluatorBuilder object to be configured
cl - The command line
Throws:
BadThresholdException - -

gatherMetrics

public Collection<Metric> gatherMetrics(ICommandLine cl)
                                 throws MetricGatheringException
This method must be overridden if you don't override the execute(ICommandLine) method. This way you can demand all the work about evaluating the thresholds to this class.

Parameters:
cl - The command line.
Returns:
All the collected metrics
Throws:
MetricGatheringException - -

execute

public ReturnValue execute(ICommandLine cl)
                    throws BadThresholdException
Executes the plugin. You must override this method if you want total control about what the plugins does. Most of the times, however, you'll want to override the gatherMetrics(ICommandLine) instead.

Specified by:
execute in interface IPluginInterface
Parameters:
cl - The command line
Returns:
The return value to be sent to Nagios.
Throws:
BadThresholdException - -


Copyright © 2014. All Rights Reserved.