Ad Widget

Collapse

Integrate Selenium with Zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhagwati
    Junior Member
    • May 2014
    • 7

    #1

    Integrate Selenium with Zabbix

    Hello

    I want to monitor special web checks in zabbix for a web page.
    Can you please help me .... I want to know how can we integrate selenium with Zabbix
  • zeds
    Junior Member
    Zabbix Certified Specialist
    • Jan 2009
    • 20

    #2
    you have to write your own code then. zabbix uses curl and simple web checks only AFAIK

    Comment

    • lagos.mc
      Junior Member
      • Jan 2011
      • 6

      #3
      Integrate Selenium with Zabbix

      Hi bhawati,

      Did you get to integrate selenium with zabbix?

      Or did you get to do webmonitoring work like selenium?

      Regards,

      Lagos

      Originally posted by bhagwati
      Hello

      I want to monitor special web checks in zabbix for a web page.
      Can you please help me .... I want to know how can we integrate selenium with Zabbix

      Comment

      • bhagwati
        Junior Member
        • May 2014
        • 7

        #4
        Selenium with Zabbix

        Hello Lagos,

        I prepared curl script to monitor some web related checks.
        I too was not able to integrate selenium with zabbix so found another way out.

        Regards,
        Bhagwati

        Comment

        • bitmeup
          Junior Member
          • Apr 2018
          • 18

          #5
          I recently came across this post again, because I did not recall how I had done it in the past. This post details how I currently do it.

          I use selenium+zabbix for two purposes that match this use case:
          - SIM cards: balance checks for multiple cards from multiple websites (different ISPs). This feature allows me to save several thousand Euro yearly, because it allows me to use pre-paid cards with the least expensive rates as compared to monthly plans
          - one-off scripts: heartbeat functionality by leveraging the nodata() expression in triggers

          What you need to do is essentially the following:
          1. create a host/item combination where you will receive info from a trapper. See zabbix documentation for trappers
          2. create a trigger that creates a problem, w«hen the item is not working as expected (e.g. no data, value does not meet expression)
            1. trigger1
              1. name: .. Stale Data
              2. prio: high
              3. expression: nodata(/YOURHOST/YOURKEYNAME,5s)=1
              4. wait 30 seconds (default period of recalculation for nodata triggers) to check if it goes into problem and then change the interval to one similar of the code interval (e.g. 50h)"
            2. trigger2
              1. name: ... low value
              2. prio: high
              3. operational data: Latest Value is less than acceptable: {ITEM.VALUE}
              4. expression: last(/YOURHOST/YOURKEYNAME)<5.50
              5. zabbix_send value "4.32" and make sure it goes into "PROBLEM" and then send back the actual value to see that it goes into "OK"
          3. test the trigger by using the zabbix_sender command from the CLI. See zabbix documentation for trappers
          4. now for the hard part (differs between the technology you can/intend to use
            1. setup your stack (e.g. selenium, firefox, python, venv)
            2. create your code with selenium/python/whatever so that it spits out a value to stdout that you can pass to the zabbix_sender. Warning: be careful as there are many special condition here. For example, sometimes zabbix_sender will accept bad values without error (e.g. accepts "" as a valid float)
            3. add your code to cron with the following logic:
              1. 'rm' the path to temporary file where you will store the value to push with zabbix_sender
              2. run your script and send stdout to the temporary file you deleted
              3. use a zabbix_sender command that 'cat's the temporary file
          5. configure an email relay for local alerts in case you don't have one. These alerts from cron are important and you should be alerted when scripts raise exception, files are not found, etc

          Example crontab
          Code:
          0 6 * * * rm "/home/USERNAME/balance-webcheck/src/last-balance.txt"
          1 6 * * * cd /home/USERNAME/balance-webcheck/src/ && source ../bin/activate && python get_balance.py 1> last-balance.txt
          3 6 * * * /usr/bin/zabbix_sender -z 127.0.0.1 -p 10051 -s "balance-webcheck" -k trap -o "$(cat /home/USERNAME/balance-webcheck/src/last-balance.txt)" 1> /dev/null
          Example script:
          Code:
          import time
          from selenium import webdriver
          
          from selenium.webdriver.support import expected_conditions as EC
          from selenium.common.exceptions import NoSuchElementException
          from selenium.common.exceptions import ElementNotVisibleException
          from selenium.common.exceptions import ElementNotSelectableException
          
          from selenium.webdriver.firefox.options import Options
          from selenium.webdriver.firefox.service import Service
          
          from selenium.webdriver.common.by import By
          from selenium.webdriver.common.action_chains import ActionChains
          from selenium.webdriver.support import expected_conditions
          from selenium.webdriver.support.wait import WebDriverWait
          from selenium.webdriver.common.keys import Keys
          from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
          from selenium.webdriver.support.ui import WebDriverWait
          
          # (...)  
            print(YOUR_VAR)

          Comment

          Working...