[comment]: # ({d9bf322f-f34132a6})
# 2 Real-life scenario

[comment]: # ({/d9bf322f-f34132a6})

[comment]: # ({608fb726-d43d02d4})
#### Overview

This section presents a step-by-step real-life example of how web monitoring can be used.

Zabbix web monitoring will be used to monitor Zabbix frontend. The goal is to determine if it is available, provides the 
right content, and how quickly it works. To achieve this, several steps are required, including checking the 
availability of the first page, logging in with a username and password, verifying the login success, logging out, and 
confirming the logout.

[comment]: # ({/608fb726-d43d02d4})

[comment]: # ({51af514b-51af514b})
#### Scenario

[comment]: # ({/51af514b-51af514b})

[comment]: # ({5c6f5f4d-6b72dd59})
##### Add a new web scenario

Go to *Data collection → Hosts*, pick a host and click *Web* in the row of that host. 
Then click *Create web scenario*. 

![](../../../assets/en/manual/web_monitoring/new_scenario.png){width="600"}


In the new scenario form, fill out the following fields:

- **Name** - Frontend check
- **Update interval** - 1m
- **Attempts** - 1
- **Agent** - Zabbix

In the *Variables* section, add two variables: *{password}* and *{user}*. 
Enter your existing Zabbix user credentials as values. 

For safety reasons, it is recommended to create a separate user with minimal permissions to use for monitoring purposes.

Optionally, switch to the *Tags* tab and add web scenario tags.

:::notetip
Once fully configured, this web scenario will automatically add a Zabbix trapper item to the host. 
You can use web scenario tags to quickly identify related items and triggers or search through collected data. 
For example, suitable tags for this tutorial are `component: web-scenario` and/or `target: frontend`. 
::: 

[comment]: # ({/5c6f5f4d-6b72dd59})

[comment]: # ({17b5bd92-475cbb1a})
##### Configure web scenario steps

Switch to the *Steps* tab and define steps for the scenario. Click *Add* button to add an individual step. 

[comment]: # ({/17b5bd92-475cbb1a})

[comment]: # ({75dcae2e-8e70e0cd})
###### 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
 

[comment]: # ({/75dcae2e-8e70e0cd})

[comment]: # ({d7edf15f-c793921e})
###### 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](#common-fields). 

When done configuring the step, click the *Add* button.

![](../../../assets/en/manual/web_monitoring/scen_step1.png){width="600"}

[comment]: # ({/d7edf15f-c793921e})

[comment]: # ({713aa628-3bec9061})
###### 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](#web-scenario-step-4).
- Fill out the [common fields](#common-fields).

![](../../../assets/en/manual/web_monitoring/scen_step2.png){width="600"}

::: noteimportant
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.
:::

[comment]: # ({/713aa628-3bec9061})

[comment]: # ({635690e6-ea24f4e7})
###### 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](#common-fields).

![](../../../assets/en/manual/web_monitoring/scen_step3.png){width="600"}

[comment]: # ({/635690e6-ea24f4e7})

[comment]: # ({06efb3e5-684b5527})
###### 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](#common-fields).

This step uses the variable {csrf_token} obtained in [step 2](#web-scenario-step-2)

![](../../../assets/en/manual/web_monitoring/scen_step4.png){width="600"}

[comment]: # ({/06efb3e5-684b5527})

[comment]: # ({5bdfc52a-5c1c5393})
###### Web scenario step 5

To confirm the logout, check for the **Username** string.

- In the **Name** field, enter *Logout check*.
- In the **Required string** field, enter *Username*. 
- Fill out the [common fields](#common-fields). 

![](../../../assets/en/manual/web_monitoring/scen_step5.png){width="600"}

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

[comment]: # ({2b6fe488-5c42025e})
###### Full configuration of steps

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

![](../../../assets/en/manual/web_monitoring/scenario_steps.png){width="600"}

[comment]: # ({/2b6fe488-5c42025e})

[comment]: # ({fd36f2c5-3e213338})
##### Check the results

Save the finished web monitoring scenario.

The scenario will be added to the host. To view web scenario information go to *Monitoring → Hosts*, locate the host in 
the list and click the Web hyperlink in the last column.

![](../../../assets/en/manual/web_interface/web_monitoring.png){width="600"}

Click the scenario name to see more detailed statistics:

![](../../../assets/en/manual/web_monitoring/scenario_details2.png){width="600"}

[comment]: # ({/fd36f2c5-3e213338})

