Zabbix Web Scenario Trigger – Setup for Multiple Response Codes

monitoringzabbix

I am running some Zabbix Web Scenario's to gather information on certain websites and API's for some of the API's 401 and 404 status codes are acceptable and I want to adopt these in the trigger expression. Currently they are considered to be "down" because they do not match the 200 response code.

I have created a Web Scenario in Zabbix that accepts the following response codes: 200, 401, 404 (currently hosting some API's so these are very common)

This Check was working fine when I was only allowing the 200 status code. To this check I have added 2 'OR' statements regarding the 401 and 404 status code. For some reason this confuses the trigger and every check "fails"

I had my trigger expression set up like this for the 200 status code check: (This works great!)

{Template App Nginx by Zabbix agent:web.test.error["Web Check Status 200, 401, 404"].last()}=0 or {Template App Nginx by Zabbix agent:web.test.fail["Web Check Status 200, 401, 404"].last()}>0 or {Template App Nginx by Zabbix agent:web.test.rspcode["Web Check Status 200, 401, 404","Web Check Status 200, 401, 404"].last()}<>200

For the 2 new status codes I changed it to this:

{Template App Nginx by Zabbix agent:web.test.error["Web Check Status 200, 401, 404"].last()}=0 or {Template App Nginx by Zabbix agent:web.test.fail["Web Check Status 200, 401, 404"].last()}>0 or {Template App Nginx by Zabbix agent:web.test.rspcode["Web Check Status 200, 401, 404","Web Check Status 200, 401, 404"].last()}<>200 or {Template App Nginx by Zabbix agent:web.test.rspcode["Web Check Status 200, 401, 404","Web Check Status 200, 401, 404"].last()}<>401 or {Template App Nginx by Zabbix agent:web.test.rspcode["Web Check Status 200, 401, 404","Web Check Status 200, 401, 404"].last()}<>404

Now how I understand the logic of the expression it is as follows:

Alert IF:

web.test.error is equal to 0
OR web.test.fail is bigger then 0
OR web.test.rspcode does not equal 200
OR web.test.rspcode does not equal 401
OR web.test.rspcode does not equal 404

Is my approach correct? And how can I fix this?
Creating another trigger won't suffice (I think) because the original trigger will still be failing.

Best Answer

Problem 1:

Item web.test.error returns last error message of scenario as a string. So, your expression

{Template App Nginx by Zabbix agent:web.test.error["Web Check Status 200, 401, 404"].last()}=0

will never fire, as this item will never be 0. Change it to

{Template App Nginx by Zabbix agent:web.test.error["Web Check Status 200, 401, 404"].strlen()}>=0

and logical operator to AND. This will solve the first problem.

Problem 2:

You dont need the item.rspcode<>200 or item.rspcode<>401 or item.rspcode<>404 part. You already specified expected response codes in the web scenario. What happens in your case:

  • Zabbix receives HTTP 200: item.rspcode<>401 and item.rspcode<>404 are TRUE. Trigger is firing.
  • Zabbix receives HTTP 401: item.rspcode<>200 and item.rspcdoe<>404 are TRUE. Trigger is firing.
  • Zabbix receives HTTP 404: item.rspcode<>200 and item.rspcode<>401 are TRUE. Trigger is firing.

Remove aforementioned part from your trigger expression. It should solve problem 2.

TL;DR

Do it like this:

{Template App Nginx by Zabbix agent:web.test.error["Web Check Status 200, 401, 404"].strlen()}>=0 and
{Template App Nginx by Zabbix agent:web.test.fail["Web Check Status 200, 401, 404"].last()}>0
Related Topic