Community discussions

MikroTik App
 
mode
newbie
Topic Author
Posts: 37
Joined: Sun Jun 03, 2018 12:12 am

Notify when route changes

Mon Oct 25, 2021 12:53 pm

Hi
i have two default routes (to the internet) on my mikrotik. When the primary route goes offline the routes switches automaticaly to the second. This works fine.
I am looking for a way to inform an external system about the change of the default route. Is this possible with mikrotik? Perhaps using SNMP, MQTT, or HTTP Request? As i see mikrotik does not even log this route change in its own logfile.

BR

mode
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Notify when route changes  [SOLVED]

Mon Oct 25, 2021 4:29 pm

You can play around with logging rules, i.e.
/system logging
add topics=route action=memory prefix="Route Changes"
 
mode
newbie
Topic Author
Posts: 37
Joined: Sun Jun 03, 2018 12:12 am

Re: Notify when route changes

Mon Oct 25, 2021 6:34 pm

This helped perfectly. Thanks a lot.

To give someting back here my solution to find out the active default route

In Mikrotik: Add a log action (type=remote) with ip destination from a host, where NodeRED is running. Use Option BSD Syslog. I used Port 20514
Add a log rule to send all "route" logs to the new log action. Then you are done on the mikrotik.

In NodeRED this flow will extract the comment of the active route, when it changes:
[
    {
        "id": "743ea3c6.a7384c",
        "type": "tab",
        "label": "Mikrotik active Route",
        "disabled": false,
        "info": ""
    },
    {
        "id": "2ee0f510.7df702",
        "type": "syslog-input",
        "z": "743ea3c6.a7384c",
        "name": "syslog",
        "socktype": "udp",
        "address": "",
        "port": 20514,
        "topic": "",
        "x": 360,
        "y": 300,
        "wires": [
            [
                "b980ea19.91ba28"
            ]
        ]
    },
    {
        "id": "7ed62eb5.61b06",
        "type": "debug",
        "z": "743ea3c6.a7384c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1030,
        "y": 300,
        "wires": []
    },
    {
        "id": "b980ea19.91ba28",
        "type": "join",
        "z": "743ea3c6.a7384c",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "1",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 630,
        "y": 300,
        "wires": [
            [
                "1e1a90cb.979067"
            ]
        ]
    },
    {
        "id": "1e1a90cb.979067",
        "type": "function",
        "z": "743ea3c6.a7384c",
        "name": "",
        "func": "var state = 0;\nvar ret= {\"payload\": undefined};\n\nmsg.payload.forEach(function(element,index){\n    switch (state) {\n        case 0:\n            if (element.msg == \"Select route\"){\n                state++;\n            }\n            break;\n        case 1:\n            if (element.msg.includes(\"comment\")){\n                state++;\n                ret.payload = element.msg.trim().replace(\"comment=\", \"\");\n            }\n            break;\n    }\n});\nreturn ret;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 640,
        "y": 380,
        "wires": [
            [
                "7ed62eb5.61b06"
            ]
        ]
    }
]