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

Nested Class Summary
protected  class PluginBase.Logger
          This class represent a generic logger that will be used by plugins extending the PluginBase to write logs.
 
Field Summary
protected  PluginBase.Logger log
          The logger object.
 
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.
protected  Set<IJNRPEEventListener> getListeners()
          Returns all the registered listeners.
protected abstract  String getPluginName()
           
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final PluginBase.Logger log
The logger object.

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.

getPluginName

protected abstract String getPluginName()
Returns:
the friendly name of this plugins.

getListeners

protected final Set<IJNRPEEventListener> getListeners()
Returns all the registered listeners.

Returns:
All the listeners

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.