[comment]: # ({188108fa-226b9489})
# 1 トリガーの例

このページはトリガーの例のコレクションです。

例はユースケースごとに分類されています:

-   [利用できないホスト](#detect-unavailable-host)
-   [利用できないプロキシ](#detect-unavailable-proxy)
-   [利用できないSMTPクラスタ](#detect-unavailable-smtp-cluster)
-   [到達できないホスト](#detect-unreachable-host)
-   [予期しないリブート](#detect-unexpected-reboot)
-   [重要なファイルの変更](#detect-changes-in-important-files)
-   [DNSクエリの変更](#detect-changes-in-dns-query)
-   [異なるホストで一致しないソフトウェア](#detect-non-matching-software-on-different-hosts)
-   [同期していないクロック](#detect-unsynchronized-clocks)
-   [古いエージェント](#detect-outdated-agent)
-   [フラッピングインターフェース](#detect-flapping-interface)
-   [高い受信トラフィック](#detect-high-incoming-traffic)
-   [ディスク容量不足](#detect-low-disk-space)
-   [ディスク容量不足（動的しきい値）](#detect-low-disk-space-dynamic-threshold)
-   [高いCPU負荷](#detect-high-cpu-load)
-   [CPU負荷の比較](#compare-cpu-loads)
-   [長期的なCPU負荷の比較](#compare-cpu-loads)
-   [特殊文字を含む文字列](#detect-string-containing-special-characters)

[comment]: # ({/188108fa-226b9489})

[comment]: # ({2116104b-1b661572})
##### 利用できないホストの検出

```default
max(/host/zabbix[host,agent,available],5m)=0
```
このトリガーは、ホスト上のZabbixエージェントが5分間利用できない場合に発生します。<br>
関数: [`max`](/manual/config/triggers/expression/aggregate#max)<br>
データアイテム: [`zabbix[host,agent,available]`](/manual/config/items/itemtypes/internal#hostavailable)

代替案:

```default
nodata(/host/agent.ping,5m)=1
```

このトリガーは、Zabbixエージェントから5分間データが受信されていない場合に発生します。<br>
関数: [`nodata`](/manual/config/triggers/expression/history#nodata)<br>
データアイテム: [`agent.ping`](/manual/config/items/itemtypes/zabbix_agent#agent.ping)

[comment]: # ({/2116104b-1b661572})

[comment]: # ({fedc75b0-de5361b9})
##### 利用できないプロキシの検出

```default
fuzzytime(/host/zabbix[proxy,{$PROXY_NAME},lastaccess],1m)=0
```

このトリガーは、ZabbixプロキシのデータがZabbixサーバーの時刻より1分遅れている場合に発生します。<br>
関数: [`fuzzytime`](/manual/config/triggers/expression/history#fuzzytime)<br>
データアイテム: [`zabbix[proxy,{$PROXY_NAME},lastaccess]`](/manual/config/items/itemtypes/internal#proxy)

[comment]: # ({/fedc75b0-de5361b9})

[comment]: # ({a2a7ab26-7956e04e})
##### 利用できないSMTPクラスタの検出

```default
last(/smtp1.example.com/net.tcp.service[smtp])=0 and last(/smtp2.example.com/net.tcp.service[smtp])=0
```

両方のSMTPサーバーがダウンしている場合、このトリガーが発生します。<br>
関数: [`last`](/manual/config/triggers/expression/history#last)<br>
データアイテム: [`net.tcp.service`](/manual/config/items/itemtypes/simple_checks#nettcpservice)

[comment]: # ({/a2a7ab26-7956e04e})

[comment]: # ({c2c339fa-567b88a9})
##### 到達不能なホストの検出

```default
count(/host/icmpping,30m,,"0")>5
```

このトリガーは、過去30分間に5回以上pingでホストに到達できなかった場合に発生します。<br>
関数: [`count`](/manual/config/triggers/expression/history#count)<br>
データアイテム: [`icmpping`](/manual/config/items/itemtypes/simple_checks#icmpping)

[comment]: # ({/c2c339fa-567b88a9})

[comment]: # ({e9862861-b356d712})
##### 予期しない再起動の検出

```default
change(/host/system.uptime)<0
```

システムの稼働時間の値に負の変化があった場合(再起動を示す)にこのトリガーが発生します。<br>
関数: [`change`](/manual/config/triggers/expression/history#change)<br>
データアイテム: [`system.uptime`](/manual/config/items/itemtypes/zabbix_agent#system.uptime)

[comment]: # ({/e9862861-b356d712})

[comment]: # ({1ee22f8b-49592749})
##### 重要なファイルの変更を検出する

```default
last(/host/vfs.file.cksum[/etc/passwd],#1)<>last(/host/vfs.file.cksum[/etc/passwd],#2)
```

このトリガーは、`/etc/passwd`が変更された場合に発生します。直前の`/etc/passwd`のチェックサムと最新のチェックサムが異なる場合に式が真になります。`/etc/passwd`、`/etc/inetd.conf`、`/kernel`などの重要なファイルの変更を監視するために、同様の式が役立ちます。<br>
関数: [`last`](/manual/config/triggers/expression/history#last)<br>
データアイテム: [`vfs.file.cksum`](/manual/config/items/itemtypes/zabbix_agent#vfs.file.cksum)

[comment]: # ({/1ee22f8b-49592749})

[comment]: # ({cc85e7ec-c2b4949f})
##### DNSクエリの変更を検出する

```default
last(/Zabbix server/net.dns.record[192.0.2.0,{$WEBSITE_NAME},{$DNS_RESOURCE_RECORD_TYPE},2,1])<>"{$WEBSITE_NAME}           {$DNS_RESOURCE_RECORD_TYPE}       0 mail.{$WEBSITE_NAME}"
```

2番目のオペランドの周りに引用符があることに注意してください。

このトリガーは、クエリ結果が通常返されるものと等しくない場合に発生します。

```default
example.com           MX       0 mail.example.com
```

関数: [`last`](/manual/config/triggers/expression/history#last)<br>
データアイテム: [`net.dns.record[192.0.2.0,{$WEBSITE_NAME},{$DNS_RESOURCE_RECORD_TYPE},2,1]`](/manual/config/items/itemtypes/zabbix_agent#net.dns.record)、マクロは以下のように定義されています。

```default
{$WEBSITE_NAME} = example.com
{$DNS_RESOURCE_RECORD_TYPE} = MX
```

[comment]: # ({/cc85e7ec-c2b4949f})

[comment]: # ({0fc019ff-adfc6b9d})
##### 異なるホストで一致しないソフトウェアを検出する

```default
last(/host/vfs.file.contents[/etc/os-release])<>last(/host2/vfs.file.contents[/etc/os-release])
```

このトリガーは、異なるホストでUbuntuのバージョンが異なる場合に発生します。ここでのオペランドは文字列を返す関数であることに注意してください。<br>
関数: [`last`](/manual/config/triggers/expression/history#last)<br>
データアイテム: [`vfs.file.contents`](/manual/config/items/itemtypes/zabbix_agent#vfs.file.contents)

[comment]: # ({/0fc019ff-adfc6b9d})

[comment]: # ({101c1203-0e6bfc51})
##### 同期していないクロックを検出

```default
fuzzytime(/host/system.localtime,10s)=0
```

このトリガーは、クライアントのローカル時刻とZabbixサーバーの時刻の差が10秒を超える場合に発生します。<br>
関数: [`fuzzytime`](/manual/config/triggers/expression/history#fuzzytime)<br>
データアイテム: [`system.localtime`](/manual/config/items/itemtypes/zabbix_agent#system.localtime)

[`system.localtime`](/manual/config/items/itemtypes/zabbix_agent#systemlocaltime) は、Zabbixエージェントでは [パッシブチェック](/manual/appendix/items/activepassive#passive-checks) として設定する必要があることに注意してください。Zabbixエージェント 2 では、アクティブチェックとして設定することもできます。

[comment]: # ({/101c1203-0e6bfc51})

[comment]: # ({108d71c4-62cfb014})
##### 古いエージェントの検出

```default
find(/host/agent.version,,"like","beta")=1
```

このトリガーは、Zabbixエージェントがベータバージョンの場合に発生します。Zabbixエージェントをアップグレードする必要があります。<br>
関数: [`find`](/manual/config/triggers/expression/history#find)<br>
データアイテム: [`agent.version`](/manual/config/items/itemtypes/zabbix_agent#agent.version)

[comment]: # ({/108d71c4-62cfb014})

[comment]: # ({b4fdf283-3f25a585})
##### flappingインターフェースの検出

```default
changecount(/host/vfs.file.contents["/sys/class/net/eth0/operstate"],1h)>5 
```

このトリガーは、`eth0`の運用状態(up/down/unknown)が1時間に5回以上変化した場合に発生します。<br>
関数: [`changecount`](/manual/config/triggers/expression/history#changecount)<br>
データアイテム: [`vfs.file.contents`](/manual/config/items/itemtypes/zabbix_agent#vfs.file.contents)

[comment]: # ({/b4fdf283-3f25a585})

[comment]: # ({984a4c2f-46e72843})
##### 高い受信トラフィックを検出する

```default
min(/host/net.if.in[eth0,bytes],5m)>100K
```

このトリガーは、過去5分間に`eth0`で受信したバイト数が常に100キロバイトを超えていた場合に発生します。誰かが大きなファイルをダウンロードしている可能性があります。<br>
関数: [`min`](/manual/config/triggers/expression/aggregate#min)<br>
データアイテム: [`net.if.in[eth0,bytes]`](/manual/config/items/itemtypes/zabbix_agent#net.if.in)

[comment]: # ({/984a4c2f-46e72843})

[comment]: # ({2e223320-bddf0717})
##### ディスク容量不足の検知

```default
max(/host/vfs.fs.size[/,free],5m)<10G
```

空きディスク容量が5分間連続して10GB未満の場合にトリガーが発生します。

リカバリエクスプレッションも定義できます:

```default
min(/host/vfs.fs.size[/,free],10m)>40G
```

空きディスク容量が10分間連続して40GBを超えた場合にのみ、問題が**解決**されます。<br>
関数: [`min`](/manual/config/triggers/expression/aggregate#min)<br>
データアイテム: [`vfs.fs.size`](/manual/config/items/itemtypes/zabbix_agent#vfs.fs.size)

[comment]: # ({/2e223320-bddf0717})

[comment]: # ({e2a732dc-bb0f5278})
##### ディスク容量不足の検出（動的しきい値）

```default
last(/template/hrStorageFree[{#SNMPVALUE}])<last(/template/hrStorageSize[{#SNMPVALUE}])*0.1
```

空き容量（割り当て単位）が10%未満になるとトリガーが発生します。さまざまなサイズの検出されたストレージに適用できる適応トリガーしきい値を取得するために、別のアイテムの値が使用されていることに注意してください。
関数: [`last`](/manual/config/triggers/expression/history#last)<br>

[comment]: # ({/e2a732dc-bb0f5278})

[comment]: # ({643d3a74-17b607dc})
##### 高いCPU負荷の検出

```default
last(/host/system.cpu.load[all,avg1])>5
```

平均プロセッサ負荷が1分間5を超えている場合にトリガーが発生します。

バリエーション:

```default
min(/host/system.cpu.load[all,avg1],5m)>2 and time()<060000
```
```default
min(/host/system.cpu.load[all,avg1],5m)>2 and not (dayofweek()=7 and time()>230000) and not (dayofweek()=1 and time()<010000)
```

このようなトリガーは5分間のデータを分析し、CPU負荷が2未満にならない場合にのみトリガーします。さらに、これらのトリガーは以下の場合に発生します:

-   夜間のみ (00:00-06:00)
-   週の切り替え時の2時間 (日曜日23:00～月曜日01:00) を除く任意の時間

```default
(last(/host/system.cpu.load[all,avg1])>5) + (last(/host2/system.cpu.load[all,avg1])>5) + (last(/host3/system.cpu.load[all,avg1])>5)>=2
```

このトリガーは、3つのホストのうち少なくとも2つでプロセッサ負荷が高すぎる場合に発生します。<br>
関数: [`last`](/manual/config/triggers/expression/history#last), [`min`](/manual/config/triggers/expression/aggregate#min), [`dayofweek`](/manual/config/triggers/expression/time#dayofweek), [`time`](/manual/config/triggers/expression/time#time)<br>
データアイテム: [`system.cpu.load`](/manual/config/items/itemtypes/zabbix_agent#system.cpu.load)

[comment]: # ({/643d3a74-17b607dc})

[comment]: # ({49f3b448-47b2e2fd})
##### CPU負荷の比較

```default
avg(/Zabbix server/system.cpu.load,1h)/avg(/Zabbix server/system.cpu.load,1h:now-1d)>2
```

このトリガーは、今日の平均負荷が昨日の同じ時間帯の平均負荷（`now-1d`の時間シフトを使用）を2倍以上上回った場合に発生します。<br>
関数: [`avg`](/manual/config/triggers/expression/aggregate#avg)<br>
データアイテム: [`system.cpu.load`](/manual/config/items/itemtypes/zabbix_agent#system.cpu.load)

[comment]: # ({/49f3b448-47b2e2fd})

[comment]: # ({e83bf5a3-6906462b})
##### 長期的なCPU負荷の比較

```default
trendavg(/host/system.cpu.load,1M:now/M)>1.1*trendavg(/host/system.cpu.load,1M:now/M-1M)
```

このトリガーは、ホストのCPU負荷が先月より10%以上増加した場合に発生します<br>
関数: [`trendavg`](/manual/config/triggers/expression/trends#trendavg)<br>
データアイテム: [`system.cpu.load`](/manual/config/items/itemtypes/zabbix_agent#system.cpu.load)

また、トリガー設定の[イベント名](/manual/config/triggers/trigger#configuration)フィールドを使用して、意味のあるアラートメッセージを作成することもできます。例えば、以下のようなメッセージを受け取るには

`"Exchangeサーバーの負荷が7月に24%増加しました (0.69)、6月 (0.56) と比較して"`

イベント名は次のように定義する必要があります:

```default
{HOST.HOST}サーバーの負荷が{{?100*trendavg(//system.cpu.load,1M:now/M)/trendavg(//system.cpu.load,1M:now/M-1M)}.fmtnum(0)}%増加しました。{{TIME}.fmttime(%B,-1M)} ({{?trendavg(//system.cpu.load,1M:now/M)}.fmtnum(2)})、{{TIME}.fmttime(%B,-2M)} ({{?trendavg(//system.cpu.load,1M:now/M-1M)}.fmtnum(2)}) と比較して
```

この種の問題には、トリガー設定で手動クローズを許可することも有用です。

[comment]: # ({/e83bf5a3-6906462b})

[comment]: # ({4ae4641e-60fad4fc})
##### 特殊文字を含む文字列の検出

```default
last(/host/vfs.file.contents[/tmp/hello])={$HELLO_MACRO}
```

`/tmp/hello`の内容が`{$HELLO_MACRO}`で定義された文字列と等しい場合、トリガーが発生します。

```default
{$HELLO_MACRO} = \" //hello ?\"
```

または、直接文字列と比較することもできます。

```default
last(/Zabbix server/vfs.file.contents[/tmp/hello])="\\\" //hello ?\\\""
```

特殊文字（`\\`と`"`）が直接比較される場合、どのようにエスケープされているかに注意してください。

関数: [`last`](/manual/config/triggers/expression/history#last)<br>
データアイテム: [`vfs.file.contents`](/manual/config/items/itemtypes/zabbix_agent#vfs.file.contents)

[comment]: # ({/4ae4641e-60fad4fc})

[comment]: # ({baa6a112-contribute})
::: note-contribute
他の人にも役立つ可能性のあるトリガー式の例をお持ちですか？<br>
[提案フォーム](#report-example)を使用して、式とコンテキストの両方を含む例を送信し、Zabbix開発者に提出してください。
:::

[comment]: # ({/baa6a112-contribute})
