Skip to content

Commit

Permalink
Result alerts in description as table (#194)
Browse files Browse the repository at this point in the history
* added option enabled_table for results in description

* reformat

* reformat1

* - added requests for github workflow
- removed required from globalconfig as error indicated by ucc
  • Loading branch information
schose authored Nov 20, 2024
1 parent e448560 commit ba8d59f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
7 changes: 4 additions & 3 deletions globalConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
"pattern": "^[a-zA-Z]\\w*$"
}
],
"options": {
"placeholder": "Required"
},
"field": "name",
"help": "Enter a unique name for this JIRA account.",
"required": true
Expand Down Expand Up @@ -556,6 +553,10 @@
{
"value": "enabled_json",
"label": "Enabled (JSON format)"
},
{
"value": "enabled_table",
"label": "Enabled (Table format)"
}
],
"display": true
Expand Down
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 @@ -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
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
splunk-add-on-ucc-framework>=5.44.0
splunk-add-on-ucc-framework>=5.44.0
requests

0 comments on commit ba8d59f

Please sign in to comment.