From ea0d8d5b4254aa63e92338ea82b92ce9a4498791 Mon Sep 17 00:00:00 2001 From: Guilhem Marchand Date: Wed, 20 Nov 2024 23:57:29 +0000 Subject: [PATCH] Version 2.0.19 (#199) * 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 --- docs/releasenotes.rst | 9 ++ globalConfig.json | 8 +- .../modalert_jira_service_desk_helper.py | 100 ++++++++++++------ package/default/app.conf | 1 + .../data/ui/alerts/jira_service_desk.html | 1 + package/default/transforms.conf | 2 +- 6 files changed, 85 insertions(+), 36 deletions(-) diff --git a/docs/releasenotes.rst b/docs/releasenotes.rst index 033c829..cac05b7 100644 --- a/docs/releasenotes.rst +++ b/docs/releasenotes.rst @@ -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 ============== diff --git a/globalConfig.json b/globalConfig.json index b822e63..4729ef3 100644 --- a/globalConfig.json +++ b/globalConfig.json @@ -520,6 +520,10 @@ { "value": "enabled_json", "label": "Enabled (JSON format)" + }, + { + "value": "enabled_table", + "label": "Enabled (Table format)" } ], "display": true @@ -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" } } diff --git a/package/bin/ta_service_desk_simple_addon/modalert_jira_service_desk_helper.py b/package/bin/ta_service_desk_simple_addon/modalert_jira_service_desk_helper.py index d9c26d2..9953614 100755 --- a/package/bin/ta_service_desk_simple_addon/modalert_jira_service_desk_helper.py +++ b/package/bin/ta_service_desk_simple_addon/modalert_jira_service_desk_helper.py @@ -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): @@ -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)) @@ -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 @@ -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 + '"' @@ -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, @@ -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( @@ -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)) @@ -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: "' @@ -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): @@ -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 @@ -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": "' @@ -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"] @@ -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": "' @@ -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": "' diff --git a/package/default/app.conf b/package/default/app.conf index d372fbe..4be7e09 100644 --- a/package/default/app.conf +++ b/package/default/app.conf @@ -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 diff --git a/package/default/data/ui/alerts/jira_service_desk.html b/package/default/data/ui/alerts/jira_service_desk.html index 2cc7a2d..2ed308a 100644 --- a/package/default/data/ui/alerts/jira_service_desk.html +++ b/package/default/data/ui/alerts/jira_service_desk.html @@ -132,6 +132,7 @@

JIRA main fields:

+
Enable this option to automatically add the Splunk results as diff --git a/package/default/transforms.conf b/package/default/transforms.conf index 4608655..26200ec 100644 --- a/package/default/transforms.conf +++ b/package/default/transforms.conf @@ -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]