Last active
August 8, 2018 23:01
-
-
Save len0rd/86f2f0f245cd93a0ad63219b2a08bab9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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