Ad Widget

Collapse

Unable to do a Regex to extract a bearer token.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tonyv81
    Junior Member
    • Mar 2023
    • 13

    #1

    Unable to do a Regex to extract a bearer token.

    Hi, could someone assist us to create a working regex.
    We use this regex:name="access_token" content="([0-9a-z]{36})" in a web monitoring step.
    Step "Bearer Token" [1 of 2] failed: error in step variables "{BearerToken}=regex:name="access_token" content="([0-9a-z]{36})"": cannot extract the value of "{BearerToken}" from response
    ​Kind regards,
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    To create a working regex, need to at least know the source string(s) .
    And what exactly do you want to get at the output.

    Comment

    • Tonyv81
      Junior Member
      • Mar 2023
      • 13

      #3
      Hi Hamardaban, Thank you for the response, this is de value we receive from our request {"access_token":"05312e3e-6a77-4ff2-9ac8-255b12910dc2","token_type":"bearer","expires_in":86399,"scope" :"read write","updated_at":1689760701473}
      And we wan't to extract the token 05312e3e-6a77-4ff2-9ac8-255b12910dc2 out of it to use it later on as a variable.

      Do you have also experiënce with Oath 2.0 in Zabbix?

      Kind regards,
      Tony

      Comment

      • Hamardaban
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • May 2019
        • 2713

        #4
        In your case, the expression for the macro can be like this
        Code:
        regex:"access_token":"([a-f0-9-]{36})",​
        Only I didn't understand where you want to use this expression? It seems that the information between the steps is not transmitted in web checks. That is, it will not work to use the result of the first step as input parameters of the second step. (or I don't know about it)
        A "Script" item is probably more suitable for you.​

        Comment

        • Hamardaban
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • May 2019
          • 2713

          #5
          Pls look at this example of JavaScript:


          (taken from https://www.zabbix.com/forum/zabbix-...n-header/page2 )

          Comment

          Working...