目次

コンソール拡張の開発

Pandora FMS ドキュメント一覧に戻る

概要

Extensions are a way to develop new features for Pandora FMS Web Console as plugins.

拡張は、Pandora FMS Web コンソールの新しい機能をプラグインとして開発する方法です。

「拡張」の種類

An extension can be one (or more) of the following types:

拡張には次の種類があります。

「拡張」のディレクトリ

The extensions directory is a subdirectory inside the local installation of Pandora FMS Web Console that has the name extensions. This directory contains the following for each extension:

拡張のディレクトリは、Pandora FMS コンソールをインストールしたディレクトリ内の extensions というサブディレクトリです。このディレクトリは、次のようは拡張が含まれています。

Extension main file

拡張のメインファイル

This file has the code to be loaded in the Pandora FMS Web Console.

Pandora FMS コンソールにロードされるコードです。

Extension subdirectory

拡張のサブディレクトリ

It is optional and can contain the icon image file (18 by 18 pixels) shown next to the extension name in the menu, as well as other files such as translations, modules and images.

これはオプションで、メニュー内の拡張名の隣に表示されるアイコンの画像ファイル (18×18 のサイズ) および、その他、翻訳、モジュール、画像ファイルなどが含まれます。

「拡張」の構造

<?php
 
<Comments with license, author/s, etc...>
 
<php auxiliary code as functions, variables, classes that your extension use>
 
function <name of main function> () {
    <Main function Code>
}
 
/*-------------------------------------*/
 
/* Adds the link in the operation menu */
extensions_add_operation_menu_option ('<Name Extension>', '<father ID menu>', '<relative path Icon>');
 
/* Adds the link in the godmode menu */
extensions_add_godmode_menu_option ('<Name Extension>', '<ACL level>', '<father ID menu>', '<relative path Icon>')
 
/*-------------------------------------*/
 
/* Sets the callback function to be called when the extension is selected in the operation menu */
extensions_add_main_function ('<name of main function>');
 
/* Sets the callback function to be called when the extension is selected in the godmode menu */
extensions_add_godmode_function('<name of godmode function>');
?>

「拡張」の API

The API for extensions is still under development and may change in the future.

拡張の API はまだ開発途上で、将来変更するかもしれません。

extensions_add_operation_menu_option

extensions_add_operation_menu_option ('<string name>', '<father ID menu>', '<relative path Icon>')
extensions_add_operation_menu_option ('<名前文字列>', '<メニュー親ID>', '<アイコン相対パス>')

This function adds the link to the extension with the name given in the Operations menu. The third parameter is optional and this is the optional field for the icon image (18 by 18 pixels) to appear next to the link.

この関数は、拡張へのリンクを指定した名称で 操作(Operations) メニューに追加します。3番目のパラメータはオプションで、アイコン画像 (18×18 ピクセル) への相対パスを指定します。

If this last parameter is not defined, the icon of a plug will be used ().

この最後のパラメータが定義されていない場合は、プラグのアイコンが使用されます ()。

extensions_add_godmode_menu_option

extensions_add_godmode_menu_option ('<Name Extension>', '<ACL level>' , '<father ID menu>', '<relative path Icon>')
extensions_add_godmode_menu_option ('<拡張名>', '<ACL レベル>' , '<メニュー親ID>', '<アイコン相対パス>')

This function adds the link to the extension with the name given in the Godmode menu if the user has the required ACL level as indicated by the second parameter. The fourth parameter is optional and is the relative field for the icon image (18 by 18 pixels) to appear next to the link.

この関数は、ユーザが 2番目のパラメータで指定された ACL レベルを満たす場合に、拡張へのリンクを指定した名称で システム管理(Godmode) メニューに追加します。4番目のパラメータはオプションで、アイコン画像 (18×18 ピクセル) への相対パスを指定します。

If this last parameter is not defined, the icon of a plug will be used ( ).

この最後のパラメータが定義されていない場合は、プラグのアイコンが使用されます ( )。

extensions_add_main_function

extensions_add_main_function ('<name of main function>')
extensions_add_main_function ('<メイン関数名>')

Sets the callback function to return when the user clicks on the extension link in the operation menu.

操作(operation)メニューで拡張のリンクをクリックしたときに呼び出される関数を設定します。

extensions_add_godmode_function

extensions_add_godmode_function ('<name of godmode function>')
extensions_add_godmode_function ('<システム管理メニュー関数名>')

Adds the extension function to call once the user goes to the extension in the godmode of the Pandora FMS Web Console instead of loading the main function.

Pandora FMS コンソールのシステム管理メニューの拡張のリンクをクリックしたときに呼び出される関数を設定します。

extensions_add_login_function

extensions_add_login_function ('<name of login function>')
extensions_add_login_function ('<ログイン関数名>')

Adds the extension function to call once the user successfully logs into the Pandora FMS Web Console.

Pandora FMS コンソールへユーザが正しくログインしたときに呼び出される関数を設定します。

extensions_add_godmode_tab_agent

extensions_add_godmode_tab_agent('<ID of extension tab>', '<Name of extension tab>', '<Image file with relative dir>', '<Name of function to show content of godmode tab agent>')
extensions_add_godmode_tab_agent('<拡張タブID>', '<拡張タブ名>', '<画像ファイルの相対パス>', '<エージェント管理のタブから実行される関数名>')

Adds one more tab to the agent edit view so that when it is selected the code of the function of the name passed to it is executed.

エージェント編集画面に 1つ以上のタブを追加します。それが選択された場合は、指定した名前の関数が呼び出されます。

extensions_add_opemode_tab_agent

extensions_add_opemode_tab_agent('<ID of extension tab>', '<Name of extension tab>', '<Image file with relative dir>', '<Name of function to show content of operation tab agent>')
extensions_add_opemode_tab_agent('<拡張タブID>', '<拡張タブ名>', '<画像ファイルの相対パス>', '<エージェント参照のタブから実行される関数名>')

Adds one more tab to the agent operation view that causes the function code of the name that is passed to it to be executed when selected.

エージェント参照画面に 1つ以上のタブを追加します。それが選択された場合は、指定した名前の関数が呼び出されます。

extensions_add_translation_string_function

extensions_add_translation_string_function('<Name of translation function>')
extensions_add_translation_string_function('<翻訳関数名>')

Adds the callback function to be called from the standard extension translation function.

拡張共通の翻訳関数 ___() から呼び出される関数を設定します。

メニューの親 ID

List of IP strings available for use in extension API. If you use a null value or do not include parameter in the call function, then the extension appears only in the extension submenu.

拡張 API で利用できる ID 文字列を示します。呼び出し関数で指定しなかったり、パラメータを指定しない場合は、拡張のサブメニューにのみ表示されます。

操作

システム管理

The extension displays a table where columns are groups of modules and rows are groups of agents. Each cell has a color with the following meanings:

列がモジュールのグループ、行がエージェントグループの表を表示する拡張です。また、それぞれのセルは、次のような意味の色が表示されます。

This extension resides in the Operation menu under Agents.

そして、この拡張は、操作メニューのエージェント参照から呼び出されます。

ソースコード

<?php
/**
 * Pandora FMS - http://pandorafms.com
 * ==================================================
 * Copyright (c) 2005-2024 PFMS
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation for version 2.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
 
/**
 * Extension specific translation function
 */
 function extensions_translation() {
   $translates = array(
     'es' => array(
       "sentence" => "translated sentence"
     ),
     /*
      ... for other language's definitions.
     */
   );
 
   $args = func_get_args();
   $string = array_shift($args);
   $user_language = get_user_language ();
   if(isset($translates[$user_language][$string])){
     return vsprintf($translates[$user_language][$string], $args);
   }
   else{
     return false;
   }
 }
 
/**
 * Translate the array texts using gettext
 */
 function translate(&$item, $key) {
     $item = ___($item);
 }
 
/**
 * The main function of module groups and the enter point to
 * execute the code.
 */
function mainModuleGroups() {
    global $config; //the useful global var of Pandora Console, it has many data can you use
 
    //The big query
    $sql = "select COUNT(id_agente) AS count, estado
        FROM tagente_estado
        WHERE utimestamp != 0 AND id_agente IN
            (SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled IS FALSE)
            AND id_agente_modulo IN
            (SELECT id_agente_modulo
                FROM tagente_modulo
                WHERE id_module_group = %d AND disabled IS FALSE AND delete_pending IS FALSE)
        GROUP BY estado";
 
    echo "<h1>" . ___("Combine table of agent group and module group") . "</h1>";
 
    echo "<p>" . ___("This table show in columns the modules group and for rows agents group. The cell show all modules") . "</p>";
 
    $agentGroups = get_user_groups ($config['id_user']);
    $modelGroups = get_all_model_groups();
    array_walk($modelGroups, 'translate'); //Translate all head titles to language is set
 
    $head = $modelGroups;
    array_unshift($head, ' ');
 
    //Metaobject use in print_table
    $table = null;
    $table->align[0] = 'right'; //Align to right the first column.
    $table->style[0] = 'color: #ffffff; background-color: #778866; font-weight: bolder;';
    $table->head = $head;
 
    //The content of table
    $tableData = array();
    //Create rows and celds
    foreach ($agentGroups as $idAgentGroup => $name) {
 
        $row = array();
 
        array_push($row, $name);
 
        foreach ($modelGroups as $idModelGroup => $modelGroup) {
            $query = sprintf($sql,$idAgentGroup, $idModelGroup);
            $rowsDB = get_db_all_rows_sql ($query);
 
            $states = array();
            if ($rowsDB !== false) {
                foreach ($rowsDB as $rowDB) {
                    $states[$rowDB['estado']] = $rowDB['count'];
                }
            }
 
            $count = 0;
            foreach ($states as $idState => $state) {
                $count = $state;
            }
 
            $color = 'transparent'; //Defaut color for cell
            if ($count == 0) {
                $color = '#babdb6'; //Grey when the cell for this model group and agent group hasn't modules.
                $alinkStart = '';
                $alinkEnd = '';
            }
            else {
                $alinkStart = '<a href="index.php?sec=estado&sec2=operation/agentes/status_monitor&status=-1&ag_group=' . $idAgentGroup .
                    '&modulegroup=' . $idModelGroup . '">';
                $alinkEnd = '</a>';
 
                if (array_key_exists(0,$states) && (count($states) == 1))
                    $color = '#8ae234'; //Green when the cell for this model group and agent has OK state all modules.
                else {
                    if (array_key_exists(1,$states))
                        $color = '#cc0000'; //Red when the cell for this model group and agent has at least one module in critical state and the rest in any state.
                    else
                        $color = '#fce94f'; //Yellow when the cell for this model group and agent has at least one in warning state and the rest in green state.
                }
            }
 
            array_push($row,
                '<div
                    style="background: ' . $color . ' ;
                        height: 15px;
                        margin-left: auto; margin-right: auto;
                        text-align: center; padding-top: 5px;">
                    ' . $alinkStart . $count . ' modules' . $alinkEnd . '</div>');
        }
        array_push($tableData,$row);
    }
    $table->data = $tableData;
 
    print_table($table);
 
    echo "<p>" . ___("The colours meaning:") .
        "<ul>" .
        '<li style="clear: both;">
            <div style="float: left; background: #babdb6; height: 20px; width: 80px;margin-right: 5px; margin-bottom: 5px;"> </div>' .
            ___("Grey when the cell for this model group and agent group hasn't modules.") . "</li>" .
        '<li style="clear: both;">
            <div style="float: left; background: #8ae234; height: 20px; width: 80px;margin-right: 5px; margin-bottom: 5px;"> </div>' .
            ___("Green when the cell for this model group and agent has OK state all modules.") . "</li>" .
        '<li style="clear: both;"><div style="float: left; background: #cc0000; height: 20px; width: 80px;margin-right: 5px; margin-bottom: 5px;"> </div>' .
            ___("Red when the cell for this model group and agent has at least one module in critical state and the rest in any state.") . "</li>" .
        '<li style="clear: both;"><div style="float: left; background: #fce94f; height: 20px; width: 80px;margin-right: 5px; margin-bottom: 5px;"> </div>' .
            ___("Yellow when the cell for this model group and agent has at least one in warning state and the rest in green state.") . "</li>" .
        "</ul>" .
        "</p>";
}
 
extensions_add_operation_menu_option("Modules groups", 'estado', 'module_groups/icon_menu.png');
extensions_add_main_function('mainModuleGroups');
extensions_add_translation_string_function('extensions_translation');
?>

説明

There are two parts in the source code:

ソースコードは、2つのパーツにわかれています。

The order of the parts is indifferent, it is better to place the “call API functions” under its main extension file because the style guides warn that this part should be placed underneath so that all extensions have approximately the same style.

パーツの順番は関係ありませんが、APIを呼び出す関数は拡張ファイルの下の方が良いです。なぜなら、スタイルのガイドラインでは、この部分を下に書くようにアドバイスしているためです。それにより、すべての拡張は同じようなスタイルになります。

拡張のソースコード

In the case of this example there are two functions in the same file, if you had a more complex code then it would be better to split it into many files (and save it in subdirectory extension). The functions are:

この例の場合、同じファイルに 3つの関数があります。しかし、共通のコードがあるのであれば、複数ファイルに分割する方が良いです(そして、拡張のサブディレクトリに保存します)。関数は次の通りです。

API 呼び出し関数

extensions_add_operation_menu_option("Modules groups", 'estado', 'module_groups/icon_menu.png');

The order in which the functions are named is irrelevant.

関数の順序は関係ありません。

ディレクトリ構成

The extension has this directory structure:

拡張機能のディレクトリ構造は次のとおりです。

+module_groups
|
+--icon_menu.png
|
+module_groups.php

The directory extension is in /var/www/pandora_console.

拡張のディレクトリは /var/www/pandora_console にあります。

You should only copy all the extension files to the extension directory in installation of Pandora FMS Console. You should install the permissions so the Pandora FMS Console can read the files and the extension subdirectories. The Pandora FMS console looks for new extensions and adds them to the system when it finds them.

すべての拡張ファイルは、Pandora FMS コンソール の拡張ディレクトリにのみコピーする必要があります。Pandora FMS コンソールがファイルと拡張サブディレクトリを読み取ることができるように、権限を調整する必要があります。Pandora FMS コンソールは新しい拡張を検索し、見つかった場合はシステムに追加します。

サブディレクトリ

The example has only one subdirectory (and generally any extension should have a subdirectory). The subdirectory has the same name as the extension name and the main file. The subdirectory of the example has only one icon image file (icon_menu.png). This icon will appear in the Pandora FMS menu.

この場合、例では一つのサブディレクトリがあります。そして、通常、拡張は一つのサブディレクトリを持つ必要があります。サブディレクトリは、拡張のメインファイルと同じ名前です。この例のサブディレクトリには、アイコンファイル (icon_menu.png) のみがあります。このアイコンは、 Pandora FMS メニューに表示されます。

Pandora FMS ドキュメント一覧に戻る