Ceci est une ancienne révision du document !
Table des matières
Plugin developer guide
Zabbix Report
This guide is aimed at moodle plugins developpers that want implement Zabbix Report compatibility so the plugin can be discovered by the Zabbix Report and have indicators emission handled by the sending tasks.
Note that only the Pro version of the Zabbix Report plugin with a valid license key will support this integration. Free releases of the report plugin will not provide this extension capability.
Plugin registration method
The plugin can be registrated within the Zabbix Report among two scenarios:
- The third-party plugin is installed AFTER the Zabbix Report has been installed.
- The third parry-plugin is installed BEFORE the Zabbix Report plugin.
Note : note that if you install a complete moodle preequiped with third-party plugins, then both cases might happen depending on the pluginlist order.
Registration function in lib.php
You will add to your main lib.php file the following function:
/**
* This function is a "late" callback, when zabbix report
* is installed AFTER this plugin has been installed. It is called
* by the Zabbix Report installer to register all compatible plugins.
*/
function <plugin_frankenname>_zabbix_register() {
global $CFG;
if (is_dir($CFG->dirroot.'/report/zabbix')) {
include_once($CFG->dirroot.'/report/zabbix/xlib.php');
report_zabbix_register_plugin('<plugintype>', '<pluginname>');
}
}
Handling post installation case
If the Zabbix report plugin is already installed, it will not scan for your third-party plugin, but the third-party plugin will use it's post install sequence to do so.
In your db/install.php post install file, add the following;
function xmldb_<plugin_frankenname>_after_install() {
[...]
// Register zabbix indicators if installed.
// Note will only work with report_zabbix "pro" version.
// This call is only a wrapper.
if (is_dir($CFG->dirroot.'/report/zabbix')) {
include_once($CFG->dirroot.'/<pluginpath>/lib.php'); // If not yet done.
learningtimecheck_zabbix_register();
}
[...]
}
This function will reuse the thrird-party registering callback at install time.
Defining indicators
Create a indicators directory in your classes plugin's subdirectory.
Depending on how often you want to send data to Zabbix, you will adopt the following rules :
- Sending each cron run : create indicator classes directly in
classes/indicators(whatever name they have). - Sending hourly values : create a
hourlydirectory inindicatorsand implement your indicator classes there. - Sending daily values : same as above, in a
dailydirectory. - Sending weekly values : same as above creating a
weeklydirectory. - Sending monthly values : … no worth explaining how, uh ?
Implementing indicator class
An indicator class is a class in the report_zabbix\indicators namespace, even if located in your plugin. It has a unique parent class:
namespace report_zabbix\indicators;
use moodle_exception; // If needed
use coding_exception; // If needed
use StdClass; // If needed, usually it is.
require_once($CFG->dirroot.'/report/zabbix/classes/indicator.class.php');
class daily_<indicatorset>_indicators extends zabbix_indicator {
[...]
}
Note that the php file must:
- Have one single indicatorset class
- be named as the class i.e. : daily_<indicatorset>_indicators
The indicator class can send one or several values, called “submodes” of the main indcatorset. It will be usually the case, so we start immediatly with this use case.
Back to Zabbix Report index - Back to plugin index - Back to catalog
