Ad Widget

Collapse

Web Check: How to use returned values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dtedesc1
    Junior Member
    • Feb 2014
    • 10

    #1

    Web Check: How to use returned values

    So with 2.2 it's now possible to pull back data from your page and put it in a variable.

    See http://blog.zabbix.com/zabbix-2-2-fe...webpages/2256/

    In Step 1 I need to login in to a web page, and it contains a randomly generated token that I need to pass with the request, the token is defined like this:

    <input type="hidden" name="lt" value="_c128ACABE-1BAB-7FC6-A2DA-F53A6AC21D5D_k93C450DF-E950-E512-3891-C0316EF93D41" />

    So I created a variable:

    {logintoken}:regex:name="lt" value="([0-9a-zA-Z)"

    to capture that value.

    My question is, can I use use {logintoken} in Step 2 of my scenario?
    What's the scope of that variable?

    I know a variable created at the Scenario level is global, and is overridden by one defined at the Step level.

    Do I need to define {logintoken} at the Scenario level and then pull it in Step 1 to make it available in Step 2?
  • dtedesc1
    Junior Member
    • Feb 2014
    • 10

    #2
    Step Variables

    OK, after some trial and error I finally got this working, mostly.

    In Step 1 I was able to define a variable:

    {logintoken}=regex:name="lt" value="([^"]*)

    Which returns the value I wanted, and I'm able to use that in variable in Step 2, so I'm assuming it available in all Steps defined later.

    Now my problem is a complete lack of info on why my response code is good, ie, 200, but my Required String is not found. Even at debug level 4 the logs provide no info on the html response from the page. But that's another problem.

    Comment

    • bsdtux
      Junior Member
      • Mar 2014
      • 9

      #3
      First I want to say my regex is not that strong but it looks to me in your second post that your value is not properly enclosed. Also could you share what value you are expecting? Because ^ normally means start of the string. So if you where looking for a double quote at the beginning of the string I would think it would be
      Code:
      {$logintoken}=regex:name="lt" value="(^["]*)"
      also I put in a dollar sign in $logintoken because I believe that is how zabbix expects variables.

      Comment

      • dtedesc1
        Junior Member
        • Feb 2014
        • 10

        #4
        Regex

        Thanks for the reply.

        I'll be the first to admit that I suck at regular expressions.

        My first attempt to pull the value from:

        <input type="hidden" name="lt" value="_c128ACABE-1BAB-7FC6-A2DA-F53A6AC21D5D_k93C450DF-E950-E512-3891-C0316EF93D41" />

        didn't work at all. I switched to something like:

        {logintoken}=regex:name="lt" value="(.*)

        And what I would up with was

        {logintoken}='_c128ACABE-1BAB-7FC6-A2DA-F53A6AC21D5D_k93C450DF-E950-E512-3891-C0316EF93D41" />'

        With the " /> on the end that I didn't want. After begging for some local help I used:

        {logintoken}=regex:name="lt" value="([^"]*)

        which is working and returning the expected value:
        {logintoken}='_c128ACABE-1BAB-7FC6-A2DA-F53A6AC21D5D_k93C450DF-E950-E512-3891-C0316EF93D41'

        As I said, not a regex expert, your expression may be better than what I'm currently using.

        Comment

        • bsdtux
          Junior Member
          • Mar 2014
          • 9

          #5
          hey if it works I would stick with it. No pointing in making matters worse. are you still a good response code but not a string return?

          Comment

          • dtedesc1
            Junior Member
            • Feb 2014
            • 10

            #6
            Required String

            Yes, Response Code still good but can't get a match on Required String.

            I have seen other posts suggesting direct use of curl as a way of troubleshooting this but that seems tedious at best. Zabbix must be getting the html response for the match. I understand why they wouldn't want to log that normally since it could be huge, but at DebugLevel 4 it would be really helpful.

            Comment

            • dtedesc1
              Junior Member
              • Feb 2014
              • 10

              #7
              Cookie

              OK, there's a cookie that's required as well. Since this app runs out of tomcat there's a JSESSIONID cookie that needs to be there.

              I have no clue how Zabbix web checks deal with cookies.

              Comment

              • dtedesc1
                Junior Member
                • Feb 2014
                • 10

                #8
                Cookie Handling

                From the 2.2 docs:

                "Zabbix web monitoring supports both HTTP and HTTPS. When running a web scenario, Zabbix always follows redirects. All cookies are preserved during the execution of a single scenario. "

                So, it shouldn't be cookie related.

                Comment

                • dtedesc1
                  Junior Member
                  • Feb 2014
                  • 10

                  #9
                  Works!!!

                  OK, I was missing a crucial piece of the URL I needed to post. Once I added that, the step was able to login in successfully and match on the required string.

                  Thanks for your help.

                  I'd still like to be able to log the html response coming back from a particular step.

                  Comment

                  • bsdtux
                    Junior Member
                    • Mar 2014
                    • 9

                    #10
                    Gald you have your problem fixed. So if I understand the problem was that you were missing a part of the link.

                    Also for the Return piece you probably could somehow look at the headers which is where return codes normally are located such as your 503, 404, and 200. and basically I wonder if you can throw a trigger somehow that can then preform maybe a database write to a user defined table.

                    As I continue my discovery of Zabbix and find a way to do what you are seeking I will try and post back.

                    Comment

                    • sopapa
                      Junior Member
                      • May 2012
                      • 8

                      #11
                      Originally posted by dtedesc1
                      OK, I was missing a crucial piece of the URL I needed to post. Once I added that, the step was able to login in successfully and match on the required string.

                      Thanks for your help.

                      I'd still like to be able to log the html response coming back from a particular step.
                      Hi im checking a cas validation application, can you show me the steps for the web monitoring?
                      I cannot do the logon on the cas.

                      thanks in advance

                      Comment

                      • ZMS
                        Junior Member
                        • Nov 2020
                        • 19

                        #12
                        hello
                        i just stumbled on you post here and im trying to do the same thing
                        im trying to log in to a web page using a token just like you but i dont really understand how do i save the token from the response.
                        do i make the variable in step 1 or in the scene?
                        and how do i write it?

                        Comment

                        Working...