Hello,
Need to filter some services by country.
Using the following script to download and create a list:
ip firewall address-list
:local update do={
:do {
:local data ([:tool fetch url=$url output=user as-value]->"data")
:local array [find dynamic list=allowed-countries]
:foreach value in=$array do={:set array (array,[get $value address])}
:while ([:len $data]!=0) do={
:if ([:pick $data 0 [:find $data "\n"]]~"^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}") do={
:local ip ([:pick $data 0 [:find $data $delimiter]].$cidr)
:do {add list=allowed-countries address=$ip comment=$description timeout=60d} on-error={
:do {set ($array->([:find $array $ip]-[:len $array]/2)) timeout=90d} on-error={}
}
}
:set data [:pick $data ([:find $data "\n"]+1) [:len $data]]
}
} on-error={:log warning "Address list <$description> update failed"}
}
$update url=https://www.ipdeny.com/ipblocks/data/countries/ro.zone description="Romania" delimiter=("\n")
Have a schedule to update the list and it works.
The problem is: if the source I am downloading the list from goes offline, the list will not be updated and will become empty if the router is not rebooted. If rebooted and the source is offline, the list will not be populated at all. Access to the filtered service will be down.
Thus, I need a way to check if a specific list name is empty.
At the moment I am thinking to add a Telegram notification on-error, making it:
} on-error={:log warning "Address list <$description> update failed"; /tool fetch "https://api.telegram.org/botX:Y/sendmessage?chat_id=MyID&text=List $description download failed" keep-result=no;}
Still, this only notifies me if the source is temporary down and not if the list is empty.
My searching skills are subpar today or it is not possible?
Thank you.