Skip to content

Commit da58de2

Browse files
authored
Cleanup the code a little bit
1 parent d1ca6a5 commit da58de2

File tree

1 file changed

+4
-156
lines changed

1 file changed

+4
-156
lines changed

splunklogger.groovy

Lines changed: 4 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ section("Log these power meters:") {
8080
input "powermeters", "capability.powerMeter", multiple: true, required: false
8181
}
8282
section("Log these illuminance sensors:") {
83-
input "illuminance", "capability.illuminanceMeasurement", multiple: true, required: false
83+
input "illuminances", "capability.illuminanceMeasurement", multiple: true, required: false
8484
}
8585
section("Log these batteries:") {
8686
input "batteries", "capability.battery", multiple: true, required: false
@@ -140,7 +140,7 @@ subscribe(location, "location", locationHandler)
140140
subscribe(accelerations, "acceleration", accelerationHandler)
141141
subscribe(energymeters, "energy", energyHandler)
142142
subscribe(musicplayers, "music", musicHandler)
143-
subscribe(illuminaces, "illuminance", illuminanceHandler)
143+
subscribe(lightSensor, "illuminance", illuminanceHandler)
144144
subscribe(powermeters, "power", powerHandler)
145145
subscribe(batteries, "battery", batteryHandler)
146146
subscribe(button, "button", buttonHandler)
@@ -329,83 +329,7 @@ genericHandler(evt)
329329
}
330330

331331
def batteryHandler(evt) {
332-
log.trace "$evt"
333-
def json = ""
334-
json += "{\"event\":"
335-
json += "{\"date\":\"${evt.date}\","
336-
json += "\"name\":\"${evt.name}\","
337-
json += "\"displayName\":\"${evt.displayName}\","
338-
json += "\"device\":\"${evt.device}\","
339-
json += "\"deviceId\":\"${evt.deviceId}\","
340-
json += "\"value\":\"${evt.value}\","
341-
json += "\"isStateChange\":\"${evt.isStateChange()}\","
342-
json += "\"id\":\"${evt.id}\","
343-
json += "\"description\":\"${evt.description}\","
344-
json += "\"descriptionText\":\"${evt.descriptionText}\","
345-
json += "\"installedSmartAppId\":\"${evt.installedSmartAppId}\","
346-
json += "\"isoDate\":\"${evt.isoDate}\","
347-
json += "\"isDigital\":\"${evt.isDigital()}\","
348-
json += "\"isPhysical\":\"${evt.isPhysical()}\","
349-
json += "\"location\":\"${evt.location}\","
350-
json += "\"locationId\":\"${evt.locationId}\","
351-
json += "\"unit\":\"${evt.unit}\","
352-
json += "\"source\":\"${evt.source}\",}"
353-
json += "}"
354-
//log.debug("JSON: ${json}")
355-
356-
def ssl = use_ssl.toBoolean()
357-
def local = use_local.toBoolean()
358-
def http_protocol
359-
def splunk_server = "${splunk_host}:${splunk_port}"
360-
def length = json.getBytes().size().toString()
361-
def msg = parseLanMessage(description)
362-
def body = msg.body
363-
def status = msg.status
364-
365-
if (local == true) {
366-
//sendHubCommand(new physicalgraph.device.HubAction([
367-
def result = (new physicalgraph.device.HubAction([
368-
method: "POST",
369-
path: "/services/collector/event",
370-
headers: [
371-
'Authorization': "Splunk ${splunk_token}",
372-
"Content-Length":"${length}",
373-
HOST: "${splunk_server}",
374-
"Content-Type":"application/json",
375-
"Accept-Encoding":"gzip,deflate"
376-
],
377-
body:json
378-
]))
379-
log.debug result
380-
sendHubCommand(result);
381-
return result
382-
}
383-
else {
384-
//log.debug "Use Remote"
385-
//log.debug "Current SSL Value ${use_ssl}"
386-
if (ssl == true) {
387-
//log.debug "Using SSL"
388-
http_protocol = "https"
389-
}
390-
else {
391-
//log.debug "Not Using SSL"
392-
http_protocol = "http"
393-
}
394-
395-
def params = [
396-
uri: "${http_protocol}://${splunk_host}:${splunk_port}/services/collector/event",
397-
headers: [
398-
'Authorization': "Splunk ${splunk_token}"
399-
],
400-
body: json
401-
]
402-
log.debug params
403-
try {
404-
httpPostJson(params)
405-
} catch ( groovyx.net.http.HttpResponseException ex ) {
406-
log.debug "Unexpected response error: ${ex.statusCode}"
407-
}
408-
}
332+
genericHandler(evt)
409333
}
410334

411335
def buttonHandler(evt) {
@@ -417,81 +341,5 @@ genericHandler(evt)
417341
}
418342

419343
def lockHandler(evt) {
420-
log.trace "$evt"
421-
def json = ""
422-
json += "{\"event\":"
423-
json += "{\"date\":\"${evt.date}\","
424-
json += "\"name\":\"${evt.name}\","
425-
json += "\"displayName\":\"${evt.displayName}\","
426-
json += "\"device\":\"${evt.device}\","
427-
json += "\"deviceId\":\"${evt.deviceId}\","
428-
json += "\"value\":\"${evt.value}\","
429-
json += "\"isStateChange\":\"${evt.isStateChange()}\","
430-
json += "\"id\":\"${evt.id}\","
431-
json += "\"description\":\"${evt.description}\","
432-
json += "\"descriptionText\":\"${evt.descriptionText}\","
433-
json += "\"installedSmartAppId\":\"${evt.installedSmartAppId}\","
434-
json += "\"isoDate\":\"${evt.isoDate}\","
435-
json += "\"isDigital\":\"${evt.isDigital()}\","
436-
json += "\"isPhysical\":\"${evt.isPhysical()}\","
437-
json += "\"location\":\"${evt.location}\","
438-
json += "\"locationId\":\"${evt.locationId}\","
439-
json += "\"unit\":\"${evt.unit}\","
440-
json += "\"source\":\"${evt.source}\",}"
441-
json += "}"
442-
//log.debug("JSON: ${json}")
443-
444-
def ssl = use_ssl.toBoolean()
445-
def local = use_local.toBoolean()
446-
def http_protocol
447-
def splunk_server = "${splunk_host}:${splunk_port}"
448-
def length = json.getBytes().size().toString()
449-
def msg = parseLanMessage(description)
450-
def body = msg.body
451-
def status = msg.status
452-
453-
if (local == true) {
454-
//sendHubCommand(new physicalgraph.device.HubAction([
455-
def result = (new physicalgraph.device.HubAction([
456-
method: "POST",
457-
path: "/services/collector/event",
458-
headers: [
459-
'Authorization': "Splunk ${splunk_token}",
460-
"Content-Length":"${length}",
461-
HOST: "${splunk_server}",
462-
"Content-Type":"application/json",
463-
"Accept-Encoding":"gzip,deflate"
464-
],
465-
body:json
466-
]))
467-
log.debug result
468-
sendHubCommand(result);
469-
return result
470-
}
471-
else {
472-
//log.debug "Use Remote"
473-
//log.debug "Current SSL Value ${use_ssl}"
474-
if (ssl == true) {
475-
//log.debug "Using SSL"
476-
http_protocol = "https"
477-
}
478-
else {
479-
//log.debug "Not Using SSL"
480-
http_protocol = "http"
481-
}
482-
483-
def params = [
484-
uri: "${http_protocol}://${splunk_host}:${splunk_port}/services/collector/event",
485-
headers: [
486-
'Authorization': "Splunk ${splunk_token}"
487-
],
488-
body: json
489-
]
490-
log.debug params
491-
try {
492-
httpPostJson(params)
493-
} catch ( groovyx.net.http.HttpResponseException ex ) {
494-
log.debug "Unexpected response error: ${ex.statusCode}"
495-
}
496-
}
344+
genericHandler(evt)
497345
}

0 commit comments

Comments
 (0)