Skip to content

Instantly share code, notes, and snippets.

@len0rd
Last active August 8, 2018 23:01
Show Gist options
  • Save len0rd/86f2f0f245cd93a0ad63219b2a08bab9 to your computer and use it in GitHub Desktop.
Save len0rd/86f2f0f245cd93a0ad63219b2a08bab9 to your computer and use it in GitHub Desktop.
import groovy.grape.Grape
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.2')
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON
import groovy.json.JsonSlurper
def urlToSendTo = 'https://hooks.slack.com/services/token/tokenAgain/evenMoreToken'
def message = """{
"attachments": [
{
"fallback": "Today's status update",
"color": "danger",
"title": "<!date^@@DATE^{date_short}|Today's> Status Update",
"text": "I recorded xxx total errors yesterday. Scrapes that failed to start or collected no records are shown below",
"fields": [
{
"title": "Failed to start",
"value": "123",
"short": true
},
{
"title": "No Collection",
"value": "456",
"short": true
}
],
"actions": [
{
"type": "button",
"text": "see failures",
"url": "https://lenords.net",
"style": "danger"
},
{
"type": "button",
"text": "see no collection scrapes",
"url": "https://lenords.net",
"style": "danger"
}
]
}
]
}"""
def now = (new Date()).getTime().toString().substring(0, 10)
println "using date" + now
message = message.replace('@@DATE', now)
def jsonMessage = new JsonSlurper().parseText(message)
def client = new RESTClient(urlToSendTo)
println "post"
def response = client.post(requestContentType: JSON, body: jsonMessage)
println "done"
if (response.getStatus() != 200) {
println "bad response!"
} else {
println "good response!"
}
println response.getData().toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment