[comment]: # translation:outdated

[comment]: # ({70a6015a-70a6015a})
# 5 ユーザーパラメーター

[comment]: # ({/70a6015a-70a6015a})

[comment]: # ({2f2b2ee2-9a4b2756})
#### 概要

Zabbixにあらかじめ定義されていないエージェントチェックを実行したい場合があります。<br>
このような場合、ユーザパラメータが役に立ちます。

必要なデータを取得するコマンドを作成し、そのデータをユーザパラメータとして[agent configuration file](/manual/appendix/config/zabbix_agentd)('UserParameter') という設定パラメータを作成します。

ユーザパラメータは次のような構文になります。

    UserParameter=<key>,<command>

このように、ユーザパラメータにはキーも含まれます。キーは、item を設定する際に必要となります。<br>
参照しやすい任意のキーを入力します(ホスト内で一意でなければなりません)。<br>

agent を再起動するか、agent [runtime control](/manual/concepts/agent#runtime_control) オプションを使用して、新しいパラメータを取得します。

    zabbix_agentd -R userparameter_reload 

次に、[configuring an item](item)の際に、実行したいユーザパラメータからコマンドを参照するためのキーを入力します。

ユーザパラメータとは、Zabbix agent が実行するコマンドのことです。item のプリプロセスステップの前に<br>
最大512KBのデータを返すことができます。ただし、最終的にデータベースに保存できるテキスト値は、<br>
MySQLでは64KBに制限されていることに注意してください。<br>
(他のデータベースについては、[table](/manual/config/notifications/action/operation/remote_command#overview)を参照してください)。

UNIX オペレーティングシステムでは、コマンドラインインタプリタとして **/bin/sh** が使用されます。<br>
ユーザーパラメータはエージェントチェックのタイムアウトに従います。タイムアウトに達すると<br>
フォークされたユーザーパラメータ・プロセスが終了します。<br>

こちらもご覧ください。

- ユーザーパラメータを利用するための [Step-by-step tutorial](/manual/config/items/userparameters/extending_agent) 
- [Command execution](/manual/appendix/command_execution) 

[comment]: # ({/2f2b2ee2-9a4b2756})

[comment]: # ({53dfad45-53dfad45})
##### 単純なユーザーパラメータの例

単純なコマンド:

    UserParameter=ping,echo 1

agent は、'ping' キーを持つ item に対して常に '1' を返します。

より複雑な例:

    UserParameter=mysql.ping,mysqladmin -uroot ping | grep -c alive

agent は、MySQL サーバが生きている場合は '1' を、そうでない場合は '0' を返します。

[comment]: # ({/53dfad45-53dfad45})

[comment]: # ({ecc909a7-e619711f})
#### フレキシブルユーザーパラメータ

フレキシブルユーザーパラメータは、キーでパラメータを受け取ります。<br>
このように、フレキシブルユーザーパラメータは、複数の item を作成するためのベースとなることができます。

フレキシブルユーザーパラメーターの構文は以下の通りです。

    UserParameter=key[*],command

|パラメータ|説明|
|---------|-----------|
|**Key**|Unique item key. The \[\*\] defines that this key accepts parameters within the brackets.<br>Parameters are given when configuring the item.|
|**Command**|Command to be executed to evaluate value of the key.<br>*For flexible user parameters only*:<br>You may use positional references $1…$9 in the command to refer to the respective parameter in the item key.<br>Zabbix parses the parameters enclosed in \[ \] of the item key and substitutes $1,...,$9 in the command accordingly.<br>$0 will be substituted by the original command (prior to expansion of $0,...,$9) to be run.<br>Positional references are interpreted regardless of whether they are enclosed between double (") or single (') quotes.<br>To use positional references unaltered, specify a double dollar sign - for example, awk '{print $$2}'. In this case `$$2` will actually turn into `$2` when executing the command.|

::: noteimportant
Zabbix agent では、柔軟なユーザパラメータの場合のみ、$記号を含む位置参照が検索され、置換されます。<br>
シンプルなユーザパラメータでは、このような参照処理はスキップされるため、$記号の引用は必要ありません。
:::

::: noteimportant
デフォルトでは、ユーザパラメータに特定のシンボルを使用することはできません。
全リストは [UnsafeUserParameters](/manual/appendix/config/zabbix_agentd) ドキュメントを参照してください。
:::

[comment]: # ({/ecc909a7-e619711f})

[comment]: # ({5c6e8e3c-5c6e8e3c})
##### 例1

とてもシンプルなもの:

    UserParameter=ping[*],echo $1

ping\[something\]というフォーマットを持つ監視項目は無制限に定義することができる。

-   ping\[0\] - 常に '0' を戻す
-   ping\[aaa\] - 常に 'aaa' を戻す

[comment]: # ({/5c6e8e3c-5c6e8e3c})

[comment]: # ({db2a6e16-db2a6e16})
##### 例2

もっとセンスを磨こう!

    UserParameter=mysql.ping[*],mysqladmin -u$1 -p$2 ping | grep -c alive

このパラメータは、MySQLデータベースの可用性を監視するために使用することができます。<br>
ユーザー名とパスワードを渡すことができます:

    mysql.ping[zabbix,our_password]

[comment]: # ({/db2a6e16-db2a6e16})

[comment]: # ({dd3ac3fa-dd3ac3fa})
##### 例3

正規表現にマッチする行はファイル中に何行あるか？

    UserParameter=wc[*],grep -c "$2" $1

このパラメータは、ファイル内の行数を計算するために使用することができます。

    wc[/etc/passwd,root]
    wc[/etc/services,zabbix]

[comment]: # ({/dd3ac3fa-dd3ac3fa})

[comment]: # ({d2e04f43-a5d86054})
#### コマンドの結果

コマンドの戻り値は、標準出力と標準エラー出力です。

::: noteimportant
標準エラー出力の場合、テキスト（文字、ログ、テキスト型情報）item は未サポ―トになりません。
:::

テキスト（文字、ログ、テキスト型情報）を返すユーザーパラメータは、空白を返すことができます。<br>
無効な結果を返した場合、そのitem は サポートされなくなります。

[comment]: # ({/d2e04f43-a5d86054})
