Hello team, i code this code:
#!/usr/bin/env python3
import sys
import json
import requests
from requests.auth import HTTPBasicAuth
# Read configuration parameters
alert_file = open(sys.argv[1])
user = sys.argv[2].split(':')[0]
print(user)
api_key = sys.argv[2].split(':')[1]
hook_url = sys.argv[3]
# Read the alert file
alert_json = json.loads(alert_file.read())
alert_file.close()
# Extract issue fields
alert_level = alert_json['rule']['level']
ruleid = alert_json['rule']['id']
description = alert_json['rule']['description']
agentid = alert_json['agent']['id']
agentname = alert_json['agent']['name']
# Set the project attributes ===> This section needs to be manually configured before running!
project_key = 'WT' # You can get this from the beggining of an issue key. For example, WS for issue key WS-5018
issuetypeid = '10002' # Check https://confluence.atlassian.com/jirakb/finding-the-id-for-issue-types-646186508.html. There's also an API endpoint to get it.
# Generate request
headers = {'content-type': 'application/json'}
issue_data = {
"update": {},
"fields": {
"summary": 'Wazuh Alert: ' + description,
"issuetype": {
"id": issuetypeid
},
"project": {
"key": project_key
},
"description": {
'version': 1,
'type': 'doc',
'content': [
{
"type": "paragraph",
"content": [
{
"text": '- Rule ID: ' + str(ruleid) + '\n- Alert level: ' + str(alert_level) + '\n- Agent: ' + str(agentid) + ' ' + agentname,
"type": "text"
}
]
}
],
},
}
}
# Send the request
response = requests.post(hook_url, data=json.dumps(issue_data), headers=headers, auth=(user, api_key))
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))) # <--- Uncomment this line for debugging
sys.exit(0)
While i am trying to run this code i got this errors:
{
"errorMessages": [
"You do not have permission to create issues in this project."
],
"errors": {}
}
I am the project lead and jira owner, how can i fix this issue ?