Python Scripts: Difference between revisions

(→‎Extensions corrector: Moved to github)
 
Line 815:
== Bulk Upload Parameters ==
 
<syntaxhighlight lang="pypython">
import socket
import json
Line 867:
</syntaxhighlight>
 
== Slack Webhook POST ==
<syntaxhighlight lang="python">
#!/usr/bin/python
import json
import requests
 
requests.packages.urllib3.disable_warnings()
 
# Create the webhook at https://my.slack.com/services/new/incoming-webhook/
webhook_url = 'https://hooks.slack.com/services/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'
slack_data = {'text': "Sev1 Incident: Pool is Down :skull:"}
 
response = requests.post(
webhook_url, data=json.dumps(slack_data),
headers={'Content-Type': 'application/json'}
)
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
</syntaxhighlight>