Skip to content

Commit

Permalink
Version 2.0.19 (#199)
Browse files Browse the repository at this point in the history
* Version 2.0.19

- Refresh Splunk UCC, Splunk Python SDK and others libs to address Appinspect vetting removal due to outdated dependencies

* Version 2.0.19

- Refresh Splunk UCC, Splunk Python SDK and others libs to address Appinspect vetting removal due to outdated dependencies

* Result alerts in description as table (#194)

* added option enabled_table for results in description

* reformat

* reformat1

* - added requests for github workflow
- removed required from globalconfig as error indicated by ucc

* Fix Issue#197
- FIPS compatibility

* Add support for dark theme

* Fix Issue#181
- Problem setting Assets custom field object #181

* release note:

---------

Co-authored-by: Andreas Roth <andreas@batchworks.de>
  • Loading branch information
guilhemmarchand and schose authored Nov 20, 2024
1 parent a0db670 commit ea0d8d5
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 36 deletions.
9 changes: 9 additions & 0 deletions docs/releasenotes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Release notes
#############

Version 2.0.19
==============

- Fix Issue#181 - Fix - Problem setting Assets custom field object #181
- Fix Issue#194 - Enhancement - Result alerts in description as table #194
- Fix Issue#197 - FIPS Support since Splunk 9.3.x - FIPS error when creating tickets #197
- Change - Upgrade all SDKs and Libraries to latest versions
- Change - Dark theme support for Configuration

Version 2.0.18
==============

Expand Down
8 changes: 6 additions & 2 deletions globalConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@
{
"value": "enabled_json",
"label": "Enabled (JSON format)"
},
{
"value": "enabled_table",
"label": "Enabled (Table format)"
}
],
"display": true
Expand Down Expand Up @@ -613,7 +617,7 @@
"restRoot": "ta_service_desk_simple_addon",
"version": "2.0.19",
"displayName": "JIRA Service Desk simple addon",
"schemaVersion": "0.0.7",
"_uccVersion": "5.48.2"
"schemaVersion": "0.0.9",
"_uccVersion": "5.53.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ def reformat_customfields(i):

return i

# This function is used to format a markdown table from json table in description
def json_to_jira_table(json_data):
# Ensure json_data is a list of dictionaries
if isinstance(json_data, dict):
json_data = [json_data]

if not json_data:
return ""

# Extract the headers from the keys of the first dictionary
headers = json_data[0].keys()

# Create the header row in bold
#header_row = f"| {' | '.join(headers)} |"
header_row = f"| {' | '.join(f'*{header}*' for header in headers)} |"

# Create the data rows
rows = []
for entry in json_data:
row = f"| {' | '.join(str(entry.get(header, '')) for header in headers)} |"
rows.append(row)

# Combine all parts into the final table
table = f"{header_row}\n" + "\n".join(rows)

return table

# This function can optionnally be used to only remove the espaced double quotes and leave the custom fields with no parsing at all
def reformat_customfields_minimal(i):
Expand Down Expand Up @@ -862,12 +888,12 @@ def query_url(
jira_dedup_full_mode = True
helper.log_debug(
"jira_dedup: jira_dedup_full_mode is set to True, the full issue data will be used"
" for the md5 calculation."
" for the sha256 calculation."
)
else:
jira_dedup_full_mode = False
helper.log_debug(
"jira_dedup: jira_dedup_full_mode is set to False, the md5 calculation scope will be restricted"
"jira_dedup: jira_dedup_full_mode is set to False, the sha256 calculation scope will be restricted"
" to the content of the jira_dedup_content."
)
helper.log_debug("jira_dedup_content={}".format(jira_dedup_content))
Expand Down Expand Up @@ -996,6 +1022,14 @@ def query_url(
+ "\n{code}"
)

elif jira_results_description in ("enabled_table"):
search_results_json = get_results_json(helper, jira_attachment_token)
if search_results_json:
search_result_table = json_to_jira_table(json.loads(search_results_json))
jira_description = ( jira_description
+ "\nSplunk search results:\n"
+ search_result_table )

data["fields"]["description"] = jira_description

# add issue type
Expand Down Expand Up @@ -1049,7 +1083,7 @@ def query_url(
jira_customfields = '"' + jira_customfields

# Add a double quote at the end if it doesn't end with }
if not jira_customfields.endswith("}"):
if not jira_customfields.endswith("}") and not jira_customfields.endswith("]"): # added to support arrays (see: Issue#181)
if not jira_customfields.endswith('"'):
jira_customfields = jira_customfields + '"'

Expand Down Expand Up @@ -1080,26 +1114,26 @@ def query_url(
)
)

# Generate an md5 unique hash for this issue
# Generate an sha256 unique hash for this issue
# If jira_dedup_full_mode is set to True, the entire json data is used
# Otherwise, jira_dedup_content was detected as filled and its content is used to perform the md5 calculation
# Otherwise, jira_dedup_content was detected as filled and its content is used to perform the sha256 calculation
if jira_dedup_full_mode:
jira_md5sum = hashlib.md5(json.dumps(data).encode())
jira_sha256sum = hashlib.sha256(json.dumps(data).encode())
else:
jira_md5sum = hashlib.md5(jira_dedup_content.encode())
jira_md5sum = jira_md5sum.hexdigest()
helper.log_debug("jira_md5sum:={}".format(jira_md5sum))
jira_sha256sum = hashlib.sha256(jira_dedup_content.encode())
jira_sha256sum = jira_sha256sum.hexdigest()
helper.log_debug("jira_sha256sum:={}".format(jira_sha256sum))

# Initiate default behaviour
jira_dedup_md5_found = False
jira_dedup_sha256_found = False
jira_dedup_comment_issue = False

# Verify the collection, if the collection returns a result for this md5 as the _key, this issue
# Verify the collection, if the collection returns a result for this sha256 as the _key, this issue
# is a duplicate (http 200)
record_url = "https://localhost:" + str(
splunkd_port
) + "/servicesNS/nobody/" "TA-jira-service-desk-simple-addon/storage/collections/data/kv_jira_issues_backlog/" + str(
jira_md5sum
jira_sha256sum
)
headers = {
"Authorization": "Splunk %s" % session_key,
Expand All @@ -1112,8 +1146,8 @@ def query_url(
if response.status_code == 200:
if jira_dedup_enabled:
helper.log_info(
"jira_dedup: An issue with same md5 hash ("
+ str(jira_md5sum)
"jira_dedup: An issue with same sha256 hash ("
+ str(jira_sha256sum)
+ ") was found in the backlog "
"collection, as jira_dedup is enabled a new comment "
"will be added if the issue is active. (status is not resolved or any other done status), entry:={}".format(
Expand All @@ -1130,7 +1164,7 @@ def query_url(
jira_backlog_key = jira_backlog_response_json["jira_key"]
jira_backlog_kvkey = jira_backlog_response_json["_key"]
jira_backlog_self = jira_backlog_response_json["jira_self"]
jira_backlog_md5 = jira_backlog_response_json["jira_md5"]
jira_backlog_sha256 = jira_backlog_response_json["jira_sha256"]
jira_backlog_ctime = jira_backlog_response_json["ctime"]

helper.log_debug("jira_backlog_key:={}".format(jira_backlog_key))
Expand Down Expand Up @@ -1256,7 +1290,7 @@ def query_url(
"jira_dedup: The issue with key "
+ str(jira_backlog_key)
+ " has the same MD5 hash: "
+ jira_backlog_md5
+ jira_backlog_sha256
+ ' and its status was set to: "'
+ jira_issue_status
+ '" (status category: "'
Expand All @@ -1276,7 +1310,7 @@ def query_url(
}

response = requests.delete(
record_url + "/" + jira_md5sum, headers=headers, verify=False
record_url + "/" + jira_sha256sum, headers=headers, verify=False
)

if response.status_code not in (200, 201, 204):
Expand All @@ -1292,25 +1326,25 @@ def query_url(
"content={}".format(response.text)
)

jira_dedup_md5_found = False
jira_dedup_sha256_found = False

else:
helper.log_info(
"jira_dedup: An issue with same md5 hash ("
+ str(jira_md5sum)
"jira_dedup: An issue with same sha256 hash ("
+ str(jira_sha256sum)
+ ") was found in the backlog "
"collection, as jira_dedup is not enabled a new issue "
"will be created, entry:={}".format(response.text)
)
jira_dedup_md5_found = True
jira_dedup_sha256_found = True

else:
helper.log_debug(
"jira_dedup: The calculated md5 hash for this issue creation request ("
+ str(jira_md5sum)
"jira_dedup: The calculated sha256 hash for this issue creation request ("
+ str(jira_sha256sum)
+ ") was not found in the backlog collection, a new issue will be created"
)
jira_dedup_md5_found = False
jira_dedup_sha256_found = False

# Try http post, catch exceptions and incorrect http return codes

Expand Down Expand Up @@ -1504,8 +1538,8 @@ def query_url(
record = (
'{"account": "'
+ str(account)
+ '", "jira_md5": "'
+ jira_backlog_md5
+ '", "jira_sha256": "'
+ jira_backlog_sha256
+ '", "ctime": "'
+ jira_backlog_ctime
+ '", "mtime": "'
Expand Down Expand Up @@ -1577,7 +1611,7 @@ def query_url(
)
jira_creation_response = response.text

# Store the md5 hash of the JIRA issue in the backlog KVstore with the key values returned by JIRA
# Store the sha256 hash of the JIRA issue in the backlog KVstore with the key values returned by JIRA
jira_creation_response_json = json.loads(jira_creation_response)
jira_created_id = jira_creation_response_json["id"]
jira_created_key = jira_creation_response_json["key"]
Expand All @@ -1597,12 +1631,12 @@ def query_url(
"Content-Type": "application/json",
}

if jira_dedup_md5_found:
if jira_dedup_sha256_found:
record = (
'{"account": "'
+ str(account)
+ '", "jira_md5": "'
+ jira_md5sum
+ '", "jira_sha256": "'
+ jira_sha256sum
+ '", "ctime": "'
+ str(time.time())
+ '", "mtime": "'
Expand All @@ -1623,9 +1657,9 @@ def query_url(
'{"account": "'
+ str(account)
+ '", "_key": "'
+ jira_md5sum
+ '", "jira_md5": "'
+ jira_md5sum
+ jira_sha256sum
+ '", "jira_sha256": "'
+ jira_sha256sum
+ '", "ctime": "'
+ str(time.time())
+ '", "mtime": "'
Expand Down
1 change: 1 addition & 0 deletions package/default/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description = The JIRA service desk simple addon allows the creation of tickets
is_visible = 1
label = JIRA Service Desk simple addon
docs_section_override = AddOns:released
supported_themes=enterprise,dark

[package]
id = TA-jira-service-desk-simple-addon
Expand Down
1 change: 1 addition & 0 deletions package/default/data/ui/alerts/jira_service_desk.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ <h4>JIRA main fields:</h4>
<option value="disabled">Disabled</option>
<option value="enabled_json">Enabled (JSON format)</option>
<option value="enabled_csv">Enabled (CSV format)</option>
<option value="enabled_table">Enabled (Table format)</option>
</select>
<span class="help-block">
<br />Enable this option to automatically add the Splunk results as
Expand Down
2 changes: 1 addition & 1 deletion package/default/transforms.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fields_list = _key, account, data, status, ctime, mtime, no_attempts
[jira_issues_backlog]
external_type = kvstore
collection = kv_jira_issues_backlog
fields_list = _key, account, status, ctime, mtime, jira_md5, jira_id, jira_key, jira_self
fields_list = _key, account, status, ctime, mtime, jira_sha256, jira_id, jira_key, jira_self

# jira_issue reference extraction
[extract_jira_issue]
Expand Down

0 comments on commit ea0d8d5

Please sign in to comment.