report:zabbix:developerguide
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| report:zabbix:developerguide [2026/02/04 17:27] – admin | report:zabbix:developerguide [2026/02/07 19:41] (Version actuelle) – [Plugin registration method] admin | ||
|---|---|---|---|
| Ligne 36: | Ligne 36: | ||
| } | } | ||
| + | ===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 '' | ||
| + | |||
| + | | ||
| + | |||
| + | [...] | ||
| + | |||
| + | // Register zabbix indicators if installed. | ||
| + | // Note will only work with report_zabbix " | ||
| + | // This call is only a wrapper. | ||
| + | if (is_dir($CFG-> | ||
| + | | ||
| + | | ||
| + | } | ||
| + | | ||
| + | [...] | ||
| + | } | ||
| + | |||
| + | This function will reuse the thrird-party registering callback at install time. | ||
| + | |||
| + | ====Defining indicators==== | ||
| + | |||
| + | Create a '' | ||
| + | |||
| + | 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 '' | ||
| + | * Sending hourly values : create a '' | ||
| + | * Sending daily values : same as above, in a '' | ||
| + | * Sending weekly values : same as above creating a '' | ||
| + | * Sending monthly values : ... no worth explaining how, uh ? | ||
| + | |||
| + | ===Implementing indicator class=== | ||
| + | |||
| + | An indicator class is a class in the '' | ||
| + | |||
| + | | ||
| + | |||
| + | use moodle_exception; | ||
| + | use coding_exception; | ||
| + | use StdClass; // If needed, usually it is. | ||
| + | |||
| + | | ||
| + | |||
| + | class daily_< | ||
| + | [...] | ||
| + | } | ||
| + | |||
| + | Note that the php file must: | ||
| + | |||
| + | * Have one single indicatorset class | ||
| + | * be named as the class i.e. : daily_< | ||
| + | |||
| + | The indicator class can send one **or several** values, called " | ||
| + | |||
| + | Usually we name class as: | ||
| + | |||
| + | * ''< | ||
| + | * ''< | ||
| + | |||
| + | ===Describing submodes=== | ||
| + | |||
| + | Now describe your submodes as a static constant: | ||
| + | |||
| + | static $submodes = ' | ||
| + | |||
| + | Each submode is a single measurement and a single value sent to Zabbix. | ||
| + | |||
| + | ===Constructor=== | ||
| + | |||
| + | The constructor only defines the Zabbix value namespace that will be prepended to all submodes. Zabbix model will use the FQDN of the indicator values for defining items. | ||
| + | |||
| + | public function __construct() { | ||
| + | parent:: | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | ===Acquiring measures=== | ||
| + | |||
| + | Here is the most important part of the implementation. For each submode listed in the '' | ||
| + | |||
| + | /** | ||
| + | * the function that contains the logic to acquire the indicator instant value. | ||
| + | * @param string $submode to target an aquisition to an explicit submode, elsewhere | ||
| + | */ | ||
| + | public function acquire_submode($submode) { | ||
| + | global $DB; | ||
| + | |||
| + | if(!isset($this-> | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | if (is_null($submode)) { | ||
| + | $submode = $this-> | ||
| + | } | ||
| + | |||
| + | switch ($submode) { | ||
| + | |||
| + | case ' | ||
| + | |||
| + | $submodevalue = [...]; // Whatever gets a single value in Moodle. | ||
| + | |||
| + | $this-> | ||
| + | break; | ||
| + | } | ||
| + | |||
| + | default: { | ||
| + | if ($CFG-> | ||
| + | throw new coding_exception(" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Once each submode case is written, that's all done ! | ||
| ---- | ---- | ||
report/zabbix/developerguide.1770226033.txt.gz · Dernière modification : de admin
