Ad Widget

Collapse

Use/Suggestions and help for web_monitoring template using podman selenium

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jean-louis.abegg
    Member
    • Feb 2020
    • 37

    #1

    Use/Suggestions and help for web_monitoring template using podman selenium

    hi,

    i'm trying to use the web monitoring system, based on selenium webdriver.
    The learning course is not that simple, the web driver system, although obvious in the purpose, is quite heavy to handle.
    The web_driver template and the podman selenium help us to have a good quick start with it, simplifying the deployment of the solution.
    However, we obtain a system with different layers (zabbix and java variables, template and java script, podman, selenium and the webdriver).
    My trouble is: what's the best convention to add functionnality to the current template?
    An exemple: i need to monitor datas from a web site... it's specific and the maker of the system didn't used normalized system as snmp or others => the web monitoring system is the solution.
    But, the browser is in en_EN... i need to give the browser another country code.
    I'm strugling to give the country parameter to the browser... the best would be to have options directly in the template (for language, for certificate , for accept cookie...)
    If the template wouldn't evolve, the other way could be to code it in js. Unfortunately, i didn't manage to give the parameters in the javascript of the Website {$WEBSITE.DOMAIN} Get data element of the template.
    Looking for this kind of request, a options.addArguments('--lang=xx_XX''); should be used... (with xx_XX en_EN for englis, fr_FR for french, de_DE for german...)
    Same response for bypassing certificates error : options.addArguments('--ignore-certificate-errors'); should be used.
    i'm sorry about that, but my attempts to implement it directly in the js script, even without adding a parameter in the script (directly in the java code) has failed.
    I don't know if i'ts possible, the way to give the parameters in this template, if it could work...
    I'm not accustomed to js syntax, i'm pretty sure my troubles comes from lack of understanding the passing and modifying of parameters in the JS

    getOptions(browser) {
    switch ((browser || '').trim().toLowerCase()) {
    case 'firefox':
    return Browser.firefoxOptions();
    case 'safari':
    return Browser.safariOptions();
    case 'edge':
    return Browser.edgeOptions();
    default:
    //trying to add parameters for the chrome browser
    browser.chromeOptions.addArguments('--lang=fr_FR');
    //maybe other parameters to modify
    return Browser.chromeOptions();
    }
    },

    Any help would be appreciated
  • jean-louis.abegg
    Member
    • Feb 2020
    • 37

    #2
    Hi,
    Replying to myself, to keep an eye on the evolve of my comprehension and giving a chance for others to join in.
    I've made different tests with the use of the web browser tool in zabbix.
    I think that there are indeed 3 layers in the implementation of this solution:
    1°) Podman & selenium. - There are different parameters to drive selenium using the docker-compose.yml
    2°) The language of selenium. - Depends of the programing language you're using. Exemple: options.add_argument() or options.add_preference()
    3°) The language of zabbix. - Depends of the way web drivers are implemented in zabbix. Not all of the selenium language seems to be translated in it.

    I've come to this conclusion trying to manipulate the web drivers using the template given : https://git.zabbix.com/projects/ZBX/...Frelease%2F7.2

    An exemple of the dificulty: y wanted to have a pause in the web browser, giving time for a webpage to finish loading...
    Using: Thread.sleep(2000); => fail
    Using: time.sleep(2) => fail
    Using: wait.until(...) => fail

    The only solution seemed to work is Zabbix.sleep(2000); => That's a function of zabbix.

    I suppose there's a way to have access to the full parameters of the selenium language, but i don't know how to achieve that...

    Comment

    • jean-louis.abegg
      Member
      • Feb 2020
      • 37

      #3
      Hi,

      Still replying to myself...
      Looking in the passing of parameters in the template, i wonder if i understand the principe well:

      The creation of the browser is here: const browser = new Browser(Website.getOptions(Website.params.browser) );
      Is it working this way?: in Website.getOptions(Website.params.browser)
      (Website.params.browser) use the code
      const Website = {
      params: {},

      setParams(params) {
      ['scheme', 'domain','width', 'height'].forEach(function (field) {
      if (typeof params !== 'object' || !params[field]) {
      throw new Error('Required param is not set: ' + field + '.');
      }
      });
      this.params = params;
      },

      to implement the parameters from the Parameters builded in the zabbix element (analytics={$WEBSITE.ANALYTICS.WARNING},browser={$ WEBSITE.BROWSER},domain={$WEBSITE.DOMAIN}...) using the macros to get the values of the template or forced value of the device.

      and the Website.getOptions() use the code

      getOptions(browser) {
      switch ((browser || '').trim().toLowerCase()) {
      case 'firefox':
      return Browser.firefoxOptions();
      case 'safari':
      return Browser.safariOptions();
      case 'edge':
      return Browser.edgeOptions();
      default:
      return Browser.chromeOptions();
      }
      },

      to implement the specification of the browser

      So, if my comprehension is ok, adding a selenium parameter should be quite straightforward:
      - creating a new macro in the template: {WEBSITE.NEWPARAMETER}
      - creating a new Parameter in the Website {$WEBSITE.DOMAIN} Get data element: newparam={WEBSITE.NEWPARAMETER}
      - modifying the code in const Website:
      const Website = {
      params: {},

      setParams(params) {
      ['scheme', 'domain','width', 'height','newparam'].forEach(function (field) {
      if (typeof params !== 'object' || !params[field]) {
      throw new Error('Required param is not set: ' + field + '.');
      }
      });
      this.params = params;
      },

      I tried to use the changing language parameter : --accept-lang=fr-FR to try setting the language of the browser in french without success....

      But i duno if that's the way parameters are implemented, the parameter itself (--accept-lang=fr-FR) or there isn't a parameter to set the language of the browser yet...

      Last edited by jean-louis.abegg; 04-02-2025, 12:07.

      Comment

      • dpc22
        Junior Member
        • Aug 2022
        • 3

        #4
        The only solution seemed to work is Zabbix.sleep(2000); => That's a function of zabbix.
        I have had some success with a function which polls repeatedly for a specific xpath, waiting 250 milliseconds between each poll:
        Code:
        function waiton(xpath, seconds)
        {
          var count = seconds * 4;
          for (var i = 0; i < count; i++) {
            if (browser.findElement("xpath", xpath)) {
              break;
            }
            Zabbix.sleep(250)
          }
        }
        ​
        However the Zabbix "Browser" and "Element" object seem quite constrained.

        Comment


        • jean-louis.abegg
          jean-louis.abegg commented
          Editing a comment
          Hello dpc22.
          Yes, agreed, this is a more elegant way of programming.
          In fact, i wasn't focus on the right way to program, but on the functions we could use.
          Thanks for the comment, be sure i'll implement it the way you showed ;-)
      • dpc22
        Junior Member
        • Aug 2022
        • 3

        #5
        Looking in the passing of parameters in the template, i wonder if i understand the principe well:
        It looks like parameters are passed into the lump of Javascript that we get to edit as a variable "value", which is a JSON encoded dictionary. I can decode that using something like:
        Code:
        try {
            var params = JSON.parse(value);
            browser.navigate(params.webURL);
        Last edited by dpc22; 17-02-2025, 19:38.

        Comment

        • dpc22
          Junior Member
          • Aug 2022
          • 3

          #6
          However the Zabbix "Browser" and "Element" object seem quite constrained.
          A separate issue in the same vein. The following:
          Code:
          var element = browser.findElement("xpath", "//a[@title='A link to click on']");
          element.click();
          throws an exception:
          Code:
          {"duration":1.3008191585540771,"error":{"http_status":400,"code":"element not interactable","message":"cannot click element: Element <a href=\"/sympa/my\"> could not be scrolled into view"}}
          A quick trip to Google suggests that I should be able to use element.scrollIntoView() before element.click() if the element in question is a popup window. However that generates a separate error:
          Code:
          undefined not callable (property 'scrollIntoView' of [object Object])"}}
          and indeed https://www.zabbix.com/documentation...bjects#element doesn't include "scrollInfoView()" as a valid method

          Comment

          • jean-louis.abegg
            Member
            • Feb 2020
            • 37

            #7
            Now, it seems i've made some progress the way we could give some parameters to the drivers from zabbix.
            It should be incorporated the 'right' way : by creating macros and passing them using the subroutine setParams(params).

            I've faced troubles on another site, having a self-signed certificate...

            I needed to give the param: --ignore-certificate-errors to the chrome browser from zabbix.

            Here is how i succeeded to pass the --ignore-certificate-errors.
            I give another parameter: --lang=fr_FR.UTF8. I didn't verify the lang parameter function, but i can certify the ignore-certificate-errors is working OK.
            I've modified the function getOptions(browser) to push the extra options when using chrome, which is the default option in the official template: Website by Browser

            getOptions(browser) {
            switch ((browser || '').trim().toLowerCase()) {
            case 'firefox':
            return Browser.firefoxOptions();
            case 'safari':
            return Browser.safariOptions();
            case 'edge':
            return Browser.edgeOptions();
            default:
            var opts = Browser.chromeOptions();
            opts.capabilities.alwaysMatch['goog:chromeOptions'].args = ["--ignore-certificate-errors","--lang=fr_FR.UTF8"];
            return opts;
            //return Browser.chromeOptions();
            }

            Comment

            Working...