Skip to content

Commit

Permalink
Merge pull request #56 from guilhemmarchand/testing
Browse files Browse the repository at this point in the history
Version 1.1.7
  • Loading branch information
guilhemmarchand authored Oct 4, 2024
2 parents 566800d + 34e08f8 commit f199023
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 52 deletions.
6 changes: 6 additions & 0 deletions docs/releasenotes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release notes
#############

Version 1.1.7
=============

- Splunk UCC, SDK and other librairies refresh to very last versions
- Switch http.status_code verification from an explicit list of 2* codes to allow any 2* code, this change is to allow a workaround using Power Automate Flow to allow the deprecation of message cards by Microsoft.

Version 1.1.6
=============

Expand Down
53 changes: 13 additions & 40 deletions globalConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,41 +99,7 @@
"title": "Proxy"
},
{
"name": "logging",
"entity": [
{
"type": "singleSelect",
"label": "Log level",
"options": {
"disableSearch": true,
"autoCompleteFields": [
{
"value": "DEBUG",
"label": "DEBUG"
},
{
"value": "INFO",
"label": "INFO"
},
{
"value": "WARNING",
"label": "WARNING"
},
{
"value": "ERROR",
"label": "ERROR"
},
{
"value": "CRITICAL",
"label": "CRITICAL"
}
]
},
"defaultValue": "INFO",
"field": "loglevel"
}
],
"title": "Logging"
"type": "loggingTab"
},
{
"name": "additional_parameters",
Expand Down Expand Up @@ -199,7 +165,7 @@
"name": "ms_teams_publish_to_channel",
"label": "MS teams publish to channel",
"description": "Publish a message to a Microsoft Teams channel",
"activeResponse": {
"adaptiveResponse": {
"task": [
"Create",
"Update",
Expand All @@ -223,9 +189,16 @@
}
],
"drilldownUri": "search?q=search%20index%3D_internal%20OR%20index%3Dcim_modaction%20sourcetype%3Dta:msteams:alert:log&earliest=0&latest=",
"sourcetype": "ta:msteams:alert:log"
"sourcetype": "ta:msteams:alert:log",
"supportsCloud": true
},
"entity": [
{
"type": "checkbox",
"label": "Does use new webhook?",
"help": "Use new MS workflow webhook",
"field": "alert_ms_teams_new_webhook"
},
{
"type": "text",
"label": "Override default Webhook URL:",
Expand Down Expand Up @@ -407,9 +380,9 @@
"meta": {
"name": "TA-ms-teams-alert-action",
"restRoot": "ta_ms_teams_alert_action",
"version": "1.1.6",
"version": "1.1.7",
"displayName": "MS Teams alert action",
"schemaVersion": "0.0.3",
"_uccVersion": "5.39.1"
"schemaVersion": "0.0.7",
"_uccVersion": "5.48.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,39 @@ def process_event(helper, *args, **kwargs):

# data facts
data_json_facts = '"facts": [\n'
data_json_attachments = (
'"type": "exampleType",\n'
+ '"attachments": [\n'
+ " {\n"
+ ' "contentType": "application/vnd.microsoft.card.adaptive",\n'
+ ' "content": {\n'
+ ' "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",\n'
+ ' "type": "AdaptiveCard",\n'
+ ' "version": "1.2",\n'
+ ' "body": [\n'
+ " {\n"
+ ' "type": "TextBlock",\n'
+ ' "size": "Medium",\n'
+ ' "weight": "Bolder",\n'
+ ' "text": "'
+ alert_ms_teams_activity_title
+ '"\n'
+ " },\n"
+ " {\n"
+ ' "type": "TextBlock",\n'
+ ' "text": "",\n'
+ ' "wrap": true\n'
+ " },\n"
+ " {\n"
+ ' "type": "FactSet",\n'
+ ' "facts": [\n'
)

# Set to use new MS webhook
alert_ms_teams_new_webhook = helper.get_param("alert_ms_teams_new_webhook") == "1"
helper.log_info(
f"Use new MS workflow Webhook. Value is {alert_ms_teams_new_webhook}."
)

# Fields ordering in the message publication, defaults to alphabetical ordering
alert_ms_teams_fields_order = helper.get_param("alert_ms_teams_fields_order")
Expand Down Expand Up @@ -268,18 +301,32 @@ def process_event(helper, *args, **kwargs):

if count != 0:
data_json_facts = data_json_facts + ","
data_json_attachments = data_json_attachments + ","
key = checkstr(key)
value = checkstr(value)
data_json_facts = data_json_facts + "{\n"
data_json_facts = data_json_facts + '"name": "' + key + '",\n'
data_json_facts = data_json_facts + '"value": "' + value + '"\n'
data_json_facts = data_json_facts + "}\n"
# Add attachments new webhook
data_json_attachments += "{\n"
data_json_attachments += '"title": "' + key + ':",\n'
data_json_attachments += '"value": "' + value + '"\n'
data_json_attachments += "}\n"
count += 1
# helper.log_debug("count={}".format(count))

data_json_attachments += " ]\n"
data_json_attachments += " }\n"
data_json_attachments += " ]\n"
data_json_attachments += " }\n"
data_json_attachments += " }\n"
data_json_attachments += "]"

data_json_facts = data_json_facts + "],"

data_json = data_json + data_json_facts
if not (alert_ms_teams_new_webhook):
data_json = data_json + data_json_facts

# MS teams action, this is optional

Expand Down Expand Up @@ -361,6 +408,9 @@ def process_event(helper, *args, **kwargs):
# terminate the sections pattern
data_json = data_json + "\n" + '"markdown": false' + "\n" + "}]"

if alert_ms_teams_new_webhook:
data_json = data_json + ",\n" + data_json_attachments

# Actions statuses
has_action1 = False
has_action2 = False
Expand Down Expand Up @@ -569,7 +619,7 @@ def process_event(helper, *args, **kwargs):
use_proxy=opt_use_proxy,
)
# No http exception, but http post was not successful
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):

helper.log_error(
"Microsoft Teams publish to channel has failed!. "
Expand Down Expand Up @@ -613,7 +663,7 @@ def process_event(helper, *args, **kwargs):
response = requests.post(
record_url, headers=headers, data=record, verify=False
)
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):
helper.log_error(
"KVstore saving has failed!. url={}, data={}, HTTP Error={}, "
"content={}".format(
Expand Down Expand Up @@ -668,7 +718,7 @@ def process_event(helper, *args, **kwargs):
response = requests.post(
record_url, headers=headers, data=record, verify=False
)
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):
helper.log_error(
"KVstore saving has failed!. url={}, data={}, HTTP Error={}, "
"content={}".format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def process_event(helper, *args, **kwargs):
)

# No http exception, but http post was not successful
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):
helper.log_error(
"Microsoft Teams publish to channel has failed!. "
"url={}, data={}, HTTP Error={}, HTTP Reason={}, HTTP content={}".format(
Expand Down Expand Up @@ -181,7 +181,7 @@ def process_event(helper, *args, **kwargs):
response = requests.post(
record_url, headers=headers, data=record, verify=False
)
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):
helper.log_error(
"KVstore saving has failed!. url={}, data={}, HTTP Error={}, "
"content={}".format(
Expand Down Expand Up @@ -213,7 +213,7 @@ def process_event(helper, *args, **kwargs):
# Splunk Cloud vetting note, this communication is a localhost communication to splunkd
# and does not have to be verified
response = requests.delete(record_url, headers=headers, verify=False)
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):
helper.log_error(
"KVstore delete operation has failed!. url={}, HTTP Error={}, "
"content={}".format(
Expand Down Expand Up @@ -265,7 +265,7 @@ def process_event(helper, *args, **kwargs):
response = requests.post(
record_url, headers=headers, data=record, verify=False
)
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):
helper.log_error(
"KVstore saving has failed!. url={}, data={}, HTTP Error={}, "
"content={}".format(
Expand Down Expand Up @@ -314,7 +314,7 @@ def process_event(helper, *args, **kwargs):
# Splunk Cloud vetting note, this communication is a localhost communication to splunkd and
# does not have to be verified
response = requests.post(record_url, headers=headers, data=record, verify=False)
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):
helper.log_error(
"KVstore saving has failed!. url={}, data={}, HTTP Error={}, "
"content={}".format(
Expand Down Expand Up @@ -352,7 +352,7 @@ def process_event(helper, *args, **kwargs):
# Splunk Cloud vetting note, this communication is a localhost communication to splunkd and
# does not have to be verified
response = requests.delete(record_url, headers=headers, verify=False)
if response.status_code not in (200, 201, 204):
if not (200 <= response.status_code < 300):
helper.log_error(
"KVstore delete operation has failed!. url={}, HTTP Error={}, "
"content={}".format(record_url, response.status_code, response.text)
Expand Down
1 change: 1 addition & 0 deletions package/default/alert_actions.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ param._cam = {"task": ["Create", "Update", "Communicate"], "subject": ["incident
python.version = python3
is_custom = 1
payload_format = json
param.alert_ms_teams_new_webhook = false
param.alert_ms_teams_url =
param.alert_ms_teams_activity_title =
param.alert_ms_teams_fields_list =
Expand Down
18 changes: 18 additions & 0 deletions package/default/data/ui/alerts/ms_teams_publish_to_channel.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<form class="form-horizontal form-complex">
<div class="control-group">
<label
class="control-label"
for="ms_teams_publish_to_channel_alert_ms_teams_new_webhook"
>Check if use new webhook
</label>
<div class="controls">
<input
type="checkbox"
name="action.ms_teams_publish_to_channel.param.alert_ms_teams_new_webhook"
id="ms_teams_publish_to_channel_alert_ms_teams_new_webhook"
value="true"
/>
<span class="help-block">
If you want to use new MS workflow webhook, check this
</span>
</div>
</div>
<div class="control-group">
<label
class="control-label"
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>=2.32.3
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.1.6",
"version": "1.1.7",
"appID": "TA-ms-teams-alert-action"
}

0 comments on commit f199023

Please sign in to comment.