ja:documentation:pandorafms:technical_reference:06_anexo_agent_plugins

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
ja:documentation:pandorafms:technical_reference:06_anexo_agent_plugins [2024/05/23 05:44] – [pandora_agent_daemon の再起動] junichija:documentation:pandorafms:technical_reference:06_anexo_agent_plugins [2025/02/26 02:38] (現在) – [pandora_agent_daemon の再起動] junichi
行 4: 行 4:
 [[ja:documentation:start|Pandora FMS ドキュメント一覧に戻る]] [[ja:documentation:start|Pandora FMS ドキュメント一覧に戻る]]
  
-===== エージェントプラグイン開発 =====+<wrap #ks1 />
  
-==== エージェントプラグインの基本機能 ==== +===== エージェントプラグインの基本機能 =====
-エージェントプラグインは、**Pandora FMS ソフトウエアエージェントで実行され**、いくつかの特別な機能があります。+
  
-  それぞれのプラグインの実行では、一つまたは複数のモジュールの値を返します。出力は後述する XML フォーマットである必要があります。+The //agent //plugin **is run by Pandora FMS Software Agent** so it has to have some special features:
  
-  * ロカルマシのリソースおよび、リモートでマシンのリソースの両方にアクセスすることできます。+//エジェト//プラグインは、**Pandora FMS フトウエアエジェントで実行され**、いくつか特別な機能あります。
  
-  * Pandora ソフトウエアエージェントがインストールされている OS でサポートしている、任意のプログラミング言語を利用することができます。+   Each plugin execution may return one or more modules with their corresponding values. The output must be in [[#ks3_5|XML format]]. 
 +  * It will be possible to access local machine resources local or remote machine resources. 
 +  * It is possible to use any type of programming language supported by the operating system where the Pandora FMS software agent is installed. 
 +  * All dependencies or software needed to run the plugin must be available or installed in the same machine that runs Pandora FMS agent.
  
 +  * それぞれのプラグインの実行では、一つまたは複数のモジュールの値を返します。出力は後述する XML フォーマットである必要があります。
 +  * ローカルマシンのリソースおよび、リモートで他のマシンのリソースの両方にアクセスすることができます。
 +  * Pandora ソフトウエアエージェントがインストールされている OS でサポートしている、任意のプログラミング言語を利用することができます。
   * プラグインを実行するために必要な依存プログラムは、Pandora ソフトウエアエージェントを実行するのと同じマシンにインストールされている必要があります。   * プラグインを実行するために必要な依存プログラムは、Pandora ソフトウエアエージェントを実行するのと同じマシンにインストールされている必要があります。
 +
 +Agent plugins may perform a kind of recon task since the plugin may return several modules in one run and the number may change between different runs.
  
 エージェントプラグインは、"自動検出タスク" のようなことを実行でき、プラグインは一度の実行で複数のモジュールを返すことができ、また、実行ごとに異なる数を返すことができます。 エージェントプラグインは、"自動検出タスク" のようなことを実行でき、プラグインは一度の実行で複数のモジュールを返すことができ、また、実行ごとに異なる数を返すことができます。
  
-<WRAP center round important 60%> +<WRAP center round important 90%> 
-UNIX および Linux では、プラグインの終了ステータスは でなければなりません。そうでないと、プラグインの出力は無視されます。+ 
 +On UNIX and GNU/Linux the result of the plugin execution must be ''0'', otherwise the plugin result will be ignored. 
 </WRAP> </WRAP>
  
-==== エージェントプラグイン開発の例 ==== +<WRAP center round important 90%>
-簡単なプラグインの例を説明します。このエージェントプラグインは、ファイルシステムの利用率を返します。プログラムコードは次の通りです。+
  
-<code>+UNIX および GNU/Linux では、プラグインの終了ステータスは ''0'' でなければなりません。そうでないと、プラグインの出力は無視されます。 
 + 
 +</WRAP> 
 + 
 +<wrap #ks2 /> 
 + 
 +===== エージェントプラグイン開発の例 ===== 
 + 
 +This agent plugin returns the percentage of system //filesystem// usage. 
 + 
 +このエージェントプラグインは、ファイルシステムの利用率を返します。 
 + 
 +<code perl>
 #!/usr/bin/perl #!/usr/bin/perl
- +
 use strict; use strict;
  
 sub usage() { sub usage() {
-        print "\npandora_df.pl v1r1\n\n"; +        print "\npandora_df.pl v1r1\n\n";
         print "usage: ./pandora_df\n";         print "usage: ./pandora_df\n";
         print "usage: ./pandora_df tmpfs /dev/sda1\n\n";         print "usage: ./pandora_df tmpfs /dev/sda1\n\n";
 } }
-  + 
-# Retrieve information from all filesystems+# Retrieve information from all filesystem
 my $all_filesystems = 0; my $all_filesystems = 0;
  
 # Check command line parameters # Check command line parameters
-if ($#ARGV < 0) {+if ($#ARGV <0) {
         $all_filesystems = 1;         $all_filesystems = 1;
 } }
行 62: 行 82:
  
 # No filesystems? Something went wrong. # No filesystems? Something went wrong.
-if ($#df < 0) {+if ($#df <0) {
         exit 1;         exit 1;
 } }
行 69: 行 89:
 foreach my $row (@df) { foreach my $row (@df) {
         my @columns = split (' ', $row);         my @columns = split (' ', $row);
-        exit 1 if ($#columns < 4);+        exit 1 if ($#columns <4);
         $filesystems{$columns[0]} = $columns[4] if (defined ($filesystems{$columns[0]}) || $all_filesystems == 1);         $filesystems{$columns[0]} = $columns[4] if (defined ($filesystems{$columns[0]}) || $all_filesystems == 1);
 } }
行 76: 行 96:
  
         # Remove the trailing %         # Remove the trailing %
-        chop ($use); +        chop ($use);
  
         # Print module output         # Print module output
行 88: 行 108:
  
 exit 0; exit 0;
 +
 </code> </code>
 +
 +An important part of the code is the ''usage'' function:
  
 コードの重要部分は、利用方法を表示する関数です。 コードの重要部分は、利用方法を表示する関数です。
  
-<code>+<code perl>
 sub usage() { sub usage() {
-        print "\npandora_df.pl v1r1\n\n"; +        print "\npandora_df.pl v1r1\n\n";
         print "usage: ./pandora_df\n";         print "usage: ./pandora_df\n";
         print "usage: ./pandora_df tmpfs /dev/sda1\n\n";         print "usage: ./pandora_df tmpfs /dev/sda1\n\n";
 } }
 +
 </code> </code>
  
-この関数では、プラグインのバージョンと利用方法を説明します。これはとても重要で、パラメータ無しや -h, --help といったオプションをつけてプラグインを実行したときに表示すべきです。この例では、-h オプションをつけて実行した場合、次の処理でそれを判断します。+This function describes the version and how to use plugin, it is very important and must always be shown when executing plugin without any parameter or with a ''-h'' (or ''-help'') option:
  
-<code>+この関数では、プラグインのバージョンと利用方法を説明します。これはとても重要で、パラメータ無しや ''-h'', ''--help'' といったオプションをつけてプラグインを実行したときに表示すべきです。 
 + 
 +<code perl>
 if ($ARGV[0] eq "-h") { if ($ARGV[0] eq "-h") {
         usage();         usage();
         exit(0);         exit(0);
 } }
 +
 </code> </code>
  
 +Regarding the values returned by the plugin it can be observed that once the data of the following files have been collected, a part of XML is created and printed by the standard output for each of them, this task is performed in the following lines:
  
 プラグインから返される値としては、ファイルシステムから一回データが収集されることがわかると思います。データを含めた XML の書式を生成し標準出力に出力します。この処理は次の部分で行われています。 プラグインから返される値としては、ファイルシステムから一回データが収集されることがわかると思います。データを含めた XML の書式を生成し標準出力に出力します。この処理は次の部分で行われています。
  
-<code>+<code perl>
 while (my ($filesystem, $use) = each (%filesystems)) { while (my ($filesystem, $use) = each (%filesystems)) {
  
         # Remove the trailing %         # Remove the trailing %
-        chop ($use); +        chop ($use);
  
         # Print module output         # Print module output
行 126: 行 154:
         print "</module>\n";         print "</module>\n";
 } }
 +
 </code> </code>
 +
 +The result returned by this plugin could be:
  
 このプラグインの出力結果は、次のようになります。 このプラグインの出力結果は、次のようになります。
  
-<code>+<code xml>
 <module> <module>
-<name><![CDATA[tmpfs]]></name> +  <name><![CDATA[tmpfs]]></name> 
-<type><![CDATA[generic_data]]></type> +  <type><![CDATA[generic_data]]></type> 
-<data><![CDATA[0]]></data> +  <data><![CDATA[0]]></data> 
-<description>% of usage in this volume</description>+  <description>% of usage in this volume</description>
 </module> </module>
 <module> <module>
-<name><![CDATA[/dev/mapper/VolGroup-lv_home]]></name> +  <name><![CDATA[/dev/mapper/VolGroup-lv_home]]></name> 
-<type><![CDATA[generic_data]]></type> +  <type><![CDATA[generic_data]]></type> 
-<data><![CDATA[26]]></data> +  <data><![CDATA[26]]></data> 
-<description>% of usage in this volume</description>+  <description>% of usage in this volume</description>
 </module> </module>
 <module> <module>
-<name><![CDATA[/dev/sda9]]></name> +  <name><![CDATA[/dev/sda9]]></name> 
-<type><![CDATA[generic_data]]></type> +  <type><![CDATA[generic_data]]></type> 
-<data><![CDATA[34]]></data> +  <data><![CDATA[34]]></data> 
-<description>% of usage in this volume</description>+  <description>% of usage in this volume</description>
 </module> </module>
 +
 </code> </code>
  
 +The number of modules returned by this plugin depends on the number of configured filesystems and may change between executions.
  
 このプラグインから返されるモジュール数は、設定したファイルシステムの数に依存し、実行ごとに変更することができます。 このプラグインから返されるモジュール数は、設定したファイルシステムの数に依存し、実行ごとに変更することができます。
 +
 +The XML fragment is added to the general XML generated by the software agent and is sent to the Pandora FMS server to be processed by the **Data Server**.
  
 この XML がソフトウエアエージェントが生成する全体の XML に追加され、Pandora サーバへ送信され、**データサーバ** にて処理されます。 この XML がソフトウエアエージェントが生成する全体の XML に追加され、Pandora サーバへ送信され、**データサーバ** にて処理されます。
  
-==== トラブルシューティング ====+<wrap #ks4 /> 
 + 
 +===== トラブルシューティング ====
 + 
 +If Pandora FMS does not recognize the agent plugin, does not get the expected information or the agent simply does not work, here are several things you should take into account. 
 Pandora FMS がエージェントプラグインを認識できないと、期待した値が取得できなかったりエージェントが動作しません。その場合の確認ポイントを以下に示します。 Pandora FMS がエージェントプラグインを認識できないと、期待した値が取得できなかったりエージェントが動作しません。その場合の確認ポイントを以下に示します。
  
-=== pandora_agent.conf のドキュメント確認 ===+<wrap #ks3_1 /> 
 + 
 +==== pandora_agent.conf の修正 ===
 + 
 +The Software Agent requires a line in this file with the **correct path** of the plugin. 
 ソフトウエアエージェントでは、プラグインの **正しいパス** がこのファイル内に書かれている必要があります。 ソフトウエアエージェントでは、プラグインの **正しいパス** がこのファイル内に書かれている必要があります。
 +
 +Example:
  
 例: 例:
  
-   module_plugin /etc/pandora/plugins/MyMonitor.pl /etc/pandora/plugins/MyMonitor.conf 2> /etc/pandora/plugins/MyMonitor.err+<file conf /etc/pandora/pandora_agent.conf> 
 +module_plugin /etc/pandora/plugins/MyMonitor.pl /etc/pandora/plugins/MyMonitor.conf 2> /etc/pandora/plugins/MyMonitor.err
  
-**MyMonitor.pl** はエージェントプラグインで、**MyMonitor.conf** は引数として渡される設定ファイルです。また、**MyMonitor.err** はプラグインを実行した場合に出力されるエラーを書き込むファイルです。+</file>
  
-=== pandora_agent_daemon の再起動 ===+''MyMonitor.pl'' is the agent plugin, ''MyMonitor.conf'' is the configuration file passed as an argument, and ''MyMonitor.err'' is a file that will receive possible errors from the plugin execution and keep the standard output clean.
  
-The Software Agent will run the plugins every five minutes. For those people who can not wait, it is possible to restart the Software Agent from the command line.+''MyMonitor.pl'' はエージェントプラグインで、''MyMonitor.conf'' は引数として渡される設定ファイルです。また、''MyMonitor.err'' はプラグインを実行した場合に出力されるエラーを書き込むファイルです。 
 + 
 +<wrap #ks3_2 /> 
 + 
 +==== pandora_agent_daemon の再起動 ==== 
 + 
 +The Software Agent will run the plugins every minutes and it is possible to restart the Software Agent with user **root** or equivalent from the command line:
  
 ソフトウエアエージェントは 5分ごとにプラグインを実行します。次回の実行まで待てない場合は、コマンドラインからソフトウエアエージェントを再起動します。 ソフトウエアエージェントは 5分ごとにプラグインを実行します。次回の実行まで待てない場合は、コマンドラインからソフトウエアエージェントを再起動します。
  
-例:+<code bash> 
 +systemctl restart pandora_agent_daemon
  
-  /etc/init.d/pandora_agent_daemon restart 
  
-=== プラグインのパーミッションの確認 === +</code>
-プラグインおよび利用するファイルは、リード、ライト、実行の**権限を正しく設定する**必要があります。Unix であれば、次のようにします。+
  
-  chmod 755 <プラグインファイル>+<wrap #ks3_3 />
  
-=== 出力の確認 === 
-エラーを見つける簡単な方法は、コマンドラインで**プラグインを手動実行**することです。注意して**出力結果を確認**してください。例えば、次のように実行します。 
  
-<code> +==== プラグインのパーミッションの確認 ==== 
-popeye:/etc/pandora/plugins # ./pandora_df  + 
-<module> +The plugin and the files to be used **must have the correct** read, write and execute permissions
-<name><![CDATA[/dev/sda2]]></name> + 
-<type><![CDATA[generic_data]]></type> +プラグインおよび利用するファイルは、リード、ライト、実行の**権限を正しく設定する**必要があります。Unix であれば、次のようにします。 
-<data><![CDATA[19]]></data+ 
-<description>% of usage in this volume</description+<code bash
-</module> +chmod 755 plugin_path 
-<module> +
-<name><![CDATA[udev]]></name> +
-<type><![CDATA[generic_data]]></type> +
-<data><![CDATA[1]]></data> +
-<description>% of usage in this volume</description> +
-</module>+
 </code> </code>
  
-=== XMLの確認 ===+<wrap #ks3_4 />
  
-The XML that prints the plugin **must have valid XML syntax**. 
-The XML also **needs to be well formed**. To check if it is, you could follow this steps from the command line: 
  
-プラグインが出力する XML は、**正しい XML 書式である必要があります**。 +==== 出力の確認 ====
-XML はまた、**正しく整形されている必要があります**。それを確認するためには、コマンドラインから次の手順を実行します。+
  
-  - Create an XML document with the plugin output: //./Plugin.pl > Plugin.xml// +A better way to find the errors is to **run the plugin manually** in command line. **The result or output of the execution should be carefully checked**.
-  - Check the XML document: //xmllint Plugin.xml//+
  
-  - プラグインの出力を xml ファイルに落します。: //./Plugin.pl > Plugin.xml// +エラーを見つける簡単な方法は、コマンドラインで**プラグインを手動実行**するこす。注意して**出力結果確認**てください
-  - xml ファイルの書式チェックます: //xmllint Plugin.xml//+
  
-=== デバッグモード === +<wrap #ks3_5 />
-//pandora_agent.conf// ファイル内で、//debug// の値を 0 から 1に変更することで、デバッグモードを有効にすることができます。これを行うと、ソフトウエアエージェントがプラグインを実行した結果が、エージェントのその他の情報とあわせて xml ファイルに保存されます。+
  
-ファイル名は、エージェント名と //.data// を含むもので、///tmp// ディレクトリに保存されます(pandoraエージェントのログは、/var/log/pandora/pandora_agent.log を確認してください)。内容を確認し、期待したプラグインの実行結果が含まれているかどうかを見ます。+==== XMLの確認 ==== 
 + 
 +The XML produced by the plugin **must have a valid XML syntax**. To check you can follow these two steps from the command line (you must have ''xmllint'' installed): 
 + 
 +プラグインによって生成された XML は、**正しい XML 構文である必要があります**。確認するには、コマンドラインから次の 2 つの手順を実行します (''xmllint'' がインストールされている必要があります)。 
 + 
 +  - Create an XML document with the plugin output: ''./Plugin.pl > Plugin.xml''
 +  - Checking the XML document: ''xmllint Plugin.xml''
 + 
 +  - プラグインの出力を xml ファイルに落とします。: ''./Plugin.pl > Plugin.xml'' 
 +  - xml ファイルの書式をチェックします。: ''xmllint Plugin.xml'' 
 + 
 +<wrap #ks3_6 /> 
 + 
 +==== デバッグモード ==== 
 + 
 +You can activate the development mode by changing the value of the debug tag in the ''pandora_agent.conf'' file from ''0'' to ''1''. Once you have done this, when the Software Agent executes the plugin, the results will be saved in an XML document with all the agent information. 
 + 
 +''pandora_agent.conf'' ファイル内で、debug の値を ''0'' から ''1'' に変更することで、デバッグモードを有効にすることができます。これを行うと、ソフトウエアエージェントがプラグインを実行した結果が、エージェントのその他の情報とあわせて xml ファイルに保存されます。 
 + 
 +The name of the document will be the name of the agent with the extension ''.data'', and it will be located in the '''tmp''' directory (you should check the log of the PFMS agent in ''/var/log/pandora/pandora_agent.log''). By reviewing the document, you will be able to see if the plugin data is being collected and if it is as expected. 
 + 
 +ファイル名は、エージェント名と ''.data'' を含むもので、''tmp'' ディレクトリに保存されます(Pandora FMS エージェントのログは、''/var/log/pandora/pandora_agent.log'' を確認してください)。内容を確認し、期待したプラグインの実行結果が含まれているかどうかを見ます。 
 + 
 +<WRAP center round tip 90%> 
 + 
 +When you enable Debug mode, the agent runs only once and then exits. 
 + 
 +</WRAP> 
 + 
 +<WRAP center round tip 90%>
  
-<WRAP center round tip 60%> 
 デバッグモードを有効にすると、エージェントは 1回の実行で終了します。 デバッグモードを有効にすると、エージェントは 1回の実行で終了します。
 +
 </WRAP> </WRAP>
  
-=== フォーラム === +<wrap #ks3_7 /> 
-それでもまだうまくいかない場合は、我々の [[http://www.openideas.info/smf/|フォーラム]] (日本語フォーラムは [[http://openideas.info/smf/index.php/board,30.0.html|こちら]]) で聞いてみてください。+ 
 +==== フォーラム ==== 
 + 
 +If after all the error persists, [[https://pandorafms.com/community/|you can ask in the PFMS forum]]. 
 + 
 +それでもまだうまくいかない場合は、我々の [[https://pandorafms.com/community/|フォーラム]] で聞いてみてください。
  
 [[ja:documentation:start|Pandora FMS ドキュメント一覧に戻る]] [[ja:documentation:start|Pandora FMS ドキュメント一覧に戻る]]
  
  • ja/documentation/pandorafms/technical_reference/06_anexo_agent_plugins.1716443058.txt.gz
  • 最終更新: 2024/05/23 05:44
  • by junichi