Hello ! I just bought a hex Lite recently: this is my first time with Mikrotik, I have a few routers with openwrt, but I need a heat-resistant router for controlling our wood pellet boilers, and the manufacturer of the boilers told me to buy this.
Now, I wanted to run a ping monitor, so I set up e-mail. That’s working. Then I wrote a bash script and asked chatGPT to translate it to routerOS. Now, tried to paste it on ssh window but it doesn’t seem to be accepted properly, so I am trying with webfig. I clicked “system”, then “scripts”. I let the check boxes as they were, except checking “don’t require permissions”, and pasted the following:
:local hosts {
"Heiz-links"="192.168.1.40";
"Heiz-rechts"="192.168.1.41";
"Heiz-folge"="192.168.1.42";
}
:foreach host in=$hosts do={
:local ip [:pick $hosts $host];
:local name $host;
:local pingResult [/ping $ip count=1];
:if ($pingResult = "") do={
:if ([:typeof [/file find where name=("$name.fail1")]] = "nil") do={
:log info "$name is down";
/file print file="$name.report" message="Host $name ($ip) is down";
/file set "$name.fail1" contents="failed";
:local emailBody ("$name is down");
/tool e-mail send to="xx@gmail.com" subject="$name is down" body=$emailBody;
}
} else={
:if ([:typeof [/file find where name=("$name.fail1")]] != "nil") do={
:log info "$name is online";
/file remove "$name.fail1";
/file print file="$name.report" message="Host $name ($ip) is online";
:local emailBody ("$name is online");
/tool e-mail send to="xx@gmail.com" subject="$name is online" body=$emailBody;
}
}
}
Then clicked apply, and run script. Now the boilers are not connected with the router, so there is nothing with IP. So I should be getting some email. But I don’t get anything. As I said, e-mail is set up properly.
I do /tool e-mail> send to="xx@gmail.com" subject="test"
and I do get an email.
Now, obviously I was being too lazy just asking chatGPT to translate it. If the script is all wrong, then I should just try to learn, or give it up and put an openwrt access point and run my bash script there for ping. In fact, the latter is the easiest way, but I am not sure if my fritzbox4020 survive the heat, I am inclined to do the script on mikrotik. Since I have no plan to use mikrotik for other places, I don’t really want to put too much effort on it… if it’s avoidable.
I will appreciate it if you could please tell me what’s wrong, or all wrong, or I’m wrong in relying on chatGPT. I original bash script is attached, it is in use, and is working. (Currently they were on EdgeRouterX with openwrt.)
checkhost_heiz_anonym.txt (1.49 KB)