Sending device diagnostics with a webhook


#1

Hi!

I’m currently trying to setup a webhook that listens for “spark/device/diagnostics/update” events (diagnostic information) and posts to a database. However since the values in the data aren’t connected to any variables I can’t seem to use the json: {} declaration in the custom template. And sending PARTICLE_EVENT_DATA gives a really weird format and does not produce a good json.

My webhook:

{
    "event": "spark/device/diagnostics/update",
    "deviceID": "-",
    "url": "-",
    "requestType": "POST",
    "noDefaults": true,
    "rejectUnauthorized": true,
    "json": {
        "device": {
            "system": {
                "uptime": "{{uptime}}",
                "memory": {
                    "total": "{{total}}",
                    "used": "{{used}}"
                }
            },
            "network": {
                "connection": {
                    "status": "{{{status}}}",
                    "error": "{{error}}",
                    "disconnects": "{{disconnects}}",
                    "attempts": "{{attempts}}",
                    "disconnect": "{{disconnect}}"
                },
                "signal": {
                    "rssi": "{{rssi}}",
                    "strength": "{{strength}}",
                    "quality": "{{quality}}",
                    "qualityv": "{{qualityv}}",
                    "at": "{{at}}",
                    "strengthv": "{{strengthv}}"
                }
            },
            "cloud": {
                "connection": {
                    "status": "{{status}}",
                    "error": "{{error}}",
                    "attempts": "{{attempts}}",
                    "disconnect": "{{disconnect}}"
                },
                "disconnects": "{{disconnects}}",
                "publish": {
                    "rate_limited": "{{rate_limited}}"
                },
                "coap": {
                    "unack": "{{unack}}"
                }
            }
        },
        "service": {
            "device": {
                "status": "{{status}}"
            },
            "coap": {
                "round_trip": "{{round_trip}}"
            },
            "cloud": {
                "uptime": "{{uptime}}",
                "publish": {
                    "sent": "{{sent}}"
                }
            }
        }
    },
    "query": {
        "auth": "-"
    }
}

I’m aware that the current code is wrong since there are no variables with the names I’ve declared.

How can I send the data from the diagnostics event while preserving a good json format?

Thanks!


#2

Could you show how weird?

Not sure what you mean by that.
I’d expect the event to contain actual data an no variables, but you can extract the data from the event body by refering to the key entries for your custom template.

Can you show your template too?


#3

Turned out the “weird format” was very easy to edit after I grabbed it from the database. So I was able to parse it as a JSON anyway!