差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン | |||
ja:documentation:08_technical_reference:07_anexo_console_extensions_development [2022/08/06 22:56] – [サブディレクトリ] junichi | ja:documentation:08_technical_reference:07_anexo_console_extensions_development [Unknown date] (現在) – 削除 - 外部編集 (Unknown date) 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== コンソール拡張の開発 Development ====== | ||
- | {{indexmenu_n> | ||
- | |||
- | [[ja: | ||
- | |||
- | ===== コンソールの拡張 ===== | ||
- | |||
- | 拡張は、プラグインとして新たな機能を Pandora コンソールに開発するためのものです。 | ||
- | |||
- | この章では、拡張の開発の仕方を説明します。 | ||
- | |||
- | ====「拡張」の種類 ==== | ||
- | |||
- | An extension can be one (or more) of the following types: | ||
- | |||
- | 拡張には次の種類があります。 | ||
- | |||
- | * **Agent tab**: Extensions that appear in the tab header of the agent' | ||
- | * **Visible**: | ||
- | * **Invisible**: | ||
- | |||
- | * **エージェントタブ**拡張は、エージェント表示または編集画面のヘッダーのタブに表示されます。 | ||
- | * **表示される**拡張は、Pandora のメニューに表示されます。 | ||
- | * **非表示**の拡張は、Pandora メニューである index.php からロードされ実行されますが、Pandora メニューには表示されません。 | ||
- | |||
- | ====「拡張」のディレクトリ ==== | ||
- | 拡張のディレクトリは、Pandora FMS コンソールをインストールしたディレクトリ内の " | ||
- | |||
- | {{ : | ||
- | |||
- | このディレクトリは、次のようは拡張が含まれています。 | ||
- | |||
- | **拡張のメインファイル** | ||
- | |||
- | Pandora FMS コンソールにロードされるコードです。 | ||
- | |||
- | **拡張のサブディレクトリ** | ||
- | |||
- | これはオプションで、メニュー内の拡張名の隣に表示されるアイコンの画像ファイル (18x18 のサイズ) および、その他、翻訳、モジュール、画像ファイルなどが含まれます。 | ||
- | |||
- | ====「拡張」のテンプレート ==== | ||
- | |||
- | <code php> | ||
- | <?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 */ | ||
- | 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 ==== | ||
- | |||
- | <WRAP center round important 60%> | ||
- | |||
- | The API for extensions is stil under development and may change in the future. | ||
- | |||
- | </ | ||
- | |||
- | <WRAP center round important 60%> | ||
- | |||
- | 拡張の API はまだ開発途上で、将来変更するかもしれません。 | ||
- | </ | ||
- | |||
- | 以下の章では、拡張に関する API の関数の説明をします。 | ||
- | |||
- | === extensions_add_operation_menu_option === | ||
- | |||
- | < | ||
- | extensions_add_operation_menu_option ('< | ||
- | |||
- | </ | ||
- | |||
- | < | ||
- | extensions_add_operation_menu_option ('< | ||
- | |||
- | </ | ||
- | |||
- | この関数は、拡張へのリンクを指定した名称で **操作(Operations)** メニューに追加します。3番目のパラメータはオプションで、アイコン画像 (18x18 ピクセル) への相対パスを指定します。パラメータを設定しない場合は、コンセントのアイコン ({{wiki: | ||
- | |||
- | === extensions_add_godmode_menu_option === | ||
- | |||
- | < | ||
- | extensions_add_godmode_menu_option ('< | ||
- | |||
- | </ | ||
- | |||
- | < | ||
- | extensions_add_godmode_menu_option ('< | ||
- | |||
- | </ | ||
- | |||
- | この関数は、ユーザが 2番目のパラメータで指定された ACL レベルを満たす場合に、拡張へのリンクを指定した名称で **システム管理(Godmode)** メニューに追加します。4番目のパラメータはオプションで、アイコン画像 (18x18 ピクセル) への相対パスを指定します。パラメータを設定しない場合は、コンセントのアイコン ({{wiki: | ||
- | |||
- | === 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('< | ||
- | |||
- | </ | ||
- | |||
- | エージェント編集画面に 1つ以上のタブを追加します。それが選択された場合は、指定した名前の関数が呼び出されます。 | ||
- | |||
- | === extensions_add_opemode_tab_agent === | ||
- | |||
- | < | ||
- | extensions_add_opemode_tab_agent('< | ||
- | |||
- | </ | ||
- | |||
- | < | ||
- | extensions_add_opemode_tab_agent('< | ||
- | |||
- | </ | ||
- | |||
- | エージェント参照画面に 1つ以上のタブを追加します。それが選択された場合は、指定した名前の関数が呼び出されます。 | ||
- | |||
- | === extensions_add_translation_string_function === | ||
- | |||
- | < | ||
- | extensions_add_translation_string_function('< | ||
- | |||
- | </ | ||
- | |||
- | < | ||
- | extensions_add_translation_string_function('< | ||
- | |||
- | </ | ||
- | |||
- | 拡張共通の翻訳関数 **< | ||
- | |||
- | === メニューの親 ID === | ||
- | 拡張 API で利用できる ID 文字列を示します。呼び出し関数で指定しなかったり、以下に無いものを指定した場合は、拡張のサブメニューにのみ表示されます。 | ||
- | |||
- | == 操作 == | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | == システム管理 == | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | **エンタープライズ版の管理** | ||
- | |||
- | <WRAP center round tip 60%> | ||
- | これらの要素は、Enterprise版にのみあります。 | ||
- | </ | ||
- | |||
- | * '' | ||
- | |||
- | ==== 例 ==== | ||
- | |||
- | {{ : | ||
- | |||
- | 列がモジュールのグループ、行がエージェントグループの表を表示する拡張です。また、それぞれのセルは、次のような意味の色が表示されます。 | ||
- | * **緑**: すべてのモジュールが正常 | ||
- | * **黄色**: 少なくとも一つのモニタ項目が警告状態 | ||
- | * **赤**: 少なくとも一つのモニタ項目が障害状態 | ||
- | |||
- | そして、この拡張は、操作メニューのエージェント参照から呼び出されます。 | ||
- | |||
- | |||
- | ==== ソースコード ==== | ||
- | |||
- | <code php> | ||
- | <?php | ||
- | /** | ||
- | * Pandora FMS- http:// | ||
- | * ================================================== | ||
- | * Copyright (c) 2005-2009 Artica Soluciones Tecnologicas | ||
- | * | ||
- | * 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. | ||
- | * GNU General Public License for more details. | ||
- | */ | ||
- | |||
- | /** | ||
- | * Extension specific translation function | ||
- | */ | ||
- | | ||
- | | ||
- | ' | ||
- | " | ||
- | ), | ||
- | /* | ||
- | ... for other language' | ||
- | */ | ||
- | ); | ||
- | |||
- | $args = func_get_args(); | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | } | ||
- | else{ | ||
- | | ||
- | } | ||
- | } | ||
- | |||
- | /** | ||
- | * Translate the array texts using gettext | ||
- | */ | ||
- | | ||
- | $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 = " | ||
- | 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 "< | ||
- | |||
- | echo "< | ||
- | |||
- | $agentGroups = get_user_groups ($config[' | ||
- | $modelGroups = get_all_model_groups(); | ||
- | array_walk($modelGroups, | ||
- | |||
- | $head = $modelGroups; | ||
- | array_unshift($head, | ||
- | |||
- | // | ||
- | $table = null; | ||
- | $table-> | ||
- | $table-> | ||
- | $table-> | ||
- | |||
- | //The content of table | ||
- | $tableData = array(); | ||
- | //Create rows and celds | ||
- | foreach ($agentGroups as $idAgentGroup => $name) { | ||
- | |||
- | $row = array(); | ||
- | |||
- | array_push($row, | ||
- | |||
- | foreach ($modelGroups as $idModelGroup => $modelGroup) { | ||
- | $query = sprintf($sql, | ||
- | $rowsDB = get_db_all_rows_sql ($query); | ||
- | |||
- | $states = array(); | ||
- | if ($rowsDB !== false) { | ||
- | foreach ($rowsDB as $rowDB) { | ||
- | $states[$rowDB[' | ||
- | } | ||
- | } | ||
- | |||
- | $count = 0; | ||
- | foreach ($states as $idState => $state) { | ||
- | $count = $state; | ||
- | } | ||
- | |||
- | $color = ' | ||
- | if ($count == 0) { | ||
- | $color = '# | ||
- | $alinkStart = ''; | ||
- | $alinkEnd = ''; | ||
- | } | ||
- | else { | ||
- | $alinkStart = '<a href=" | ||
- | '& | ||
- | $alinkEnd = '</ | ||
- | |||
- | if (array_key_exists(0, | ||
- | $color = '# | ||
- | else { | ||
- | if (array_key_exists(1, | ||
- | $color = '# | ||
- | else | ||
- | $color = '# | ||
- | } | ||
- | } | ||
- | |||
- | array_push($row, | ||
- | '< | ||
- | style=" | ||
- | height: 15px; | ||
- | margin-left: | ||
- | text-align: center; padding-top: | ||
- | ' . $alinkStart . $count . ' modules' | ||
- | } | ||
- | array_push($tableData, | ||
- | } | ||
- | $table-> | ||
- | |||
- | print_table($table); | ||
- | |||
- | echo "< | ||
- | "< | ||
- | '< | ||
- | <div style=" | ||
- | ___(" | ||
- | '< | ||
- | <div style=" | ||
- | ___(" | ||
- | '< | ||
- | ___(" | ||
- | '< | ||
- | ___(" | ||
- | "</ | ||
- | "</ | ||
- | } | ||
- | |||
- | extensions_add_operation_menu_option(" | ||
- | extensions_add_main_function(' | ||
- | extensions_add_translation_string_function(' | ||
- | ?> | ||
- | |||
- | </ | ||
- | |||
- | |||
- | ==== 説明 ==== | ||
- | ソースコードは、2つのパーツにわかれています。 | ||
- | |||
- | * 拡張のソースコード | ||
- | * API を呼び出す関数 | ||
- | |||
- | パーツの順番は関係ありませんが、APIを呼び出す関数は拡張ファイルの下の方が良いです。なぜなら、スタイルのガイドラインでは、この部分を下に書くようにアドバイスしているためです。それにより、すべての拡張は同じようなスタイルになります。 | ||
- | |||
- | === 拡張のソースコード === | ||
- | この例の場合、同じファイルに 3つの関数があります。しかし、共通のコードがあるのであれば、複数ファイルに分割する方が良いです(そして、拡張のサブディレクトリに保存します)。関数は次の通りです。 | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * 最初は、設定のグローバル変数へのアクセスです。この変数に、Pandora コンソールに関する多くの設定やデフォルト値が含まれます。 | ||
- | * 2つ目の変数は、[[https:// | ||
- | * 次に表示するためのいくつかの '' | ||
- | * DB のデータを 1次元の 2つの配列に展開し、id がインデックスで、内容は列(モジュールグループと行(エージェントグループ)にタイトルです。 | ||
- | * モジュールグループ配列のタイトルを変換します。 | ||
- | * メタオブジェクトの $table を作成し、行を埋めて表示します。 | ||
- | * foreach ループの前に、'' | ||
- | * 最初のループは行のデータ用です。(それぞれのエージェントグループ) | ||
- | * 2つ目のループは、現在の行に対する列のデータ用です。(それぞれのモジュールグループ) | ||
- | * そして、それぞれのセルに、モジュールグループとエージェントグループの ID の 2つの数字が当てはまり、この 2つの数字を使ってデータベースクエリを実施し、データを取得します。 | ||
- | * 異なる種類のモニタ状態および、状態の数の合計の結果の配列を生成します。 | ||
- | * そして残りは、セルを html に整形する処理です。仕組みは簡単です。すべての状態の合計がゼロであれば、CSS の div で背景をグレーにします。もし、'' | ||
- | * 合計が '' | ||
- | * 行を '' | ||
- | * 表を表示します。 | ||
- | * 凡例とその他注意をページの下に表示します。 | ||
- | |||
- | === API 呼び出し関数 === | ||
- | |||
- | There are only a few lines of code. The operations in these lines are: | ||
- | |||
- | 数行のコードです。この行で行う処理は次の通りです。 | ||
- | |||
- | * Insert the extension into Pandora FMS menu. | ||
- | * And it's with the call | ||
- | |||
- | * 拡張を Pandora FMS メニューへ挿入 | ||
- | * そして、呼び出し | ||
- | |||
- | < | ||
- | extensions_add_operation_menu_option(" | ||
- | |||
- | </ | ||
- | |||
- | Where: | ||
- | |||
- | ここで、 | ||
- | |||
- | * **' | ||
- | * **' | ||
- | * **' | ||
- | * Define the main function of this extension . \\ And it's with the call '' | ||
- | * **' | ||
- | |||
- | * **' | ||
- | * **' | ||
- | * **' | ||
- | * この拡張のメイン関数の定義\\ '' | ||
- | * ' | ||
- | |||
- | 呼び出す関数の順番に指定はありません。いずれかを最初に呼び出して、2つ目に他の関数などを呼び出すことができます。 | ||
- | |||
- | === ディレクトリ構成 === | ||
- | |||
- | {{ : | ||
- | |||
- | 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 [[: | ||
- | |||
- | 拡張のインストールはとても簡単です。なぜなら、Pandora FMS コンソールは新たな拡張を検索し、それを見つけたらシステムに追加します。 | ||
- | 拡張のファイルすべてを [[: | ||
- | |||
- | 画面例では、extension は次のようなディレクトリ構造になっています。 | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | And the extension directory is for example in ''/ | ||
- | |||
- | そして、例では extension ディレクトリは、''/ | ||
- | |||
- | === サブディレクトリ === | ||
- | |||
- | In this case, the example has one subdirectory, | ||
- | |||
- | この場合、例では一つのサブディレクトリがあります。そして、通常、拡張は一つのサブディレクトリを持つ必要があります。サブディレクトリは、拡張のメインファイルと同じ名前です。この例のサブディレクトリには、アイコンファイル ('' | ||