Ad Widget

Collapse

Jira webhook sending failed: Request failed with status code 401

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmendoza
    Junior Member
    • Nov 2021
    • 6

    #1

    Jira webhook sending failed: Request failed with status code 401

    I am trying to send a test jira webhook with the following options and get "Received response with status code 401 <html> <head> <title>Unauthorized (401)....."
    alert_message TEST1
    alert_subject Zabbix to Jira TEST1 please ignore
    event_recovery_value {EVENT.RECOVERY.VALUE}
    event_source 0
    event_tags_json {EVENT.TAGSJSON}
    event_update_action {EVENT.UPDATE.ACTION}
    event_update_message {EVENT.UPDATE.MESSAGE}
    event_update_status 0
    event_update_user {USER.FULLNAME}
    event_value 1
    jira_issue_key ISSUEKEY
    jira_issue_type Support Request
    jira_password USERTOKEN
    jira_project_key PROJECTKEY
    jira_url https://jira.test.domain
    jira_user USER
    trigger_description {TRIGGER.DESCRIPTION}

    I tried this my own user account token and a service account. What could I be missing?

    Versions used
    Zabbix 5.4.2
    Jira v8.17.1

    webhook media_jira.yml default used.

  • cmendoza
    Junior Member
    • Nov 2021
    • 6

    #2
    Here is most of the debug log. I had to remove the middle due to the size restrictions.
    Attached Files

    Comment

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

      #3
      You problem is in the topic header.. Request failed with status code 401

      Your debug log is full of "unauthorized" and "Authentication failure"-s... fix your permissions.

      Comment


      • cmendoza
        cmendoza commented
        Editing a comment
        When I use the actual password for the user it works but not when I use a token.
    • cmendoza
      Junior Member
      • Nov 2021
      • 6

      #4
      Here is a screenshot of when I use the password but when I try to use a Token it fails.
      Attached Files

      Comment

      • cmendoza
        Junior Member
        • Nov 2021
        • 6

        #5
        The jira web hook does have <PLACE PASSWORD OR TOKEN> in the jira_password field parameters. I will be disabling the login for this API login and will need to use a token.
        Attached Files

        Comment

        • cmendoza
          Junior Member
          • Nov 2021
          • 6

          #6
          I am using a Personal Access Token (PAT) from Jira.

          Comment

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

            #7
            I am not much of a coder, but I have a feeling that this webhook only implements basic auth and you have to adapt it to token by yourself, whatever the field description there may say...
            Your last link describes the need to add
            "Authorization: Bearer <yourToken>" header,
            but all I can see from script, is
            Code:
            "request.AddHeader('Authorization: Basic ' + btoa(Jira.params.user + ':' + Jira.params.password));"
            Maybe replacind that line with following might help...
            Code:
            request.addHeader('Authorization: Bearer ' + btoa(Jira.params.password));
            Theres probably better coders out here, who can confirm or deny this....

            Comment


            • cmendoza
              cmendoza commented
              Editing a comment
              I updated the code and imported it as jira_test_new and tested with jira_password set to PAT token and jira_user set to my API user name (could not leave blank) but now get a slightly different error: "Received response with status code 401 {"errorMessages":["You do not have the permission to see the specified issue.","Login Required"],"errors":{}}"
              Original code still works with my API user name and password and all other entries the same, so this bit of code we need to find out how to send a Personal Access Token (PAT) to Jira for authentication.
          • cmendoza
            Junior Member
            • Nov 2021
            • 6

            #8
            I was able to find the correct code to pass the PAT to jira after some code example searching and testing. In media_jira.yml replaced
            "request.AddHeader('Authorization: Basic ' + btoa(Jira.params.user + ':' + Jira.params.password));"
            with
            "request.addHeader('Authorization: Bearer ' + Jira.params.password);"

            Maybe someone with more coding skills can modify media_jira.yml to take jira_password and check if it is a Password or Token so that the value <PLACE PASSWORD OR TOKEN> can be used as intended and pass Authentication: Bearer when a Personal Authentication Token is used.
            Last edited by cmendoza; 16-11-2021, 20:23.

            Comment

            Working...