Sebbo
Sebbo

Reputation: 65

How to check HTTP response code in zabbix?

I have a Zabbix server 2.2 and a few linux hosts with websites. How can I get a notification from Zabbix, if the HTTP(s) response code is not 200?

I've tried those triggers without any success:

    {owncloud:web.test.rspcode[Availability of owncloud,owncloud availability].last(,10)}#200

    {owncloud:web.test.error[Availability of owncloud].count(10,200)}<1

    {owncloud:web.test.error[Availability of owncloud].last(#1,10)}=200

But nothing works. I never got an notification, that the code is not 200 anymore even it was 404, because I have renamed the index.php of owncloud to index2.php

Upvotes: 2

Views: 38834

Answers (4)

Sean Bradley
Sean Bradley

Reputation: 3577

The question has been answered adequately, but I will provide a very much more advanced solution that you could use for all HTTP status codes.

I've created an item that monitors all HTTP status codes of a proxy, graphs them, and then set up multiple different types of triggers to watch last value and counts in last N minutes.

The regex I used to extract all the values from a Nginx or Apache access log is ^(\S+) (\S+) (\S+) \[([\w:\/]+\s[+\-]\d{4})\] \"(\S+)\s?(\S+)?\s?(\S+)?\" (\d{3}|-) (\d+|-)\s?\"?([^\"]*)\"?\s?\"?([^\"]*)\"?\s

I then set many triggers relevant for my particular situation

  • 101 Switching Protocols
  • 301 Moved Permanently
  • 302 Redirect
  • 304 not modified
  • 400 Bad Request
  • 401 Unauthorised
  • 403 Forbidden
  • 404 Not found
  • 500 Server Error

It's also important that your Zabbix agent has permissions to read the log file on the host. You can add the zabbix-agent to the www-data group using this command.

$ sudo usermod -a -G www-data Zabbix

See the tutorial for all the steps in greater detail.

Zabbix Log File Monitoring - HTTP Status Codes

Upvotes: 0

Stefano
Stefano

Reputation: 1722

I configured the Application and the we the Web Scenario as followed: if you have already configured the host go to step 1

1) Select the host by Configuration-> Host groups -> select host (example server 1)

enter image description here

2) Go to Config > Hosts > [Host Created Above] > Applications and click on Create Application

enter image description here

3) Now you have to create the Web scenario with the status code check, in my case I checked status code 200. So go to Configuration > Hosts > [Host Created Above] > Web Scenarios and click on Create Web Scenario .

Remark: you have to select the previous application created at the step 2

enter image description here

4) After that without click on Add button go to Steps window and you have to configure the host and parameters for the chek. After that click on Add. In my cas e check the status code 200 response for the HTTP request.

enter image description here

Upvotes: 2

rafie
rafie

Reputation: 21

you have set a triggers bye Expression

{host name:web.test.rspcode[Scenario name,Steps name].last()}=200

Upvotes: 2

Sebbo
Sebbo

Reputation: 65

I found the issue. You need to specify the URL to check with file. For example like this in your web scenario:

    https://owncloud.example.com/index.php

"Note that Zabbix frontend uses JavaScript redirect when logging in, thus first we must log in, and only in further steps we may check for logged-in features. Additionally, the login step must use full URL to index.php file." - https://www.zabbix.com/documentation/2.4/manual/web_monitoring/example

I also used following expression as trigger:

    {owncloud:web.test.fail[Availability of owncloud].last()}>0

Upvotes: 1

Related Questions