Help with HTTP monitor in existing flow?

Hi there,

I need some help monitoring a web page using a HTTP monitor. I simply want to know when the HTTP server is no longer accessible.

My current flow is attached below (too big to paste).

Thanks

[
    {
        "id": "82df664307dddebe",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "782629be73fc1d1a",
        "type": "switch",
        "z": "82df664307dddebe",
        "name": "Check if found",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 560,
        "y": 160,
        "wires": [
            [
                "f2c7f815bd6d6233"
            ],
            [
                "72b9d81abf404f96"
            ]
        ]
    },
    {
        "id": "f2c7f815bd6d6233",
        "type": "change",
        "z": "82df664307dddebe",
        "name": "Kermit Up",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 760,
        "y": 120,
        "wires": [
            [
                "8baace6765923d9d"
            ]
        ]
    },
    {
        "id": "72b9d81abf404f96",
        "type": "change",
        "z": "82df664307dddebe",
        "name": "Kermit Down",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 770,
        "y": 200,
        "wires": [
            [
                "8baace6765923d9d"
            ]
        ]
    },
    {
        "id": "8baace6765923d9d",
        "type": "rbe",
        "z": "82df664307dddebe",
        "name": "Filter status changes only",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1030,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "a1568a1929df557c",
        "type": "ping",
        "z": "82df664307dddebe",
        "protocol": "Automatic",
        "mode": "timed",
        "name": "server1",
        "host": "192.168.1.1",
        "timer": "5",
        "inputs": 0,
        "x": 290,
        "y": 160,
        "wires": [
            [
                "782629be73fc1d1a"
            ]
        ]
    }
]

Tell us what the problem is with that flow.

There is no problem with this flow,

I want to add a flow for monitoring HTTP GET instead of PING, and output the result in the same format so I can be notified when the website is unreachable.

Thanks

What do you get from the http node when it succeeds and when it fails?

Does a Catch node catch the error when it fails?

Yea, using the web-watch node or even HTTP-in node, it just spits out the HTTP header. Not sure how to change that to 1 or 0.

"<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-NZ"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="_2y1BsvFrbl3i1nghDNJWw">(function(){var _g={kEI:'wOErZ6OgLYfp4-EPyrTByAM',kEXPI:'0,56826,3643450,666,442,541533,2891,8349,98967,162437,23024,6700,96769,26743,10962,23350,22436,9779,62658,76208,15816,1804,7734,27535,11813,1633,9710,3785,15783,21780,5303,5213698,114,378,37,8831981,1567,1,78,24,1,6,1,6,1,6,7,43,7439471,16496112,4043709,16673,2169858,23029351,8163,4636,16436,29939,54106,11643,10979,15165,8181,49430,14119,7549,6756,2639,13503,7737,9139,3077,1522,328,4459,1766,23406,1,6,4577,5633,687,6592,17478,5785,1341,13707,9094,6538,4843,2230,1066,3898,3869,1908,12565,797,11897,4973,10667,9534,1492,1765,597,1802,1313,7827,285,3029,363,219,2,2,3,1451,41,1930,2,3,1995,2205,5746,866,892,1,4361,530,2570,4,641,..."

You should be using an http request node.

Oh ok, but do I need a trigger to activate that?

Probably an Inject node would be better than a Trigger node.

Ok here is what I have come up with. I feel like I am close however I just cannot get it to differentiate between true and false based on the state of the HTTP API request.

The HTTP request spits out the version just fine when all is up and running. But when down, it spits out an error (to be expected).

I need to somehow differentiate between the version being true and the error being false. I also dont really want to use the version as a string as every time I update frigate this will need to be changed.

I tried using msg.payload for the version when up, and msg.error for the error when its down, but it appears it does not matter if sending the version string or the error, it reports as msg.payload. I think this is where I am getting confused.

[
    {
        "id": "a962f6295a14250c",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "712bde0315f4267b",
        "type": "change",
        "z": "a962f6295a14250c",
        "name": "frigate Up",
        "rules": [
            {
                "t": "set",
                "p": "string[12]",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 900,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "360ff778ddacb2c1",
        "type": "http request",
        "z": "a962f6295a14250c",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://192.168.1.1:5000/api/version",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 430,
        "y": 420,
        "wires": [
            [
                "488e63f72424611e",
                "712bde0315f4267b"
            ]
        ]
    },
    {
        "id": "0c3983513a892915",
        "type": "inject",
        "z": "a962f6295a14250c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "60",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 430,
        "y": 340,
        "wires": [
            [
                "360ff778ddacb2c1"
            ]
        ]
    },
    {
        "id": "7c3125d4e30c5cf0",
        "type": "rbe",
        "z": "a962f6295a14250c",
        "name": "Filter status changes only",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload:string[91]",
        "topi": "topic",
        "x": 1190,
        "y": 380,
        "wires": [
            [
                "c6cc49afefbe3bec"
            ]
        ]
    },
    {
        "id": "488e63f72424611e",
        "type": "change",
        "z": "a962f6295a14250c",
        "name": "frigate Down",
        "rules": [
            {
                "t": "set",
                "p": "payload:string[91]",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 910,
        "y": 380,
        "wires": [
            [
                "7c3125d4e30c5cf0"
            ]
        ]
    },
    {
        "id": "c6cc49afefbe3bec",
        "type": "debug",
        "z": "a962f6295a14250c",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1500,
        "y": 420,
        "wires": []
    },
    {
        "id": "a12ed1c1d81e0631",
        "type": "rbe",
        "z": "a962f6295a14250c",
        "name": "Filter status changes only",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1190,
        "y": 440,
        "wires": [
            []
        ]
    }
]

Add a debug node to the output of the http request and show us what you get when the server is up and when it is down. Set the debug node Output Complete Message.

Thanks,

This is the response when the host is reachable.

{"_msgid":"7eb0d11c2e05d255","payload":"0.14.1-f4f3cfa","topic":"","statusCode":200,"headers":{"server":"nginx/1.25.3","date":"Fri, 08 Nov 2024 09:44:53 GMT","content-type":"text/html; charset=utf-8","content-length":"14","connection":"keep-alive","x-node-red-request-node":"776257c0"},"responseUrl":"http://192.168.1.1:5000/api/version","redirectList":[],"retry":0}

and this is unreachable.

{"_msgid":"650de2b5eb810460","payload":"RequestError: connect ECONNREFUSED 172.16.104.3:5000 : http://192.168.1.1:5000/api/version","topic":"","statusCode":"ECONNREFUSED"}

Why not add a switch node that test msg.statusCode to see if it is equal to 200?
If it is, you have a valid response, if it is not you have an error.

Yes, I could do. I need to report both True and False states.

Just tried this too, doesnt work! This is driving me nuts.

[
    {
        "id": "dd7ffb79bba7dda6",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e571c52a05135181",
        "type": "http request",
        "z": "dd7ffb79bba7dda6",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://192.168.1.1:5000/api/version",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 310,
        "y": 180,
        "wires": [
            [
                "12268d386e49ff3a"
            ]
        ]
    },
    {
        "id": "c08be775cad8c211",
        "type": "inject",
        "z": "dd7ffb79bba7dda6",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 180,
        "wires": [
            [
                "e571c52a05135181"
            ]
        ]
    },
    {
        "id": "12268d386e49ff3a",
        "type": "switch",
        "z": "dd7ffb79bba7dda6",
        "name": "Check if found",
        "property": "statusCode",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": "404",
                "vt": "num"
            },
            {
                "t": "gt",
                "v": "200",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 520,
        "y": 180,
        "wires": [
            [
                "11489db6695addc4",
                "d15d850dfe5110d8"
            ],
            [
                "507405c96af9eccc"
            ]
        ]
    },
    {
        "id": "7edd7baebf102f90",
        "type": "rbe",
        "z": "dd7ffb79bba7dda6",
        "name": "Filter status changes only",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": false,
        "property": "statusCode",
        "topi": "topic",
        "x": 950,
        "y": 180,
        "wires": [
            [
                "c41bb7f88ea91170"
            ]
        ]
    },
    {
        "id": "c41bb7f88ea91170",
        "type": "debug",
        "z": "dd7ffb79bba7dda6",
        "name": "debug 6",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 970,
        "y": 320,
        "wires": []
    },
    {
        "id": "11489db6695addc4",
        "type": "change",
        "z": "dd7ffb79bba7dda6",
        "name": "frigateOffline",
        "rules": [
            {
                "t": "set",
                "p": "statusCode",
                "pt": "msg",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 710,
        "y": 120,
        "wires": [
            [
                "7edd7baebf102f90"
            ]
        ]
    },
    {
        "id": "507405c96af9eccc",
        "type": "change",
        "z": "dd7ffb79bba7dda6",
        "name": "frigateOnline",
        "rules": [
            {
                "t": "set",
                "p": "statusCode",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 710,
        "y": 240,
        "wires": [
            [
                "7edd7baebf102f90"
            ]
        ]
    },
    {
        "id": "d15d850dfe5110d8",
        "type": "debug",
        "z": "dd7ffb79bba7dda6",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 40,
        "wires": []
    }
]

you have used > 200 and > 404. (> means Greater Than. did you mean to use == or >= ?)

If you get a 200 or 404 you will get no output

Probably better to use something like

Thanks, but I still cannot get True and False responses from the filter node.

[{"id":"dd7ffb79bba7dda6","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"e571c52a05135181","type":"http request","z":"dd7ffb79bba7dda6","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://192.168.1.1:5002/api/version","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":310,"y":180,"wires":[["12268d386e49ff3a"]]},{"id":"c08be775cad8c211","type":"inject","z":"dd7ffb79bba7dda6","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":180,"wires":[["e571c52a05135181"]]},{"id":"12268d386e49ff3a","type":"switch","z":"dd7ffb79bba7dda6","name":"Check if found","property":"statusCode","propertyType":"msg","rules":[{"t":"btwn","v":"200","vt":"num","v2":"201","v2t":"num"},{"t":"btwn","v":"400","vt":"num","v2":"499","v2t":"num"}],"checkall":"true","repair":false,"outputs":2,"x":520,"y":180,"wires":[["11489db6695addc4"],["507405c96af9eccc"]]},{"id":"7edd7baebf102f90","type":"rbe","z":"dd7ffb79bba7dda6","name":"Filter status changes only","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":950,"y":180,"wires":[["b00eceba8048fbc6"]]},{"id":"11489db6695addc4","type":"change","z":"dd7ffb79bba7dda6","name":"frigateOffline","rules":[{"t":"set","p":"statusCode","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":120,"wires":[["7edd7baebf102f90"]]},{"id":"507405c96af9eccc","type":"change","z":"dd7ffb79bba7dda6","name":"frigateOnline","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":240,"wires":[["7edd7baebf102f90","6b3d5b36e49b8671"]]},{"id":"b00eceba8048fbc6","type":"debug","z":"dd7ffb79bba7dda6","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1260,"y":180,"wires":[]},{"id":"6b3d5b36e49b8671","type":"debug","z":"dd7ffb79bba7dda6","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":360,"wires":[]}]

Why would you think you would?

You should switch on status code and if the msg comes out of the 200 port, it was successful. If it comes out of the 400 (or any other) it was not.

If you want payload to be true after the 200 add a change node to set payload to true.