Created
February 9, 2016 15:52
-
-
Save bkeifer/e8c037f91e6795e867f8 to your computer and use it in GitHub Desktop.
Logstash
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
def log(msg) { | |
log.debug(msg) | |
if (useLogstash) { | |
def dateNow = new Date() | |
def isoDateNow = dateNow.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") | |
def json = "{" | |
json += "\"date\":\"${dateNow}\"," | |
json += "\"isoDate\":\"${isoDateNow}\"," | |
json += "\"name\":\"log\"," | |
json += "\"message\":\"${msg}\"," | |
json += "\"smartapp\":\"${app.name}\"" | |
json += "}" | |
def params = [ | |
uri: "http://${logstash_host}:${logstash_port}", | |
body: json | |
] | |
try { | |
httpPostJson(params) | |
} catch ( groovyx.net.http.HttpResponseException ex ) { | |
log.debug "Unexpected response error: ${ex.statusCode}" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment