ja:documentation:08_technical_reference:05_anexo_server_plugins_development

差分

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

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
ja:documentation:08_technical_reference:05_anexo_server_plugins_development [2021/07/16 22:40] – [プラグインマクロ] junichija:documentation:08_technical_reference:05_anexo_server_plugins_development [Unknown date] (現在) – 削除 - 外部編集 (Unknown date) 127.0.0.1
行 1: 行 1:
-====== サーバプラグイン開発 ======  
-{{indexmenu_n>5}} 
  
-[[ja:documentation:start|Pandora FMS ドキュメント一覧に戻る]] 
- 
-===== サーバプラグイン開発 ===== 
- 
-==== サーバプラグインの基本機能 ==== 
- 
-{{  :wiki:pfms-servers-plugins.png?500x350  |サーバ(Servers) -> プラグイン(Plugins)}} 
- 
-サーバプラグインは、Pandora FMS プラグインサーバにより実行されるため、次に示す特別な機能を備えている必要があります。 
- 
-  * プラグインの実行では単一の値を返す必要があります。サーバプラグインは、プラグインモジュールによって実行されるためです。 
- 
-  * リモートで監視対象のリソースにアクセスできる必要があります。 
- 
-  * Pandora サーバのインストール先の OS がサポートする任意のプログラミング言語を利用することができます。 
- 
-  * プラグインの実行に必要な依存ソフトウエアは、Pandora サーバを実行するのと同一のマシンにインストールされている必要があります。 
- 
-You may find more information about monitoring with remote server plugins [[:en:documentation:03_monitoring:03_remote_monitoring#monitoring_with_server_remote_plugins|here]]. There you will find simple exambles and how the modules and agents they contain work. In this article server plugin creation is analyzed in depth. 
- 
-リモートサーバプラグインを使った監視に関する詳細は、[[:ja:documentation:03_monitoring:03_remote_monitoring#monitoring_with_server_remote_plugins|こちら]]を確認してください。そこには、簡単な例と、モジュールとエージェントがどのように機能するかが記載されています。 この記事では、サーバプラグインの作成について詳しく示します。  
- 
-==== サーバプラグイン開発 ==== 
-次に、Pandora FMS のサーバプラグインの例を説明します。 
- 
-以下のプラグインは、インタフェースの入出力トラフィックの合計を返します。データは SNMP で取得します。 
- 
-プラグインのコードは次の通りです。 
- 
-<code> 
-#!/usr/bin/perl -w 
- 
-use strict; 
-use warnings; 
- 
-sub get_param($) { 
-        my $param = shift; 
-        my $value = undef; 
- 
-        $param = "-".$param; 
- 
-        for(my $i=0; $i<$#ARGV; $i++) { 
- 
-                if ($ARGV[$i] eq $param) { 
-                        $value = $ARGV[$i+1]; 
-                        last; 
-                } 
- 
-        } 
-        return $value; 
-} 
- 
-sub usage () { 
-        print "iface_bandwith.pl version v1r1\n"; 
-        print "\nusage: $0 -ip <device_ip> -community <community> -ifname <iface_name>\n"; 
-        print "\nIMPORTANT: This plugin uses SNMP v1\n\n"; 
-} 
- 
-#Global variables 
-my $ip = get_param("ip"); 
-my $community = get_param("community"); 
-my $ifname = get_param("ifname"); 
- 
-if (!defined($ip) || 
-        !defined($community) || 
-        !defined($ifname) ) { 
-        usage(); 
-        exit; 
-} 
- 
-#Browse interface name 
-my $res = `snmpwalk -c $community -v1 $ip .1.3.6.1.2.1.2.2.1.2 -On`; 
- 
-my $suffix = undef; 
- 
-my @iface_list = split(/\n/, $res); 
- 
-foreach my $line (@iface_list) { 
- 
-        #Parse snmpwalk line 
-        if ($line =~ m/^([\d|\.]+) = STRING: (.*)$/) { 
-                my $aux = $1; 
- 
-                #Chec if this is the interface requested 
-                if ($2 eq $ifname) { 
- 
-                        my @suffix_array = split(/\./, $aux); 
- 
-                        #Get last number of OID 
-                        $suffix = $suffix_array[$#suffix_array]; 
-                } 
-        } 
-} 
- 
-#Check if iface name was found 
-if (defined($suffix)) { 
-        #Get octets stats 
-        my $inoctets = `snmpget $ip -c $community -v1 .1.3.6.1.2.1.2.2.1.10.$suffix -OUevqt`; 
-        my $outoctets = `snmpget $ip -c $community -v1 .1.3.6.1.2.1.2.2.1.16.$suffix -OUevqt`;  
- 
-        print $inoctets+$outoctets; 
-} 
-</code> 
- 
-このコードの重要な説明は、利用方法の関数にあります。 
- 
-<code> 
-sub usage () { 
-        print "iface_bandwith.pl version v1r1\n"; 
-        print "\nusage: $0 -ip <device_ip> -community <community> -ifname <iface_name>\n"; 
-        print "\nIMPORTANT: This plugin uses SNMP v1\n\n"; 
-} 
-</code> 
- 
-この関数では、バージョンおよびプラグインの利用方法を説明しています。これはとても重要で、パラメータを指定せずにプラグインを実行するかまたは -h や --help を指定してプラグインを実行した場合に常に表示される必要があります。 
- 
-プラグインが返す値に関しては、最後から 2行目に標準出力に表示する以下のようなコマンドがあります。 
- 
-  print $inoctets+$outoctets; 
- 
-見ての通り、プラグインが返す値は単一のデータで、これを Pandora プラグインサーバが関連モジュールにデータとして追加します。 
- 
-このプラグインを実行するには、Pandora サーバを実行するマシンに //snmpwalk// および //snmpget// コマンドをインストールする必要があります。 
- 
-==== プラグインの手動登録 ==== 
- 
-{{ wiki:Registro_manual_plugin.png?750 }} 
- 
- 
-  * **名前(Name)** 
- 
-プラグインの名前です。 
- 
-  * **プラグインタイプ(Plugin type)** 
- 
-プラグインには、標準プラグインと Nagios の2種類があります。 標準プラグインは、アクションを実行してパラメータを受け取るスクリプトです。 Nagios プラグインは、その名前が示すように、Nagios で利用できる形式のプラグインです。主な違いは、テストが成功したかどうかを Nagios プラグインはエラーレベルで示すことです。 
- 
-もし Nagios プラグインを使いたい場合で(OK/NG ではなく)データを取得したい場合は、Nagios プラグインを "標準" モードで利用します。 
- 
-  * **最大タイムアウト(Max. timeout)** 
- 
-プラグインの実行時間制限です。 この時間内に応答がない場合は、モジュールを不明として処理し、その値は更新されません。 プラグインを使用してモニタリングを実装する場合、これは非常に重要な要素です。そのため、プラグインの実行にかかる時間がこの数値より大きいと値を取得できません。この値は、プラグインとして使用されるスクリプトや実行ファイルが値を返すまでにかかる時間よりも常に大きくなければなりません。 何も設定しない場合は、plugin_timeout の設定値が使われます。 
- 
-  * **プラグインコマンド(Plug-in command)** 
- 
-プラグインコマンドのパスです。デフォルトインストールでのプラグインディレクトリは、/usr/share/pandora_server/util/plugin/ です。ただし、任意の場所を指定することができます。ここでは、フィールドに /usr/share/pandora_server/util/plugin/udp_nmap_plugin.sh を指定しています。 
- 
-サーバは、このスクリプトを実行します。そのため、読み取りおよび実行権限がある必要があります。 
- 
-  * **プラグインパラメータ(Plug-in parameters)** 
- 
-コマンドのパラメータ文字列で、コマンドの引数としてしていするものです。パラメータフィールドには、_field1_ _field2_ ... _fieldN_ といったマクロが使えます。 
- 
-  * **パラメータマクロ(Parameters macros)** 
- 
-プラグインパラメータフィールドで使うマクロを追加することができます。このマクロは、モジュール設定の通常のテキストフィールドとして表示されます。 
- 
-==== プラグインマクロ ==== 
- 
-Conside the **DNS Plugin** installed by default in Pandora FMS server. 
- 
-Pandora FMS サーバにデフォルトでインストールされている **DNSプラグイン** について考えてみます。  
- 
-{{  :wiki:pfms-plugins-registered-dns-plugin.png?700  }} 
- 
-Said plugin, [[:en:documentation:03_monitoring:03_remote_monitoring#example_3_-_dns_server_remote_plug_in|among other uses]], allows for a web domain and its corresponding IP to be checked by a DNS server. 
- 
-[[:ja:documentation:03_monitoring:03_remote_monitoring#例3dns_サーバリモートプラグイン|このプラグイン]]を使用すると、Webドメインとそれに対応する IP を DNS サーバでチェックできます。  
- 
-  * ''-i '': Known domain IP address. 
-  * ''-d '': Corresponding web domain. 
-  * ''-s '': DNS server for checking. Knowing these three parameters, proceed to [[:en:documentation:08_technical_reference:05_anexo_server_plugins_development#plugin_manual_registration|manually register]] a new plugin, add the name“New DNS Plugin” and in the description copy the previous summary and **in addition**  indicate that it is necessary for the Module to retrive a false value (0) or true (1) for monitoring. This type of data is also known as boolean and in Pandora FMS it is called ''generic_proc ''. 
-In the section **Macro parameters **add three macro fields **field1**, **field2**  and **field3**. 
- 
-  * ''-i '': 既知のドメインの IP アドレス。 
-  * ''-d '': 対応する Web ドメイン。 
-  * ''-s '': チェックする DNS サーバ。 
- 
-これらの3つのパラメータで、新しいプラグインの[[:ja:documentation:08_technical_reference:05_anexo_server_plugins_development#プラグインの手動登録|手動登録]]に進み、"New DNS Plugin" 
-という名前で、説明に前の概要をコピーします。**さらに** 監視のためにモジュールが false(0) または true(1) を取得する必要があることを示します。 このタイプのデータはブール値とも呼ばれ、Pandora FMS では ''generic_proc'' と呼ばれます。 
-セクション **マクロパラメータ(Macro parameters)** に、3つのマクロフィールド **field1**, **field2** および **field3** を追加します。  
- 
-For ''_field1_''  add the description according to the ''-i''  parameter and so on for parameters ''-d ''  and ''-s ''. Leave the values by **default**  empty, type in in the **Help **of each one of them the text you wish. 
- 
-'' _field1_'' では、パラメーター ''-i'' に関する説明を追加します。同様に、''-d'' および ''-s'' の説明を追加します。 **デフォルト(default)** の値を空のままにし、それぞれの **ヘルプ(Help)** に必要なテキストを入力します。  
- 
-In the text box **Plugin command**  type in: 
- 
-テキストボックスに **プラグインコマンド** を入力します。 
-<code> 
- 
-/usr/share/pandora_server/util/plugin/dns_plugin.sh 
- 
-</code> 
- 
-In the **Plugin parameters**  text box, type in: 
- 
-**プラグインパラメータ(Plugin parameters)** ボックスに入力します。 
- 
-<code> 
--i _field1_ -d _field2_ -s _field3_ 
- 
-</code> 
- 
-[[http://dokuwiki.pandorafms.com/dokuwiki/_detail/es/documentation/08_technical_reference/pfms-servers-plugins-command-parameters.png?id=es:documentation:08_technical_reference:05_anexo_server_plugins_development|{{http://dokuwiki.pandorafms.com/dokuwiki/_media/es/documentation/08_technical_reference/pfms-servers-plugins-command-parameters.png?nolink&600}}]] 
- 
-<WRAP center round box 60%> \\ When this plugin is used within the module, the **DNS Plugin**  will be executed replacing each of the fields by the parameters written on the Module. \\ </WRAP> 
- 
-<WRAP center round box 60%> \\ このプラグインをモジュールで利用する際には、それぞれのフィールドはモジュールのパラメータに置き換えられ **DNS Plugin** が実行されます。 \\ </WRAP> 
- 
-<code> 
- 
-/usr/share/pandora_server/util/plugin/dns_plugin.sh -i _field1_ -d _field2_ -s _fiel 
- 
-</code> 
- 
-=== パフォーマンス === 
- 
-Macros work like **_field1_**, **_field2_**, (…), **_fieldN**_, but they host special values both from the Modules and the Agents those Modules contain. 
- 
-Going back to the example of the previous section where the default values of the **_fieldN_** were left blank. Edit it for the default value of ''_field2_'' and add the macro ''_module_''. 
- 
-<WRAP center round important 60%>\\ 
-If any module or component is using that server plugin, a lock icon that cannot be updated will appear.\\ 
-</WRAP> 
- 
-The ''_module_'' macro returns the Module the plugin uses and will be added to the user or policy when said Module is created. To verify this, create a new Agent called "DNS verify" and a new Module through the option **Create a new plugin server module**: 
- 
-{{  :es:documentation:08_technical_reference:pfms-resources-manage_agents-modules-create_new_plugin_server_module.png?700  }}\\ 
-Once you are again in the new Module editing form, in **Plugin** select the "New DNS Plugin" list and the ''_module_'' macro will appear like this: 
- 
-{{:wiki:pfms-resources-manage_agents-modules-create_new_plugin_server_module_2.png?750}}Rememeber to add that the type of data to be collected must be "Generic boolean" **and for the name of the new Module, just add the web domain whose IP address you are going to verify with a specified DNS server****.** Save it and check it works. 
- 
-The advantage of this method is that it will have both Modules and Web domains you need to check and they are easily identified in different components (Dashboards, reports, etc.) through its name. 
- 
-==== PSPZ パッケージ ==== 
-=== Pandora サーバプラグイン Zip ファイル (.pspz) === 
-Pandora FMS 3.0では、プラグインおよび新しいプラグインを(プラグインに依存した、モジュールのライブラリのように)使用するモジュールを登録する新しい方法があります。基本的には、以下で説明する.pspzフォーマットのファイルをアップロードする管理コンソール拡張機能です。システムでファイルを読み込み、展開後、バイナリファイルとスクリプトをシステムにインストールし、Pandora FMSのモジュールライブラリへのプラグインの登録と.pspzファイル中で定義されたすべてのモジュール生成を行います。 
- 
-この節では、.pspzファイルの作成方法について説明します。 
- 
-=== パッケージファイル === 
-.pspz ファイルは2つのファイルからなるzipファイルです。 
- 
-**plugin_definition.ini**: プラグインとモジュールの仕様を含むファイル。ファイル名(大文字と小文字は区別されます)は固定です。 
- 
-**<script_file>**: プラグインスクリプトもしくはバイナリファイルそのもの。ファイル名は自由につけることができます。[[https://pandorafms.com/library/openldap-plugin/|ここ]] に、.pspzファイルのサンプル(ファイル名は.zipに変更されています)があります。 
- 
-=== plugin_definition.ini の構造 === 
-== ヘッダー/定義 == 
-これがオプションセクションを持つ標準的なINIファイルです。 
-最初のセクションは最も重要で、セクション名は"plugin_definition"固定です。 
-以下に例を示します。 
- 
-<code> 
-[plugin_definition] 
-name = Remote SSH exec 
-filename = ssh_pandoraplugin.sh 
-description = This plugin execute remotely any command provided 
-timeout = 20 
-ip_opt = -h 
-execution_command =  
-execution_postcommand =  
-user_opt = -u 
-port_opt =  
-pass_opt =  
-plugin_type = 0 
-total_modules_provided = 1 
-</code> 
- 
-**filename**: 先に<script_file>で参照されていた、.pspzファイルに含まれるスクリプト名と同じ値となります。このサンプルでは"ssh_pandoraplugin.sh"というシェルスクリプトです。 
- 
-*** _opt**: プラグインに登録するオプションを指定します。Pandora FMSコンソールで"手動で"プラグインを登録するフォームに表示されるものと同様のものです。 
- 
-**plugin_type**: 標準的なPandora FMSプラグインの場合は0、Nagiosタイププラグインの場合は1を指定します。 
- 
-**total_modules_provided**: 以下で定義するモジュールの数を指定します。必要最小限の値を指定してください(XXX) 
- 
-**execution_command**: 値が設定された場合、スクリプトの前に値が追加されます。"java -jar"といったインタプリタを指定する際に設定されます。したがって、プラグインはPandora FMSプラグインサーバから"java -jar <plugin_path>/<plugin_filename>"と実行されます。 
- 
-**execution_postcommand**: 値が設定された場合、追加パラメータがplugin_filenameの後にプラグインに渡されます。追加パラメータはユーザには見えません。 
- 
-== モジュール定義 / ネットワークコンポーネント == 
-これは動的セクション(セクション名に増加する数値を持つ)として定義され、必要な数だけ作成することができます。ここで定義したモジュール数と同じ値を、前のセクションの**total_modules_provided**に設定する必要があります。 
-もし4個のモジュールがある場合、セクション名はmodule1, module2, module3, module4となります。 
- 
-以下にモジュール定義の例を示します。 
- 
-<code> 
-[module1] 
-name = Load Average 1Min 
-description = Get load average from command uptime 
-id_group = 12 
-type = 1 
-max = 0 
-min = 0 
-module_interval = 300 
-id_module_group = 4 
-id_modulo = 4 
-plugin_user = root 
-plugin_pass =  
-plugin_parameter = "uptime | awk '{ print $10 }' | tr -d ','" 
-max_timeout = 20 
-history_data = 1 
-min_warning = 2 
-min_critical = 5 
-str_warning = "peligro" 
-min_critical = "alerta" 
-min_ff_event = 0 
-tcp_port = 0 
-critical_inverse = 0 
-warning_inverse = 0 
-critical_instructions = "Call head of department" 
-warning_instructions = "Calling the server manager to reduce the load" 
-unknown_instructions = "Verify that Pandora FMS agent is running" 
-</code> 
- 
-注意すべき点がいくつかあります。 
- 
-  * どのフィールドも"忘れない"こと。すべてのフィールドが必須となっています。設定値がない場合は、上記例の//plugin_pass//フィールドのように空白にしておくこと 
-  * 上記例の//plugin_parameter//フィールドのように、特殊文字や空白を含む値を定義する場合はダブルクォートで囲むこと。INIファイル中に ' " / - _ ( ) [[pandora:documentation_ja:start]] と言った文字を含む場合はダブルクォートを使用すること。データ中に " を含まないようにしましょう。もし必要になった場合は \" とエスケープしましょう 
-  * フィールドの意味や目的がよくわからない場合は、Pandora FMS データベースの tnetwork_component を参照してください。ほとんど同じフィールドがあります。ネットワークコンポーネントを作成する時は、利用するプラグインとデータベースに保存される全ての値を確認しながら作成してみてください。 
-  * **id_module**の値は常に4(これがプラグインモジュールであることを意味します)です。 
-  * **type**はモジュールの種類を指定します。ttipo_moduloテーブルでgeneric_data (1), generic_proc (2), generic_data_string (3), generic_data_inc (4)が定義されています。 
-  * **id_group**はグループ定義を含むtgrupoテーブルのPK(プライマリキー)を設定します。1は"全グループ"を意味し、特別なグループのようにふるまいます。 
-  * **id_module_group**の値はtmodule_groupテーブルを参照しており、XXXX。"1"を設定することで、一般モジュールグループを指定できます。 
- 
-=== バージョン2 === 
-Pandora FMS v5.1 SP1 から、サーバプラグインはマクロを利用します。 
- 
- 
-<WRAP center round important 60%> 
-これらのプラグインは、**.pspz2** という拡張子で区別されます。 
-</WRAP> 
- 
-また、plugin_definition.ini が変更になっています。次のフィールドが追加されました。 
- 
-//plugin_definition//セクション: 
-  * //total_macros_provided// プラグインが持つ動的マクロの数を定義します。 
- 
-//module<N>//セクション 
-  * //macro_<N>_value// 動的マクロを使ったモジュールの値を定義します。存在しない場合はデフォルト値が利用されます。 
- 
-そして、それぞれの動的マクロ用の次のような新たなセクションが作られています。 
- 
-<code> 
-[macro_<N>] 
-hide = 0 
-description = descripción 
-help = texto de ayuda 
-value = valor 
-</code> 
- 
-この新たな構造をバージョン2 とします。 
- 
-<WRAP center round tip 60%> 
-//execution_postcommand// の部分に指定したマクロの置換 (_fieldx_) を明示的に呼び出す必要があります。以下の例を参照してください。 
-</WRAP> 
- 
-<WRAP center round tip 60%> 
-以前のバージョンとの互換性もあります。バージョンパラメータが定義されてなければ、バージョン1 と想定します。 
-</WRAP> 
- 
-== バージョン2 のプラグイン定義例 == 
- 
-<code> 
-[plugin_definition] 
-name = PacketLoss 
-filename = packet_loss.sh 
-description = "Measure packet loss in the network in %" 
-timeout = 20 
-ip_opt =  
-execution_command =  
-execution_postcommand =  
-parameters = _field1_ _field2_ 
-user_opt =  
-port_opt =  
-pass_opt =  
-plugin_type = 0 
-total_modules_provided = 1 
-total_macros_provided = 2 
- 
-[macro_1] 
-hide = 0 
-description = Timeout 
-help = Timeout in seconds 
-value = 5 
- 
-[macro_2] 
-hide = 0 
-description = Target IP 
-help = IP adddress 
-value = 127.0.0.1 
- 
-[module1] 
-name = Packet loss 
-description = "Measure target packet loss in % " 
-id_group = 15 
-type = 4 
-max = 0 
-min = 0 
-module_interval = 300 
-id_module_group = 2 
-id_modulo = 1 
-max_timeout = 20 
-history_data = 1 
-min_warning = 30 
-min_critical = 40 
-min_ff_event = 0 
-tcp_port = 0 
-macro_1_value = 5 
-macro_2_value = localhost 
-unit = % 
-</code> 
- 
-===== 古い PSPZ (Pandora バージョン 4) のアップグレード ===== 
- 
-サーバプラグインの動的パラメータが無い、パラメータが静的な以前の PSPZ は、新しいバージョンの pandora では動作しません。これを修正する手順は以下にあります。 
- 
-[[:ja:documentation:02_installation:02_anexo_upgrade#.E3.83.97.E3.83.A9.E3.82.B0.E3.82.A4.E3.83.B3|以前のバージョンからのアップグレード → メジャーバージョンのアップデート → バージョン 4.x から 5.0 へのアップデート → プラグイン]] 
  • ja/documentation/08_technical_reference/05_anexo_server_plugins_development.1626475224.txt.gz
  • 最終更新: 2021/07/16 22:40
  • by junichi