Blog.gowifi

Blog.gowifi

logos (other)

Logos

Go Wireless NZ

Follow by Email

Thursday, July 24, 2014

Reboot PoE Port on MikroTik if the device doesn't respond to ping

Scenario:
You have devices being powered off a MikroTik Routerboard that has POE-OUT capability and one or more of these devices requires to be rebooted as it stops responding.

Resolution:
We're going to put a script on the MikroTik that checks for pings being returned, and after it doesn't respond for X amount of pings, it will turn the port off and back on again



Step 1: Open up Winbox, and under System > Scripts, Click on the blue plus to create a new script.

Name it PortReboot and put the following text in the source box, changing the variables at the top to suit what your after:

# Change the address of the device you wish to ping
:local PingAddress 172.17.0.2

# How many times it's to ping the address before turning the PoE Off and on Again
:local PingCount 5

# The port that you'd like to reboot
:local PoEPort ether2

# How long the port is to be turned off for
:local PoETime 10

# When the port is turned back on, what state do you want it to go back to (Uncomment only one)
#:local PortState forced-on
#:local PortState auto-on

#Optional: Have it email you when this happens. You'll need to uncomment the part in the script also.
#Email Alerts that the port has been rebooted

:local EmailAddress [email protected]
:local SMTPServer smtp.example.co.nz
:local SMTPUser [email protected]
:local SMTPPassword Passw0rd

{
  :if ([/ping $PingAddress count=$PingCount] = 0) do={
        /interface ethernet set $PoEPort poe-out=off
        delay $PoETime
        /interface ethernet set $PoEPort poe-out=$PortState
  

#    /tool e-mail send to=$EmailAddress \
#    subject="Port $PoEPort has been rebooted" server=$SMTPServer \
#    user=$SMTPUser password=$SMTPPassword
    }
}





Also, an E-Mail alert has been commented out of the script, you can un-comment this and adjust it to send you an alert when the script runs.

Step 2: Add a schedule to run the script: Go to System > Scheduler, Click on the blue plus to create a new schedule and add following:

name=PortRebootScheduler
start time=startup
interval=1m
on-event=PortReboot

----------------------------------------------------------------------------------------------

Thanks for reading!  Tell us what you think, Rate this blog using the tick boxes below.


No comments:

Post a Comment