tinyops-ru / zabbix-lld-ws

Add Web Scenarios support to Zabbix Low Level Discovery feature.
MIT License
9 stars 2 forks source link

Trigger not created correctly #4

Closed bbx-github closed 8 months ago

bbx-github commented 1 year ago

The triggers never get created (Zabbix 5.0) The Webscenarios are working though. I have to delete them again every time I am testing because otherwise it wont even try to start creating the triggers again.

I used this as my trigger template in the .yml file: value: "last(/${HOST}/web.test.fail[Check index page '${URL}'])<>0" since this exact trigger is already working after I set it up manually. Something seems messed up in the way the expression is put together I think. It seems to add <>0 on the end for example.

Any help is appreciated.

2023-09-25 14:52:32 - INFO - [zabbix_lld_ws::webscenarios] - creating web scenario for 'http://mysite.org'
2023-09-25 14:52:32 - INFO - [zabbix_lld_ws::webscenarios] - web scenario has been created for 'http://mysite.org'
2023-09-25 14:52:32 - INFO - [zabbix_lld_ws] - web scenario has been created for 'http://mysite.org'
2023-09-25 14:52:32 - ERROR - [zabbix_lld_ws::zabbix] - error -32602
2023-09-25 14:52:32 - ERROR - [zabbix_lld_ws::zabbix] - - message: 'Invalid params.'
2023-09-25 14:52:32 - ERROR - [zabbix_lld_ws::zabbix] - - data: 'Invalid parameter "/1/expression": incorrect expression starting from "{last(/myserver.org/web.test.fail[Check index page 'http://mysite.org'])<>0}<>0".'
2023-09-25 14:52:32 - ERROR - [zabbix_lld_ws::triggers] - unable to create trigger for 'http://mysite.org'
2023-09-25 14:52:32 - ERROR - [zabbix_lld_ws] - unable to create trigger for url 'http://mysite.org'
lebe-dev commented 1 year ago

Thanks for report. Please, post log here with --log-level=debug.

bbx-github commented 1 year ago

This is the part about trigger creation that shows up for every single item.

2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws] - item 'Vhost https://site.to.check.org item'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws] - ---------------------------
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws] - item: Vhost https://site.to.check.org item
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws] - - url 'https://site.to.check.org'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws] - web scenario wasn't found for url 'https://site.to.check.org', creating..
2023-09-27 17:32:09 - INFO - [zabbix_lld_ws::webscenarios] - creating web scenario for 'https://site.to.check.org'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::webscenarios] - host-id: '10356'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::http] - send post request to 'https://zabbix.server.org/zabbix/api_jsonrpc.php'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::http] - ---[HTTP RESPONSE]----
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::http] - {"jsonrpc":"2.0","result":{"httptestids":["122"]},"id":1}
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::http] - ---[/HTTP RESPONSE]----
2023-09-27 17:32:09 - INFO - [zabbix_lld_ws::webscenarios] - web scenario has been created for 'https://site.to.check.org'
2023-09-27 17:32:09 - INFO - [zabbix_lld_ws] - web scenario has been created for 'https://site.to.check.org'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::triggers] - create trigger for host 'web.server.org', url 'https://site.to.check.org'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::triggers] - trigger config 'ZabbixTriggerConfig { name: "Site '${URL}' on '${HOST}' is unavailable", value: "last(/${HOST}/web.test.fail[Check index page '${URL}'])<>0" }'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::triggers] - trigger name 'Site 'https://site.to.check.org' on 'web.server.org' is unavailable'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::triggers] - trigger expression '{last(/web.server.org/web.test.fail[Check index page 'https://site.to.check.org'])<>0}<>0'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::http] - send post request to 'https://zabbix.server.org/zabbix/api_jsonrpc.php'
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::http] - ---[HTTP RESPONSE]----
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::http] - {"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params.","data":"Invalid parameter \"/1/expression\": incorrect expression starting from \"{last(/web.server.org/web.test.fail[Check index page 'https://site.to.check.org'])<>0}<>0\"."},"id":1}
2023-09-27 17:32:09 - DEBUG - [zabbix_lld_ws::http] - ---[/HTTP RESPONSE]----
2023-09-27 17:32:09 - ERROR - [zabbix_lld_ws::zabbix] - error -32602
2023-09-27 17:32:09 - ERROR - [zabbix_lld_ws::zabbix] - - message: 'Invalid params.'
2023-09-27 17:32:09 - ERROR - [zabbix_lld_ws::zabbix] - - data: 'Invalid parameter "/1/expression": incorrect expression starting from "{last(/web.server.org/web.test.fail[Check index page 'https://site.to.check.org'])<>0}<>0".'
2023-09-27 17:32:09 - ERROR - [zabbix_lld_ws::triggers] - unable to create trigger for 'https://site.to.check.org'
2023-09-27 17:32:09 - ERROR - [zabbix_lld_ws] - unable to create trigger for url 'https://site.to.check.org'
lebe-dev commented 1 year ago

I'll check and come back

lebe-dev commented 1 year ago

You noticed that your Zabbix version is v5, not sure about syntax. We have Zabbix v6 and triggers look like this:

last(/somesrv.ourcompany.com/web.test.fail[Check index page 'https://somesrv.ourcompany.com'])<>0

I've never seen syntax last(...) for Zabbix 5. I think your trigger should be look like this:

someserv.ourcompany.com:web.test.fail[Check index page 'someserv.ourcompany.com'].last()

Could you provide config wszl.yml?

bbx-github commented 1 year ago

First, sorry about the confusion I thought I was using Zabbix 5, but in fact I am also using 6.0.

But, I dont think it happens because I defined the trigger wrongly. As I said I am already using the exact same definition in a manually created trigger and it works. But I can show you my wszl.yml:

zabbix:
  api:
    version: 6
    endpoint: https://zabbix.server.org/zabbix/api_jsonrpc.php
    username: user
    password: 'password,'

  trigger:
    name: "Site '${URL}' on '${HOST}' is unavailable"

    # Zabbix 6
    # Template variables are supported: ${HOST}, ${URL}
    #value: "last(/${HOST}/web.test.fail[Check index page '${URL}'])<>0"

    # Zabbix 5
    # Template variables are supported: ${HOST}, ${URL}
    #value: "${HOST}:web.test.fail[Check index page '${URL}'].last()"

    # Custom
    # copied from working trigger
    value: "last(/${HOST}/web.test.fail[Check index page '${URL}'])<>0"

  scenario:
    # Template variables are supported: ${HOST}, ${URL}
    name: "Check index page '${URL}'"
    response-timeout: "15s"
    expect-status-code: "200"
    attempts: 3
    update-interval: "5m"

As you can see the custom one is even the exact same trigger then the predefined one. The trigger that I manually created and is working (for a manually defined web scenario): last(/myerver.net/web.test.fail[Availability of mysite.org])<>0

lebe-dev commented 12 months ago

Please try new build https://github.com/tinyops-ru/zabbix-lld-ws/releases/tag/0.7.1-2

If problem will appear again, send me piece of log

bbx-github commented 11 months ago

Yes, it works now. But the functionality of not skipping the trigger creation when there is a web scenario already is gone again. You fixed this in another release of a different issue I created. Was this intentional. If yes, then I will close it, otherwise this may be a regression bug?

lebe-dev commented 11 months ago

Could you provide the latest log file with DEBUG logging mode?

bbx-github commented 11 months ago

What I did:

The debug log, but I cut out everything but one vhost, so I dont have to censor the whole thing:

2023-10-06 15:03:34 - INFO - [zabbix_lld_ws::config] - config loaded: api: 'api version: 6, endpoint: 'https://my.zabbix.server.org/zabbix/api_jsonrpc.php', username: 'api_user', password: '*********'', scenario: 'name: 'Check index page '${URL}'', response-timeout: '15s', expect-status-code: '200, attempts: 3, update-interval: '5m''
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - send post request to 'https://my.zabbix.server.org/zabbix/api_jsonrpc.php'
2023-10-06 15:03:34 - DEBUG - [reqwest::connect] - starting new connection: https://my.zabbix.server.org/
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - ---[HTTP RESPONSE]----
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - {"jsonrpc":"2.0","result":"2bc68a1d76fd25c5c6d30b632af91ea2","id":1}
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - ---[/HTTP RESPONSE]----
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws] - login success: token '2bc6..'
2023-10-06 15:03:34 - INFO - [zabbix_lld_ws::items] - searching zabbix items..
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - send post request to 'https://my.zabbix.server.org/zabbix/api_jsonrpc.php'
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - ---[HTTP RESPONSE]----
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - {"jsonrpc":"2.0","result":[{"itemid":"41636","type":"15","snmp_oid":"","hostid":"10356","name":"Vhost https://my.site.org item","key_":"vhost.item[https://my.site.org]","delay":"5m","history":"90d","trends":"365d","status":"0","value_type":"3","trapper_hosts":"","units":"","formula":"","logtimefmt":"","templateid":"0","valuemapid":"0","params":"0","ipmi_sensor":"","authtype":"0","username":"","password":"","publickey":"","privatekey":"","flags":"4","interfaceid":"0","description":"","inventory_link":"0","lifetime":"30d","evaltype":"0","jmx_endpoint":"","master_itemid":"0","timeout":"3s","url":"","query_fields":[],"posts":"","status_codes":"200","follow_redirects":"1","post_type":"0","http_proxy":"","headers":[],"retrieve_mode":"0","request_method":"0","output_format":"0","ssl_cert_file":"","ssl_key_file":"","ssl_key_password":"","verify_peer":"0","verify_host":"0","allow_traps":"0","uuid":"","state":"0","error":"","parameters":[],"lastclock":"1696597136","lastns":"222769409","lastvalue":"0","prevvalue":"0"}],"id":1}
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - ---[/HTTP RESPONSE]----
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::items] - zabbix items: [ZabbixItem { name: "Vhost https://my.site.org item", key_: "vhost.item[https://my.site.org]", hostid: "10356" }]
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws] - received items:
2023-10-06 15:03:34 - INFO - [zabbix_lld_ws::webscenarios] - searching web scenarios..
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - send post request to 'https://my.zabbix.server.org/zabbix/api_jsonrpc.php'
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - ---[HTTP RESPONSE]----
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - {"jsonrpc":"2.0","result":[{"httptestid":"174","name":"Check index page 'https://my.site.org'","nextcheck":"1696597638","delay":"5m","status":"0","agent":"Zabbix","authentication":"0","http_user":"","http_password":"","hostid":"10356","templateid":"0","http_proxy":"","retries":"3","ssl_cert_file":"","ssl_key_file":"","ssl_key_password":"","verify_peer":"0","verify_host":"0","uuid":"","headers":[],"variables":[]}],"id":1}
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - ---[/HTTP RESPONSE]----
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::webscenarios] - web scenarios found: [ZabbixWebScenario { name: "Check index page 'https://my.site.org'" }]
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws] - web scenarios have been obtained
2023-10-06 15:03:34 - INFO - [zabbix_lld_ws::hosts] - find hosts by ids..
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - send post request to 'https://my.zabbix.server.org/zabbix/api_jsonrpc.php'
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - ---[HTTP RESPONSE]----
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - {"jsonrpc":"2.0","result":[{"hostid":"10356","proxy_hostid":"0","host":"my.server.org","status":"0","lastaccess":"0","ipmi_authtype":"-1","ipmi_privilege":"2","ipmi_username":"","ipmi_password":"","maintenanceid":"0","maintenance_status":"0","maintenance_type":"0","maintenance_from":"0","name":"my.server.org","flags":"0","templateid":"0","description":"","tls_connect":"2","tls_accept":"2","tls_issuer":"","tls_subject":"","proxy_address":"","auto_compress":"1","custom_interfaces":"0","uuid":"","inventory_mode":"-1"}],"id":1}
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws::http] - ---[/HTTP RESPONSE]----
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws] - item 'Vhost https://my.site.org item'
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws] - ---------------------------
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws] - item: Vhost https://my.site.org item
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws] - - url 'https://my.site.org'
2023-10-06 15:03:34 - DEBUG - [zabbix_lld_ws] - web scenario has been found for url 'https://my.site.org', skip

EDIT: I did this with the latest 0.7.1.-2 release of course

lebe-dev commented 9 months ago

@bbx-github is the problem still relevant? sorry, i missed this issue somehow.

lebe-dev commented 9 months ago

I've release a new version 0.7.2 https://github.com/tinyops-ru/zabbix-lld-ws/releases/tag/0.7.2

Web scenarios and triggers are now independent of each other.