Note: Beginning at version 1.0.3, this feature is still beta.
The Functions part is stable and can be used. The API part is still under development.
The API is a PHP file and class which can be use to:
- Host functions that can be used in rule evaluation
- (not implemented) get all trap data from a trap and return a status (OK/WARN/CRIT/UNKNOWN)
- (not implemented) catch all traps and return a status and a host/hostgroup.
To create a new plugin named MyPlugin
:
- Create a file in
library\Trapdirector\Plugins
and call itMyPlugin.php
- In this file, create a class derived from PluginTemplate:
class MyPlugin extends PluginTemplate
See the NetworkRule.php
file for an example.
You must ACTIVATE the plugin (see below).
(More doc when implemented)
Functions are freely added to a plugin (you don't need to create a new plugin just to add one function)
Add the function parameters in the plugin->functions array:
$functions[name]['function']
: Name of the function to be called in this class$functions[name]['params']
: Description of input parameters of the function.$functions[name]['description']
: Description. Can be multiline.
Create a new function in the plugin class:
public function functionName(array $params) : bool
where:
functionName
=$functions[name]['function']
$params
= params passed by rule. The function MUST check params and throw an exception on error.- return an evaluation as a boolean
class NetworkRule extends PluginTemplate
{
public $functions=array(
'inNetwork' => array( // The name of the function in rules
'function' => 'isInNetwork', // Name of the function
'params' => '<IP to test>,<Network IP>,<Network mask (CIDR)>', // parameters description
'description' => 'Test if IP is in network, example: __inNetwork(192.168.123.5,192.168.123.0,24) returns true
Does not work with IPv6' // Description (can be multiline).
),
[... other functions...}
);
Note: You can setup parameters in the plugin construct method.
public function isInNetwork(array $params) : bool
{
// Check param numbers and thrown exception if not correct.
if (count($params)!=3)
{
throw new Exception('Invalid number of parameters: ' . count($params));
}
....
return true or false
}
After activation of the plugin, you can use the function in a rule.
In a rule handler, if for example you have an OID which gives an IP (here $1$
), and another oid (here $2$
), the rule would be like:
__inNetwork($1$,192.168.123.0,24) & ( $2$ = 1)
To activate a plugin, go to Status & Mibs -> Plugins Management and click the "Enabled" checkbox next to the plugin you want to activate.
Go back to the user guide.