2 シナリオの実例
概要
このセクションでは、Webモニタリングの実例を段階的に提示します。
Zabbix Webモニタリングを使用して、ZabbixのWebインターフェイスをモニタリングしてみましょう。それが利用可能かどうか、適切なコンテンツを提供するかどうか、そしてそれがどれだけ速く機能するかを調査します。そのためにはユーザー名とパスワードを使用してログインする必要があります。
シナリオ
ステップ1
新しいWebシナリオを追加します。
ZabbixのWebインターフェースを監視するシナリオを追加します。シナリオはいくつかのステップを実行します。
Configuration→Hostsに移動し、ホストを選択して、そのホストの行にあるWebをクリックします。次にCreate web scenarioをクリックします。

すべての必須入力フィールドは、赤いアスタリスクでマークされています。
新しいシナリオフォームで、シナリオにZabbix frontendという名前を設定します。 また、{user}と{password}の2つの変数を作成します。
Tagsタブに新しい Application:Zabbix frontendタグを追加することもできます。
ステップ 2
シナリオのステップを定義します。
StepsタブのAddボタンをクリックして、個々のステップを追加します。
Webシナリオのステップ1
最初のページが正しく応答していることを確認するため、HTTPが応答コード200で返され、テキスト「ZabbixSIA」が含まれていることをチェックします。

ステップの構成が完了したら、Addをクリックします。
Webシナリオのステップ2
Zabbixフロントエンドにログインするため、シナリオレベルで定義したマクロの変数({user}と{password})を利用します。

Zabbixフロントエンドはログイン時にJavaScriptリダイレクトを使用するため、最初にログインする必要があり、その後のステップでのみログイン機能を確認できます。さらにログイン手順ではindex.phpファイルへの完全なURLを使用する必要があります。
正規表現を使用した変数構文を使用して{sid}変数(セッションID)を取得していることにも注意してください。
regex:name="csrf-token" content="([0-9a-z]{16})"
この変数はステップ4で必要になります。
Webシナリオのステップ3
ログインできたかを確認する必要があります。そのためにログイン時にのみ表示される文字列、例えばAdministrationなどを確認します。

Webシナリオのステップ4
フロントエンドにアクセスでき、ログインして、ログインしたコンテンツを取得できることを確認したので、ログアウトする必要があります。そうしないと、Zabbixデータベースが大量のオープンセッションレコードで汚染されてしまいます。

Webシナリオのステップ5
Username文字列を探すことで、ログアウトしたことを確認することもできます。

構成完了したステップ
構成完了したWebシナリオのステップは次のようになります。

Common fields
For each step described below, fill out the following fields in addition to the step-specific fields:
- URL - the URL of Zabbix frontend
- Timeout - 15s
- Required status codes - 200
Web scenario step 1
Check that the first page responds correctly, returns HTTP response code 200 and contains the text "Zabbix SIA".
- In the Name field, enter First page.
- In the Required string field, enter Zabbix SIA.
- Fill out the common fields.
When done configuring the step, press the Add button.

Web scenario step 2
Log in to the Zabbix frontend using the macros (variables) defined at the scenario level - {user} and {password}.
- In the Name field, enter Login.
- In the Post fields section, add three post fields:
- name with value {user}
- password with value {password}
- enter with value Sign in
- In the Variables section, add a new variable {csrf_token} with value regex:([0-9a-z]{64}). This variable will catch the value of the assigned CSRF token to reuse in step 4.
- Fill out the common fields.

Note that Zabbix frontend uses JavaScript redirect when logging in, so login must occur first, and logged-in features can be checked only in further steps. Additionally, the login step must use the full URL to index.php file.
Web scenario step 3
After logging in, verify success by checking for a string visible only when logged in - for example, Administration.
- In the Name field, enter Login check.
- In the Required string field, enter Administration.
- Fill out the common fields.

Web scenario step 4
Once the frontend's accessibility and login have been verified, add a logout step - otherwise the Zabbix database will become cluttered with many open session records.
- In the Name field, enter Logout.
- In the Post fields section, add two post fields:
- reconnect with value 1
- _csrf_token with value {csrf_token}.
- Fill out the common fields.
This step uses the variable {csrf_token} obtained in step 2

Web scenario step 5
To confirm the logout, check for the Username string.
- In the Name field, enter First page.
- In the Required string field, enter Username.
- Fill out the common fields.

Full configuration of steps
A complete configuration of web scenario steps should look like this:

ステップ3
完成したWebモニタリングシナリオを保存します。
シナリオがホストに追加されます。 Webシナリオ情報を表示するにはMonitoring → Hostsに移動し、リストでホストを見つけて、最後の列のハイパーリンクをクリックします。

シナリオ名をクリックすると、より詳細な統計が表示されます。
