Ad Widget

Collapse

Using Zabbix HTTP Agent Item to Validate HTML Elements on a Page

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • za267
    Junior Member
    • Aug 2023
    • 3

    #1

    Using Zabbix HTTP Agent Item to Validate HTML Elements on a Page

    Hello,

    I'm facing a challenge with Zabbix and could use some guidance. I'm currently using an Item of type "HTTP Agent" to retrieve the content of a webpage. My goal is to perform checks on the retrieved content to ensure that specific HTML elements exist on the page, effectively verifying that the page hasn't been corrupted or altered incorrectly.

    Here's what I'm trying to achieve in a nutshell:
    1. Use a "HTTP Agent" item to fetch the content of a webpage.
    2. Perform validations on the fetched content to check if specific HTML elements exist.
    3. Ideally, return a simple numeric value (1 for success, 0 for failure) based on whether all tests succeed or fail.
    4. Discard the rest of the data.

    I've attempted to use both "Regular expressions" and the "Matches regular expression" preprocessing step for this purpose. However, I'm facing a couple of issues:
    1. With regular expressions, it seems that the value is altered during the validation process, causing the second test to fail.
    2. With "Matches regular expression," I can't figure out how to return a numeric value (1 or 0) on success or failure.

    I'm seeking advice on the best approach to achieve my goal. Is there a recommended way to use the "HTTP Agent" item along with preprocessing to validate the presence of specific HTML elements? Ideally, I would like to have a clear indication (1 or 0) whether the tests have passed or failed.

    If anyone has experience or insights into this situation, I would greatly appreciate your help.

    Thanks!
  • Answer selected by za267 at 05-09-2023, 15:38.
    cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    If you whole page is fetched at once, no extra steps/"clicks" needed, then you may try with dependent items. You pull whole page content (hopefully not too long) with http item and then create multiple dependent items with different (regex/JS..) preprocessing. In the end returning 1/0 ...

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #2
      Looks like you should use "web scenarios" instead.

      Comment

      • za267
        Junior Member
        • Aug 2023
        • 3

        #3
        Thank you for your suggestion. Initially, I attempted this approach. However, in web scenarios, each step only provides a 'required string' field that accepts regular expressions. My specific requirement involves validating content based on multiple HTML tags and sometimes plain text content within those tags. It may not be possible to achieve this using a regular expression when the order of the elements is unknown and when I need to perform a logical AND operation on multiple strings. (At least, not possible with zabbix's regex engine - I tried using positive lookahead)

        One potential solution is to set up a separate web scenario step for each string to look for. However, this would require making a separate page request for each word that are on the same page, potentially putting excessive load on the website, which is not ideal.

        Comment

        • cyber
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Dec 2006
          • 4807

          #4
          If you whole page is fetched at once, no extra steps/"clicks" needed, then you may try with dependent items. You pull whole page content (hopefully not too long) with http item and then create multiple dependent items with different (regex/JS..) preprocessing. In the end returning 1/0 ...

          Comment

          • za267
            Junior Member
            • Aug 2023
            • 3

            #5
            Thanks cyber , I ended up doing that. Great solution it works really well and it offers a lot of flexibility.

            Comment

            Working...