Inject grafana annotations like a BOSS

I think it's pretty cool to post a annotations to grafana with something. To make some one life easy ear. I'm sharing it with you.

Read info node!

[
    {
        "id": "0f3990356594599b",
        "type": "tab",
        "label": "Graf annotat",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b481d84ae887617a",
        "type": "function",
        "z": "0f3990356594599b",
        "name": "send annotation to grafana",
        "func": "tn = new Date().getTime();\n\ntags=[\"from node-red\"];\nif( msg.tags != undefined ){\n    for( var t=0,tc=msg.tags.length; t<tc; t++)\n        tags.push( msg.tags[t] );\n}\n\nmsgTs = {\n    \"payload\": \n    //JSON.stringify(\n        {\n\"dashboardId\": msg.dashboardId,\n\"panelId\": msg.panelId,\n\"time\": tn,\n\"inRegion\": true,\n\"timeEnd\": tn,\n\"text\": msg.txt,\n\"tags\": tags\n    }\n    //)\n\n};\n\nif( msg[\"patch\"] ){\n    node.status({text:\"add patch:\"+JSON.stringify(msg[\"patch\"])});\n    pa = msg[\"patch\"];\n    for (const [key, value] of Object.entries(pa)) {\n      msgTs.payload[key] = value;\n    }\n}else{\n    //node.status({text:\"no patch\"});\n    \n\n}\n\n\nnode.send(msgTs);\n//node.status({ text:JSON.stringify( msg ) });",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 480,
        "wires": [
            [
                "582b616768db1a4d",
                "bdb3c1a8c406f504"
            ]
        ]
    },
    {
        "id": "bdb3c1a8c406f504",
        "type": "debug",
        "z": "0f3990356594599b",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 750,
        "y": 180,
        "wires": []
    },
    {
        "id": "6f7847275c5e6b76",
        "type": "http request",
        "z": "0f3990356594599b",
        "name": "",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "body",
        "url": "http://admin:admin@localhost:3000/api/annotations",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": true,
        "x": 790,
        "y": 520,
        "wires": [
            [
                "bdb3c1a8c406f504"
            ]
        ]
    },
    {
        "id": "582b616768db1a4d",
        "type": "change",
        "z": "0f3990356594599b",
        "name": "Set Headers",
        "rules": [
            {
                "t": "set",
                "p": "headers",
                "pt": "msg",
                "to": "{}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "headers.content-type",
                "pt": "msg",
                "to": "application/json",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "headers.accept",
                "pt": "msg",
                "to": "application/json",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 670,
        "y": 420,
        "wires": [
            [
                "6f7847275c5e6b76"
            ]
        ]
    },
    {
        "id": "9a02d7d30eafbbaa",
        "type": "link in",
        "z": "0f3990356594599b",
        "name": "send grafana annotation",
        "links": [
            "f4a11268fee11b69"
        ],
        "x": 175,
        "y": 380,
        "wires": [
            [
                "b481d84ae887617a",
                "bdb3c1a8c406f504"
            ]
        ]
    },
    {
        "id": "30fad9aefc47480e",
        "type": "comment",
        "z": "0f3990356594599b",
        "name": "Use info",
        "info": "Examples if it will get:\n\n> msg = {\n>     \"dashboardId\": 7,\n>     \"panelId\": 3,\n>     \"txt\": \"abcd\",\n>     \"tags\": [ \"huawaii plug / unplug\" ]\n> };\n> node.send(msg);\n\nregular annotation will be added.\n\n\n        \n> msg = {\n>     \"dashboardId\": 7,\n>     \"panelId\": 3,\n>     \"patch\":{\n>         \"time\": global.get(\"hu_plug_t\"),\n>         \"timeEnd\": new Date().getTime()\n>         },\n>     \"txt\": \"huawaii was charging\",\n>     \"tags\": [ \"huawaii charging\" ]\n> };\n> node.send(msg);\n\nannotation with overrite time and timeEnd will be post'ed\n\n\n\n\n",
        "x": 220,
        "y": 300,
        "wires": []
    }
]
6 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.