Community discussions

MikroTik App
 
CrazyMonkey
just joined
Topic Author
Posts: 5
Joined: Wed Feb 03, 2010 11:44 pm
Location: Johannesburg

Logic assistance with script

Sun Aug 28, 2011 6:09 pm

Hi all,
I have read through nearly every published script I can find and I see parts of what I need but I am struggeling with the logic to simply achieve the whole script as I need it.

Check that I am getting the static address issued to me by the ISP.

I script the PPP interface to go down, wait 5 seconds, and come back up.

Compare the issued IP to the IP address it should be.
If it is fine... finish, otherwise

Send an email once and keep testing until it is fixed.
Once it is fixed send an email once and finish.

I have got the script to reset the PPP, get and compare the IP addresses and send email if it is no the same.
The email logic is testing me...

The catch I have is only sending each email once and looping to reset every minute or so thereafter.
and....
What would happen if I am running the script every 10 minutes and the fix takes 30 minutes to do, the loop would still be running when the script is instructed to run again. Does the ROS script logic account for this or would I need to cater for that?

I would appreciate any assistance in getting this scripted.

The fact that the link would be unusable with it going up and down is not relevant, the account is a dummy test account and the routers sole function in life is to perform this test, there are no clients behind the public interface.

My script todate is:
==================================
:local staticIP "10.0.0.1"

/interface pppoe-client disable [find name="pppoe-out1"]
:delay 5
/interface pppoe-client enable [find name="pppoe-out1"]
:delay 5
:local newIP [/ip address get [find interface="pppoe-out1"] address]
:set newIP [:pick $newIP 0 ([:len $newIP]-3) ]

:if ($newIP != $staticIP) do={
/tool e-mail send to="me@mail.com" subject="Static address NOT being issued" body="\n Problem with static addresses \n\nIP $staticIP / $newIP"
}
==================================

Thank you in advance for considering my request.
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

Re: Logic assistance with script

Tue Aug 30, 2011 8:37 pm

This should make a pretty good start, save as a script and schedule it as frequent at you wish, it prevents multiple concurrent runs by it self (RouterOS wont)
:global scriptRunning
:if ([:len $scriptRunning] = 0) do={
    :set scriptRunning "1"
    
    :local staticIP "10.0.0.1"
    :local infName "pppoe-out1"
    :local emailTo "me@mail.com"
    
    :local done 0
    :local attempts 0
    :do {
        /interface pppoe-client {
            :local oInf [find name=$infName] 
            disable $oInf
            :delay 5
            enable $oInf
        }
        
        /ip address {
            :local gotIP 0
            :do {
                :delay 1
                :local oAdr [find interface=$infName]
                :if ([:len $oAdr] > 0) do={
                    :set gotIP 1
                    :local newIP [get $oAdr address]
                    :set newIP [:pick $newIP 0 [:find $newIP "/"]]
                    :if ($newIP = $staticIP) do={
                        /tool e-mail send to=$emailTo subject="Static address being issued" body="\n No problem with static addresses after $attempts retries\n\nIP $staticIP / $newIP"
                        :set done 1
                    } else={
                        :if ($attempts = 0) do={
                            /tool e-mail send to=$emailTo subject="Static address NOT being issued" body="\n Problem with static addresses \n\nIP $staticIP / $newIP"
                        }
                        :set attempts ($attempts + 1)
                    }
                }
            } while=($gotIP != 1)
        }
    } while=($done != 1)

    :set scriptRunning ""
}
 
CrazyMonkey
just joined
Topic Author
Posts: 5
Joined: Wed Feb 03, 2010 11:44 pm
Location: Johannesburg

Re: Logic assistance with script

Wed Aug 31, 2011 1:15 am

Thank you very much.

Who is online

Users browsing this forum: No registered users and 6 guests