# Inject grafana annotations like a BOSS

**URL:** https://discourse.nodered.org/t/inject-grafana-annotations-like-a-boss/73164
**Category:** Share Your Projects
**Created:** [4 January 2023 15:17 UTC](https://discourse.nodered.org/t/inject-grafana-annotations-like-a-boss/73164 "2023-01-04T15:17:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yOyOeK1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yoyoek1/32/73011_2.png) [@yOyOeK1](https://discourse.nodered.org/u/yOyOeK1)
#### Post date: [4 January 2023 15:17 UTC](https://discourse.nodered.org/t/inject-grafana-annotations-like-a-boss/73164/1 "2023-01-04T15:17:46Z")

</div>

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.

 ![Screenshot from 2023-01-04 10-11-38](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae26fdf758ce3c84e77a328e1fdf8c950b505a28.png)

 ![Screenshot from 2023-01-04 10-18-07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20aeb92821d5c0bc69707f8ba94f881320c0ca5a.png)

Read info node!

```auto
[
    {
        "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": []
    }
]

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [5 March 2023 15:18 UTC](https://discourse.nodered.org/t/inject-grafana-annotations-like-a-boss/73164/2 "2023-03-05T15:18:33Z")

</div>

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