====== コンソール拡張の開発 Development ======
{{indexmenu_n>7}}
[[ja:documentation:start|Pandora FMS ドキュメント一覧に戻る]]
===== コンソールの拡張 =====
拡張は、プラグインとして新たな機能を Pandora コンソールに開発するためのものです。
この章では、拡張の開発の仕方を説明します。
====「拡張」の種類 ====
An extension can be one (or more) of the following types:
拡張には次の種類があります。
* **Agent tab**: Extensions that appear in the tab header of the agent's operation and/or edition view.
* **Visible**: Extensions that appear in the Pandora FMS Menu.
* **Invisible**: Extensions that are loaded and executed in the index.php of the Pandora FMS Menu but that do not appear in the PFMS Menu.
* **エージェントタブ**拡張は、エージェント表示または編集画面のヘッダーのタブに表示されます。
* **表示される**拡張は、Pandora のメニューに表示されます。
* **非表示**の拡張は、Pandora メニューである index.php からロードされ実行されますが、Pandora メニューには表示されません。
====「拡張」のディレクトリ ====
拡張のディレクトリは、Pandora FMS コンソールをインストールしたディレクトリ内の "extensions" というサブディレクトリです。
{{ :wiki:pfms-pandora_console-extensions-directory.png }}
このディレクトリは、次のようは拡張が含まれています。
**拡張のメインファイル**
Pandora FMS コンソールにロードされるコードです。
**拡張のサブディレクトリ**
これはオプションで、メニュー内の拡張名の隣に表示されるアイコンの画像ファイル (18x18 のサイズ) および、その他、翻訳、モジュール、画像ファイルなどが含まれます。
====「拡張」のテンプレート ====
" . ___("This table show in columns the modules group and for rows agents group. The cell show all modules") . " " . ___("The colours meaning:") .
"
< 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 */
add_operation_menu_option ('< Name Extension >', '< father ID menu >', '< relative path Icon >');
/* Adds the link in the godmode menu */
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 */
add_extension_main_function ('< name of main function >');
/* Sets the callback function to be called when the extension is selected in the godmode menu */
add_extension_godmode_function ('< name of godmode function >');
?>
====「拡張」の API ====
extensions_add_operation_menu_option ('
extensions_add_operation_menu_option ('<名前文字列>', '<メニュー親ID>', '<アイコン相対パス>')
この関数は、拡張へのリンクを指定した名称で **操作(Operations)** メニューに追加します。3番目のパラメータはオプションで、アイコン画像 (18x18 ピクセル) への相対パスを指定します。パラメータを設定しない場合は、コンセントのアイコン ({{wiki:Extensions.png}}) が利用されます。
=== extensions_add_godmode_menu_option ===
extensions_add_godmode_menu_option ('
extensions_add_godmode_menu_option ('<拡張名>', '
この関数は、ユーザが 2番目のパラメータで指定された ACL レベルを満たす場合に、拡張へのリンクを指定した名称で **システム管理(Godmode)** メニューに追加します。4番目のパラメータはオプションで、アイコン画像 (18x18 ピクセル) への相対パスを指定します。パラメータを設定しない場合は、コンセントのアイコン ({{wiki:Extensions.png}}) が利用されます。
=== extensions_add_main_function ===
extensions_add_main_function ('
extensions_add_main_function ('<メイン関数名>')
操作(operation)メニューで拡張のリンクをクリックしたときに呼び出される関数を設定します。
=== extensions_add_godmode_function ===
extensions_add_godmode_function ('
extensions_add_godmode_function ('<システム管理メニュー関数名>')
Pandora FMS コンソールのシステム管理メニューの拡張のリンクをクリックしたときに呼び出される関数を設定します。
=== extensions_add_login_function ===
extensions_add_login_function ('
extensions_add_login_function ('<ログイン関数名>')
Pandora FMS コンソールへユーザが正しくログインしたときに呼び出される関数を設定します。
=== extensions_add_godmode_tab_agent ===
extensions_add_godmode_tab_agent('
extensions_add_godmode_tab_agent('<拡張タブID>', '<拡張タブ名>', '<画像ファイルの相対パス>', '<エージェント管理のタブから実行される関数名>')
エージェント編集画面に 1つ以上のタブを追加します。それが選択された場合は、指定した名前の関数が呼び出されます。
=== extensions_add_opemode_tab_agent ===
extensions_add_opemode_tab_agent('
extensions_add_opemode_tab_agent('<拡張タブID>', '<拡張タブ名>', '<画像ファイルの相対パス>', '<エージェント参照のタブから実行される関数名>')
エージェント参照画面に 1つ以上のタブを追加します。それが選択された場合は、指定した名前の関数が呼び出されます。
=== extensions_add_translation_string_function ===
extensions_add_translation_string_function('
extensions_add_translation_string_function('<翻訳関数名>')
拡張共通の翻訳関数 **
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 "
" . ___("Combine table of agent group and module group") . "
";
echo "" .
'
" .
"
extensions_add_operation_menu_option("Modules groups", 'estado', 'module_groups/icon_menu.png');
Where:
ここで、
* **'Modules groups**' is the name appear in submenu of agents.
* **'Status**' is the element that hangs from the extension.
* **'module_groups/icon_menu.png**' is the image icon appear in submenu, the path is relative to your extension directory.
* Define the main function of this extension . \\ And it's with the call ''extensions_add_main_function('mainModuleGroups');''
* **'mainModuleGroups**' is the name of extension main function.
* **'Modules groups**' は、エージェントのサブメニューに表示される名前です。
* **'estado**' は、拡張に関連付けるエレメントです。
* **'module_groups/icon_menu.png**' は、サブメニューに表示されるアイコンです。パスは、拡張のディレクトリからの相対パスです。
* この拡張のメイン関数の定義\\ ''extensions_add_main_function('mainModuleGroups');'' を呼び出すことによって行います。ここで、
* '**mainModuleGroups**' は、拡張のメイン関数名です。
呼び出す関数の順番に指定はありません。いずれかを最初に呼び出して、2つ目に他の関数などを呼び出すことができます。
=== ディレクトリ構成 ===
{{ :wiki:directory_extension_example.png }}
The instalation of extension is very easy, because the Pandora FMS Console search new extensions and add into system when new extension is found. You only copy all files of extensions into the directory extension in your [[:es:documentation:02_installation:01_installing|Pandora FMS Console instalation]]. But you must **set the permissions for the Pandora FMS Console can read the files and subdirectories of extension**.
拡張のインストールはとても簡単です。なぜなら、Pandora FMS コンソールは新たな拡張を検索し、それを見つけたらシステムに追加します。
拡張のファイルすべてを [[:ja:documentation:02_installation:01_installing|Pandora FMS コンソールをインストール]]した extension ディレクトリにコピーするだけです。ただし、**Pandora FMS コンソールが拡張のファイルおよびサブディレクトリを読めるようにパーミッションを設定する**必要があります。
画面例では、extension は次のようなディレクトリ構造になっています。
* ''module_groups''
* ''icon_menu.png''
* ''module_groups.php''
And the extension directory is for example in ''/var/www/pandora_console''.
そして、例では extension ディレクトリは、''/var/www/pandora_console'' にあります。
=== サブディレクトリ ===
In this case, the example has one subdirectory, and usually any extension must has one subdirectory. The subdirectory has the same name as the name extension and the main file. The subdirectory of the example only has an image icon file (''icon_menu.png''). This icon is shown in the Pandora FMS Menu.
この場合、例では一つのサブディレクトリがあります。そして、通常、拡張は一つのサブディレクトリを持つ必要があります。サブディレクトリは、拡張のメインファイルと同じ名前です。この例のサブディレクトリには、アイコンファイル (''icon_menu.png'') のみがあります。このアイコンは、 Pandora FMS メニューに表示されます。