Outils pour utilisateurs

Outils du site


report:zabbix:developerguide

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
report:zabbix:developerguide [2026/02/04 17:42] – [Plugin registration method] adminreport:zabbix:developerguide [2026/04/23 10:29] (Version actuelle) florence
Ligne 1: Ligne 1:
-<html><!-- nomoodle --></html>{{ :blocks:logo-apl.png? nolink |}}<html><!-- /nomoodle --></html>+ 
 +<html><!-- nomoodle --></html>{{:report:logo-apl-transparent.png?400|}}<html><!-- /nomoodle --></html>
  
  
Ligne 43: Ligne 44:
  
    function xmldb_<plugin_frankenname>_after_install() {    function xmldb_<plugin_frankenname>_after_install() {
 +   
        [...]        [...]
 +   
        // Register zabbix indicators if installed.        // Register zabbix indicators if installed.
        // Note will only work with report_zabbix "pro" version.        // Note will only work with report_zabbix "pro" version.
Ligne 61: Ligne 62:
 ====Defining indicators==== ====Defining indicators====
  
-Create a ''indicators'' directory in your ''classes'' plugon(s subdirectory. +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 : 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 each cron run : create indicator classes directly in ''classes/indicators'' (whatever name they have).
-   * Sending hourly values : create a ''hourly'' directory in ''indicators' and implement your indicator classes there.+   * Sending hourly values : create a ''hourly'' directory in ''indicators'' and implement your indicator classes there.
    * Sending daily values : same as above, in a ''daily'' directory.    * Sending daily values : same as above, in a ''daily'' directory.
    * Sending weekly values : same as above creating a ''weekly'' directory.    * Sending weekly values : same as above creating a ''weekly'' directory.
Ligne 77: Ligne 78:
    namespace report_zabbix\indicators;    namespace report_zabbix\indicators;
        
-   use moodle_exception; +   use moodle_exception; // If needed 
-   use coding_exception; +   use coding_exception; // If needed 
-   use StdClass;+   use StdClass; // If needed, usually it is.
        
    require_once($CFG->dirroot.'/report/zabbix/classes/indicator.class.php');    require_once($CFG->dirroot.'/report/zabbix/classes/indicator.class.php');
        
    class daily_<indicatorset>_indicators extends zabbix_indicator {    class daily_<indicatorset>_indicators extends zabbix_indicator {
-      [...]+       [...]
    }    }
  
Ligne 94: Ligne 95:
 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. 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.
  
-----+Usually we name class as: 
 + 
 +   * ''<indicatorset>_indicators'' for full range values. 
 +   * ''<range>_<indicatorqet>_indicators'' for values collected on a <range> limited scope (f.e. daily, scannning data on 24 hours in the past). 
 + 
 +===Describing submodes=== 
 + 
 +Now describe your submodes as a static constant: 
 + 
 +    static $submodes = 'submode1,submode2,submode3'; 
 + 
 +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::__construct(); 
 +        $this->key = 'moodle.<indicatorset>'; 
 +    } 
 + 
 +===Acquiring measures=== 
 + 
 +Here is the most important part of the implementation. For each submode listed in the ''submodes'' static attribute, You will provide an acquisition handler that must get a single value. 
 + 
 +    /** 
 +     * 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->value)) { 
 +            $this->value = new Stdclass; 
 +        } 
 +    
 +        if (is_null($submode)) { 
 +            $submode = $this->submode; 
 +        } 
 +    
 +        switch ($submode) { 
 +    
 +            case 'submode1':
 +    
 +                $submodevalue = [...]; // Whatever gets a single value in Moodle. 
 +    
 +                $this->value->$submode = $submodevalue; 
 +                break; 
 +            } 
 +    
 +            default: { 
 +                if ($CFG->debug == DEBUG_DEVELOPER) { 
 +                    throw new coding_exception("Indicator has a submode that is not handled in acquire_submode()."); 
 +                } 
 +            } 
 +        } 
 + 
 +Once each submode case is written, that's all done ! 
 + 
 <html><!-- nomoodle --></html> <html><!-- nomoodle --></html>
 +----
  
 [[:report:zabbix|Back to Zabbix Report index]] - [[:plugins|Back to plugin index]] - [[:start|Back to catalog]] [[:report:zabbix|Back to Zabbix Report index]] - [[:plugins|Back to plugin index]] - [[:start|Back to catalog]]
  
 <html><!-- /nomoodle --></html> <html><!-- /nomoodle --></html>
report/zabbix/developerguide.1770226941.txt.gz · Dernière modification : de admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki