Now that we have seen plenty of ways to monitor all kinds of network devices, it's time to have a look at how we can monitor websites with Zabbix. With Zabbix, it's possible to monitor all kinds of information from web pages. In this recipe, we will explain you how to do it in a few easy steps.
Once again, we need our Zabbix server properly configured with a Zabbix super admin account. Make sure that the agent is installed on the Zabbix server and is working fine.
Zabbix availability check
.Zabbix web check
.{user}=Admin {password}="your zabbix Admin password"
Step 1: In this recipe, we will add the first step in our scenario to verify the existence of our front page.
Front page
.http://localhost/zabbix/index.php
).Zabbix SIA
.200
.Step 2: Now we add a second step to login in our Zabbix web page.
Login step
.http://localhost/zabbix/index.php
in the URL field.name={user}&password={password}&enter=Sign in
{sid}=regex:sid=([0-9a-z]{16})
200
.Step 3: In our third,step we will verify if the login step that we just made actually works:
Login check
.http://localhost/zabbix/index.php
Profile
.200
again:Step 4: In our fourth and last step we will log out of the web page to make sure all sessions are closed.
Logout
.URL
field:http://localhost/zabbix/index.php?reconnect=1&sid={sid}
200
.When we want to monitor websites, we have to create a scenario. This scenario is based on a certain level of steps. Each step will be executed in the exact the same order.
In our scenario, we have added some variables for user and password between {}
so that we don't have to type our login and password every time in the other steps.
We then added a first step just to monitor the front page; here we filled in the code 200
in the required status codes field. A web server will always return a certain code when we open a web page 200
is the code for OK. More codes can be found here: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes.
We also looked for a required string. This is a unique text on the web page that we see only when we are at the login page of our website.
In the next step, we tried to log in. For this we made use of the post and the variables boxes.
In the post box, we added the string that we need to post with our username and password. Remember we made macros for this. Be careful we have to enter everything in one line and have to glue it together with &
. Also, in this example we make use of name and password for name and password but this can change. You have to look in the code of the web page what the exact post variables are. Same goes for the enter=Sign
option in, this is the post variable used to enter the username and password.
The variables box is a regular expression that we need because the web page makes use of a session ID. We put our regexp
option in a macro {sid}
that we can use later.
In our third step, we are already logged in so the only thing to verify if login really worked is add a required string that can only be seen once you are logged in. In our case, that is the word Profile
.
Now in our final step, we will try to log out, else all sessions will stay recorded in the database. In some cases it is possible that you can't log in for a certain amount of time because your session is still active.
For this, we have to add the URL that we need to log out and we also have to pass our session ID. Here we can make use of the {sid}
macro that we made earlier in step 2.
A few extra tips to keep in mind when you monitor websites:
# zabbix_server -R log_level_increase="http poller"
3.145.149.253