Skip to content

Instantly share code, notes, and snippets.

@mcm
Last active May 13, 2020 20:12
Show Gist options
  • Save mcm/fcbb9bd0e0c366626bd16f3495ecaf85 to your computer and use it in GitHub Desktop.
Save mcm/fcbb9bd0e0c366626bd16f3495ecaf85 to your computer and use it in GitHub Desktop.
alert_hec_webhook
This app is based on the alert_webhook app included by Splunk, and is subject to all applicable license terms therein.
All modifications made to that app by Hurricane Labs in the creation of this app, as of 13 May 2020, are licensed
under the MIT license as included below. Unless otherwise noted, all future modifications made by Hurricane Labs are
also licensed under the same license terms. The most recent diff showing changes made by Hurricane Labs can be found at:
https://gist.github.com/mcm/fcbb9bd0e0c366626bd16f3495ecaf85
Portions Copyright (c) 2020 Hurricane Labs
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Applications/Splunk/etc/apps/alert_webhook/default/data/ui/alerts/webhook.html b/Users/cschmidt/github/alert_hec_webhook/default/data/ui/alerts/hec_webhook.html
index 4d6ef3d..de810ba 100644
--- a/Applications/Splunk/etc/apps/alert_webhook/default/data/ui/alerts/webhook.html
+++ b/Users/cschmidt/github/alert_hec_webhook/default/data/ui/alerts/hec_webhook.html
@@ -3,14 +3,14 @@
<label class="control-label" for="webhook_url">URL</label>
<div class="controls">
- <input type="text" class="input-xlarge" name="action.webhook.param.url" id="webhook_url" placeholder="https://your.server.com/foo/bar" />
+ <input type="text" class="input-xlarge" name="action.hec_webhook.param.url" id="webhook_url" placeholder="https://your.server.com/foo/bar" />
</div>
</div>
<div class="control-group">
<div class="controls">
<span class="help-block" style="display: block; position: static; width: auto; margin-left: 0;">
Specified URL to send JSON payload via HTTP POST
- (ex., https://your.server.com/api/v1/webhook).
+ (ex., https://your.server.com:8088/services/collector).
<br />
<a href="{{SPLUNKWEB_URL_PREFIX}}/help?location=learnmore.alert.action.webhook" target="_blank"
title="Splunk help">Learn More <i class="icon-external"></i></a>
@@ -18,4 +18,16 @@
</span>
</div>
</div>
-</form>
\ No newline at end of file
+ <div class="control-group">
+ <label class="control-label" for="webhook_token">HEC Token (can be comma-delimited list)</label>
+ <div class="controls">
+ <input type="text" class="input-xlarge" name="action.hec_webhook.param.token" id="webhook_token" />
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="webhook_sourcetype">Sourcetype</label>
+ <div class="controls">
+ <input type="text" class="input-xlarge" name="action.hec_webhook.param.sourcetype" id="webhook_sourcetype" />
+ </div>
+ </div>
diff --git a/Applications/Splunk/etc/apps/alert_webhook/bin/webhook.py b/Users/cschmidt/github/alert_hec_webhook/bin/hec_webhook.py
index 548ff4c..ea13bd9 100755
--- a/Applications/Splunk/etc/apps/alert_webhook/bin/webhook.py
+++ b/Users/cschmidt/github/alert_hec_webhook/bin/hec_webhook.py
@@ -1,53 +1,57 @@
import sys
import json
+import urllib2
import csv
import gzip
from collections import OrderedDict
-from future.moves.urllib.request import urlopen, Request
-from future.moves.urllib.error import HTTPError, URLError
-def send_webhook_request(url, body, user_agent=None):
+
+def send_webhook_request(url, body, user_agent=None, token=None):
if url is None:
- sys.stderr.write("ERROR No URL provided\n")
+ print >> sys.stderr, "ERROR No URL provided"
return False
- sys.stderr.write("INFO Sending POST request to url=%s with size=%d bytes payload\n" % (url, len(body)))
- sys.stderr.write("DEBUG Body: %s\n" % body)
+ print >> sys.stderr, "INFO Sending POST request to url=%s with size=%d bytes payload" % (url, len(body))
+ print >> sys.stderr, "DEBUG Body: %s" % body
try:
- req = Request(url, body, {"Content-Type": "application/json", "User-Agent": user_agent})
- res = urlopen(req)
+ req = urllib2.Request(url, body, {"Content-Type": "application/json", "User-Agent": user_agent, "Authorization": "Splunk %s" % token})
+ res = urllib2.urlopen(req)
if 200 <= res.code < 300:
- sys.stderr.write("INFO Webhook receiver responded with HTTP status=%d\n" % res.code)
+ print >> sys.stderr, "INFO Webhook receiver responded with HTTP status=%d" % res.code
return True
else:
- sys.stderr.write("ERROR Webhook receiver responded with HTTP status=%d\n" % res.code)
+ print >> sys.stderr, "ERROR Webhook receiver responded with HTTP status=%d" % res.code
return False
- except HTTPError as e:
- sys.stderr.write("ERROR Error sending webhook request: %s\n" % e)
- except URLError as e:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment