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] – [Defining indicators] adminreport:zabbix:developerguide [2026/02/07 19:41] (Version actuelle) – [Plugin registration method] admin
Ligne 43: Ligne 43:
  
    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 61:
 ====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 84: Ligne 84:
        
    class daily_<indicatorset>_indicators extends zabbix_indicator {    class daily_<indicatorset>_indicators extends zabbix_indicator {
-      [...]+       [...]
    }    }
  
Ligne 93: Ligne 93:
  
 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 !
  
 ---- ----
report/zabbix/developerguide.1770226974.txt.gz · Dernière modification : de admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki