<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Send a message to a webhook through a script alert in Feedback</title>
    <link>https://community.splunk.com/t5/Feedback/Send-a-message-to-a-webhook-through-a-script-alert/m-p/744158#M537</link>
    <description>&lt;P&gt;The script I've completed is as follows&lt;/P&gt;&lt;P&gt;#!/usr/bin/env python3&lt;BR /&gt;# -*- coding: utf-8 -*-&lt;/P&gt;&lt;P&gt;import sys&lt;BR /&gt;import json&lt;BR /&gt;import requests&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DINGTALK_WEBHOOK = "https:***"&lt;/P&gt;&lt;P&gt;def send_dingtalk_alert(computer_name, event_id, message):&lt;BR /&gt;headers = {"Content-Type": "application/json"}&lt;BR /&gt;markdown_text = f"""## Splunk alert&lt;BR /&gt;**computer_name**: {computer_name}&lt;BR /&gt;**event_id**: {event_id}&lt;BR /&gt;**message**: {message}"""&lt;BR /&gt;&lt;BR /&gt;data = {&lt;BR /&gt;"msgtype": "markdown",&lt;BR /&gt;"markdown": {&lt;BR /&gt;"title": "Windows alert",&lt;BR /&gt;"text": markdown_text&lt;BR /&gt;},&lt;BR /&gt;"at": {&lt;BR /&gt;"isAtAll": False&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt;response = requests.post(&lt;BR /&gt;DINGTALK_WEBHOOK,&lt;BR /&gt;data=json.dumps(data),&lt;BR /&gt;headers=headers,&lt;BR /&gt;timeout=10&lt;BR /&gt;)&lt;BR /&gt;if response.json().get("errcode") != 0:&lt;BR /&gt;print(f"error: {response.text}")&lt;BR /&gt;return False&lt;BR /&gt;return True&lt;BR /&gt;except Exception as e:&lt;BR /&gt;print(f"error: {str(e)}")&lt;BR /&gt;return False&lt;/P&gt;&lt;P&gt;if __name__ == "__main__":&lt;BR /&gt;try:&lt;BR /&gt;computer_name = sys.argv[1]&lt;BR /&gt;event_id = sys.argv[2]&lt;BR /&gt;event_message = sys.argv[3]&lt;BR /&gt;except IndexError:&lt;BR /&gt;print("Error: Necessary parameters are missing")&lt;BR /&gt;print("Usage: script.py &amp;lt;ComputerName&amp;gt; &amp;lt;EventCode&amp;gt; &amp;lt;Message&amp;gt;")&lt;BR /&gt;sys.exit(1)&lt;/P&gt;&lt;P&gt;success = send_dingtalk_alert(computer_name, event_id, event_message)&lt;BR /&gt;&lt;BR /&gt;if not success:&lt;BR /&gt;sys.exit(2)&lt;/P&gt;&lt;P&gt;But the content of the alert I received is incorrect, and the alert content is what I filtered from the logs, as follows ：&lt;BR /&gt;Splunk Alert Notifications&lt;BR /&gt;Alarm Event ID: Type=Error ComputerName=RJSER-FILESERIT.abc.com EventCode=* _time=*&lt;BR /&gt;Alarm event content: Type=Error ComputerName=RJSER-FILESERIT.abc.com EventCode=* _time=*&lt;/P&gt;&lt;P&gt;How can I modify the script to obtain the correct data?&lt;/P&gt;</description>
    <pubDate>Tue, 15 Apr 2025 07:42:03 GMT</pubDate>
    <dc:creator>Tomlou</dc:creator>
    <dc:date>2025-04-15T07:42:03Z</dc:date>
    <item>
      <title>Send a message to a webhook through a script alert</title>
      <link>https://community.splunk.com/t5/Feedback/Send-a-message-to-a-webhook-through-a-script-alert/m-p/744158#M537</link>
      <description>&lt;P&gt;The script I've completed is as follows&lt;/P&gt;&lt;P&gt;#!/usr/bin/env python3&lt;BR /&gt;# -*- coding: utf-8 -*-&lt;/P&gt;&lt;P&gt;import sys&lt;BR /&gt;import json&lt;BR /&gt;import requests&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DINGTALK_WEBHOOK = "https:***"&lt;/P&gt;&lt;P&gt;def send_dingtalk_alert(computer_name, event_id, message):&lt;BR /&gt;headers = {"Content-Type": "application/json"}&lt;BR /&gt;markdown_text = f"""## Splunk alert&lt;BR /&gt;**computer_name**: {computer_name}&lt;BR /&gt;**event_id**: {event_id}&lt;BR /&gt;**message**: {message}"""&lt;BR /&gt;&lt;BR /&gt;data = {&lt;BR /&gt;"msgtype": "markdown",&lt;BR /&gt;"markdown": {&lt;BR /&gt;"title": "Windows alert",&lt;BR /&gt;"text": markdown_text&lt;BR /&gt;},&lt;BR /&gt;"at": {&lt;BR /&gt;"isAtAll": False&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt;response = requests.post(&lt;BR /&gt;DINGTALK_WEBHOOK,&lt;BR /&gt;data=json.dumps(data),&lt;BR /&gt;headers=headers,&lt;BR /&gt;timeout=10&lt;BR /&gt;)&lt;BR /&gt;if response.json().get("errcode") != 0:&lt;BR /&gt;print(f"error: {response.text}")&lt;BR /&gt;return False&lt;BR /&gt;return True&lt;BR /&gt;except Exception as e:&lt;BR /&gt;print(f"error: {str(e)}")&lt;BR /&gt;return False&lt;/P&gt;&lt;P&gt;if __name__ == "__main__":&lt;BR /&gt;try:&lt;BR /&gt;computer_name = sys.argv[1]&lt;BR /&gt;event_id = sys.argv[2]&lt;BR /&gt;event_message = sys.argv[3]&lt;BR /&gt;except IndexError:&lt;BR /&gt;print("Error: Necessary parameters are missing")&lt;BR /&gt;print("Usage: script.py &amp;lt;ComputerName&amp;gt; &amp;lt;EventCode&amp;gt; &amp;lt;Message&amp;gt;")&lt;BR /&gt;sys.exit(1)&lt;/P&gt;&lt;P&gt;success = send_dingtalk_alert(computer_name, event_id, event_message)&lt;BR /&gt;&lt;BR /&gt;if not success:&lt;BR /&gt;sys.exit(2)&lt;/P&gt;&lt;P&gt;But the content of the alert I received is incorrect, and the alert content is what I filtered from the logs, as follows ：&lt;BR /&gt;Splunk Alert Notifications&lt;BR /&gt;Alarm Event ID: Type=Error ComputerName=RJSER-FILESERIT.abc.com EventCode=* _time=*&lt;BR /&gt;Alarm event content: Type=Error ComputerName=RJSER-FILESERIT.abc.com EventCode=* _time=*&lt;/P&gt;&lt;P&gt;How can I modify the script to obtain the correct data?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 07:42:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Feedback/Send-a-message-to-a-webhook-through-a-script-alert/m-p/744158#M537</guid>
      <dc:creator>Tomlou</dc:creator>
      <dc:date>2025-04-15T07:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Send a message to a webhook through a script alert</title>
      <link>https://community.splunk.com/t5/Feedback/Send-a-message-to-a-webhook-through-a-script-alert/m-p/744164#M538</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/309325"&gt;@Tomlou&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dont think you can read in the arguments in that way when running as a modinput, I'd recommend checking out&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.4.1/AdvancedDev/ModInputsExample" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.4.1/AdvancedDev/ModInputsExample&lt;/A&gt;&amp;nbsp;which has a working example that you can tweak.&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could also look at the following example by&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/1861"&gt;@LukeMurphey&lt;/a&gt;&amp;nbsp;&lt;A href="https://github.com/LukeMurphey/splunk-modular-alert-example/blob/master/src/bin/make_a_log_message.py" target="_blank"&gt;https://github.com/LukeMurphey/splunk-modular-alert-example/blob/master/src/bin/make_a_log_message.py&lt;/A&gt;&amp;nbsp;which could also get you started!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":glowing_star:"&gt;🌟&lt;/span&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Did this answer help you?&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;If so, please consider:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Adding karma to show it was useful&lt;/LI&gt;&lt;LI&gt;Marking it as the solution if it resolved your issue&lt;/LI&gt;&lt;LI&gt;Commenting if you need any clarification&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Your feedback encourages the volunteers in this community to continue contributing&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 09:41:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Feedback/Send-a-message-to-a-webhook-through-a-script-alert/m-p/744164#M538</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-04-15T09:41:54Z</dc:date>
    </item>
  </channel>
</rss>

