Log Hub Events to remote server (syslog)?

This is great! Was just coming back to comment that this is even more important now that events are limited to 100 per device... makes it super hard to troubleshoot if you don't notice right away.

yea.. i'm loving this driver code.. i am able to go back into my Syslog server and pull up practically everything that my C5 did. I just linked my C7 via hubconnect until HE comes out with the migration tools. i was considering having the C7 send to my Syslog as well but i don't think it's necessary as the logs are practically duplicates between the 2 hubs and there's really no reason to double log "logs" lol..

Again my hat is off to @User12Hubitat and @staylorx for the excellent development of this driver!!! it's a lifesaver!!

2 Likes

Boy I hope they can just roll this into the stock config. Maybe hide it in the diagnostic interface so most users don't even see it... but this is going to be a lifesaver. I've had occasional issues with rules not firing, but not realizing until the next day... which is too late to really doubleshoot.

THANK YOU both! @User12Hubitat (that's twice you've helped me in the last week) and @staylorx.

1 Like

for those interested, you can sign up for a free loggly account, then use their forwarder service on a raspberry pi. =) That is, unless you want to run Splunk or the like at home. =)

This is very cool!! Do you have a dedicated thread for this app yet?

Staylorx was nice enough to make the changes to my original version and push those changes to my repo. The dedicated thread is here: [Beta] Push user logs to Syslog server

1 Like

@staze, (and for other folks), I don't have the $$$ for Splunk, but I've had wonderful luck running a Graylog syslog server on containers (on a server in my garage). I will look into the Loggly bits... I hadn't heard that. Thanks!

1 Like

You can use a free version of splunk that gives you 500MB a day, which is MORE than enough for most people. But I'd look at Loggly first, since it's one less thing to host.

I just downloaded and installed the driver.
What do I do to configure and use it?

Can someone post an example. Maybe add the directions to the GitHub repository.

Thanks

Chris

@cbaksa If you have installed the driver, go to your devices and and add a "virtual device". Find the syslog driver and save. From there, you'll have a new device in your devices list with whatever you named it. From there you can add your Syslog server IP, port information, Protocol you're using, and give it a friendly name as this comes in handy when you're digging through your syslog's logs. Click save and it should start reporting. Keeping in mind of any network blocks ie firewalls or routers you may have to traverse..

Hope this quick dirty bit of info helps!!

1 Like

I got it to work. Thank you.
I was missing the "Add Virtual Device" part.

Chris

1 Like

I tried to come up with a solution that works without external programs (like node-red). It still needs some polish, but I think it works.

github.com

hubitatuser12/hubitatCode/blob/master/drivers/Syslog.groovy

/**
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
metadata {
    definition (name: "Syslog", namespace: "hubitatuser12", author: "Hubitat User 12") {
        capability "Initialize"
    }
    command "disconnect"

Unfortunately the github said this is no longer there... anyone else got a syslog link that will work natively without external programs?

Try: hubitatCode/Syslog.groovy at master · staylorx/hubitatCode · GitHub

1 Like

is it possible to push to influxdb without using node-red? @muxa @User12Hubitat

FYI - it may vary based on syslog implementation, but I found that the number of columns being sent by the Syslog driver was too few for receipt by my rsyslogd server. The log message would get logged, but the metadata about the device name and device ID that are formed by the Syslog driver would not appear in my logs. To resolve this, where there are two - in the constructedString, I just added a third - to increase the number of columns being sent, Now, the metadata with device name and device ID appear in my logs.

Thanks for this - just awesome - a couple of questions:

  1. Could you share your node-RED code for this newbie?
  2. Can't you configure a web socket in node-RED to be JSON?

Could you share your node-RED code for this newbie?

Here it is:

[{"id":"3d1f1994.a4d226","type":"tab","label":"Hubitat Logs","disabled":false,"info":""},{"id":"7afc51e5.c6996","type":"websocket in","z":"3d1f1994.a4d226","name":"","server":"","client":"9367365.4710bc8","x":210,"y":200,"wires":[["e703cf77.a29a7"]]},{"id":"e703cf77.a29a7","type":"json","z":"3d1f1994.a4d226","name":"","property":"payload","action":"obj","pretty":false,"x":430,"y":200,"wires":[["9aa13982.b8b418"]]},{"id":"bb0988e7.032bf8","type":"influxdb batch","z":"3d1f1994.a4d226","influxdb":"991c0352.4c569","precision":"","retentionPolicy":"","name":"","x":980,"y":200,"wires":[]},{"id":"9aa13982.b8b418","type":"function","z":"3d1f1994.a4d226","name":"Syslog Message","func":"let time = new Date(msg.payload.time);\n\nreturn {\n    payload: [{\n        measurement: \"syslog\",\n        fields: {\n            facility_code: 1,\n            message: unescapeHtml(msg.payload.msg),\n            procid: msg.payload.id,\n            severity_code: levelToSeverityCode(msg.payload.level),\n            timestamp: time.getTime()*1000000, //convert to nanoseconds\n            version: 1\n        },\n        tags:{\n            appname: msg.payload.name,\n            facility: msg.payload.type, // \"user\",\n            host: \"hubitat\",\n            hostname: \"hubitat\",\n            severity: levelToSeverity(msg.payload.level)\n        },\n        timestamp: time\n    }]\n};\n\n// For info on the message format: https://www.influxdata.com/blog/writing-logs-directly-to-influxdb/\n\n\nfunction unescapeHtml(unsafe) {\n    if (!unsafe)\n        return unsafe;\n    return unsafe\n        .replace(/&amp;/g, \"&\")\n        .replace(/&lt;/g, \"<\")\n        .replace(/&gt;/g, \">\")\n        .replace(/&quot;/g, \"\\\"\")\n        .replace(/&#027;/g, \"'\")\n        .replace(/&#039;/g, \"'\")\n        .replace(/&apos;/g, \"'\");\n}\n\n/*\n0\tEmergency\temerg\tSystem is unusable\tThis level should not be used by applications.\n1\tAlert\talert\tShould be corrected immediately\tLoss of the primary ISP connection.\n2\tCritical\tcrit\tCritical conditions\tA failure in the system's primary application.\n3\tError\terr\tError conditions\tAn application has exceeded its file storage limit and attempts to write are failing.\n4\tWarning\twarning\tMay indicate that an error will occur if action is not taken.\tA non-root file system has only 2GB remaining.\n5\tNotice\tnotice\tEvents that are unusual, but not error conditions.\t \n6\tInformational\tinfo\tNormal operational messages that require no action.\tAn application has started, paused or ended successfully.\n7\tDebug\tdebug\tInformation useful to developers for debugging the application.\t \n*/\n\nfunction levelToSeverityCode(level) {\n    switch (msg.payload.level) {\n        case \"error\":\n            return 3;\n        case \"warn\":\n            return 4;\n        case \"info\":\n            return 6;\n        default:\n            return 7;\n    }\n}\n\nfunction levelToSeverity(level) {\n    switch (level) {\n        case \"error\":\n            return \"err\";\n        case \"warn\":\n            return \"warning\";\n        case \"info\":\n            return \"info\";\n        default:\n            return \"debug\"\n    }\n}","outputs":1,"noerr":0,"x":600,"y":200,"wires":[["d2eee62c.f29988"]]},{"id":"d2eee62c.f29988","type":"batch","z":"3d1f1994.a4d226","name":"","mode":"interval","count":10,"overlap":0,"interval":10,"allowEmptySequence":false,"topics":[],"x":770,"y":200,"wires":[["bb0988e7.032bf8"]]},{"id":"9367365.4710bc8","type":"websocket-client","path":"ws://192.168.1.70/logsocket","tls":"","wholemsg":"false"},{"id":"991c0352.4c569","type":"influxdb","hostname":"192.168.1.177","port":"8086","protocol":"http","database":"hubitat","name":"","usetls":false,"tls":""}]

Can't you configure a web socket in node-RED to be JSON?

I don't know how to

It is possible to sent data directly to InfluxDB from app or driver code (e.g. as in Syslog.groovy above), but I don't see a use for that. My use case is to be able to collect Hubitat logs externally for search a review. As far as I know Hubitat does not provide a way to tap into the logging system to have a custom logger.

Thanks for this! I’ll try this out - much appreciated.

This is working really nice !