Community discussions

 
dsl400
just joined
Topic Author
Posts: 6
Joined: Tue Apr 30, 2019 11:39 am

Power out notification

Tue Apr 30, 2019 11:57 am

Hello mikrotik forum,
this is my first post so sorry if it sounds stupid
Is there any way to send a notification to the server when sensing a voltage drop or right before power goes out completely?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1310
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Power out notification

Wed May 01, 2019 10:40 am

Should be doable.

You get the voltage using /system health print
For a test try this:
:put ([/system health get voltage]/10)
You can then store it to a global variable:
:global oldvoltage ([/system health get voltage]/10)
Use an IF test and see if its going down compare to previous reading.

My voltage is 100% stable on 25V

You can find how to setup MT to send email using google. (Do a search for it)

This script should make your start:
:global oldvoltage
:local currentvoltage ([/system health get voltage]/10)
:if (($oldvoltage-$currentvoltage)>2) do={
# replace from here
:put "run script"
# to here with email script
}
:global oldvoltage $currentvoltage

But f.eks if you run a script every minute, I am not sure if its fast enough to catch that its going down.
I do use UPS that I can monitor using SNMP.

Also I do monitor voltage from MT using Splunk, see link in my signature.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
dsl400
just joined
Topic Author
Posts: 6
Joined: Tue Apr 30, 2019 11:39 am

Re: Power out notification

Wed May 01, 2019 7:31 pm

thanks for your patience but this is not quite what I had in mind. Of course running a script every minute will not help
the power outage usually takes a few seconds and composing email + connecting to the email server will take far too much time.
what I had in mind was a solution to send a short packet using an event based trigger
a ping mite help if I can filter it on the other end
 
rkau045
newbie
Posts: 43
Joined: Mon Jun 25, 2012 9:14 pm

Re: Power out notification

Thu May 02, 2019 1:43 am

I believe what you are asking for is a "dying gasp"
Edited to add: this is usually implemented in hardware.
Sent from my Pixel 3 XL using Tapatalk


 
Paternot
Long time Member
Long time Member
Posts: 607
Joined: Thu Jun 02, 2016 4:01 am
Location: Niterói / Brazil

Re: Power out notification

Thu May 02, 2019 2:54 am

Is it really that important to monitor the voltage, by the second? Or what You really want is to know when the router is unreachable?

If it's the first, I don't have a solution for you.

If it's the second, You can use Netwatch (https://wiki.mikrotik.com/wiki/Manual:Tools/Netwatch) to monitor a given address, and run a script when it goes offline/online.

No, it isn't a voltage monitoring script - but will warn You when something is unreachable. Is it enough for your needs?
 
dsl400
just joined
Topic Author
Posts: 6
Joined: Tue Apr 30, 2019 11:39 am

Re: Power out notification

Fri May 03, 2019 8:59 pm

It's not about monitoring voltage but more of the reason why a host is down
In my opinion it seams very helpful to have an idea of why you cannot reach a certain device

right now I can think of two scenarios:
1. host unreachable with no indication = uplink dead and you start investigating at the provider
2. host unreachable with last message being powering down = electricity fault in that specific location and you go straight to that place see what is unplugged
 
Paternot
Long time Member
Long time Member
Posts: 607
Joined: Thu Jun 02, 2016 4:01 am
Location: Niterói / Brazil

Re: Power out notification

Fri May 03, 2019 9:26 pm

It's not about monitoring voltage but more of the reason why a host is down
In my opinion it seams very helpful to have an idea of why you cannot reach a certain device

right now I can think of two scenarios:
1. host unreachable with no indication = uplink dead and you start investigating at the provider
2. host unreachable with last message being powering down = electricity fault in that specific location and you go straight to that place see what is unplugged
Well, number 2 rarely is so clear cut. What if your router was hit after the (say) media converter, 200m away? It will (would) try to send the "expiry ping", and fail. Either you have an UPS (an then we can just monitor the UPS and send the message anyway), or you don't - and probably we won't have enough network left to send this last message.
 
dsl400
just joined
Topic Author
Posts: 6
Joined: Tue Apr 30, 2019 11:39 am

Re: Power out notification

Sat May 04, 2019 8:13 am

I'm not here to debate if in a specific case this idea is good or bad. I only want to find out if it is doable with minimal implementation costs
of course having a ups in place is a the best solution, but having to update the network with ups for all the sites is a big investment.
This idea got to me while I was watching a documentary about computers in the 60's, at that time scientists had instruments in place to detect in software that the computer is powering down and had sufficient time to save the information and do a proper software shutdown and all this was done with vacuum tubes.
Sending a ping when detecting that the power supply of your device is fast dropping in an attempt to leave a clue to the network administrator mite be the difference between walking 10 or 100 miles and making a call to ask someone to confirm that there is a power outage and all you have to do is wait
 
pe1chl
Forum Guru
Forum Guru
Posts: 5927
Joined: Mon Jun 08, 2015 12:09 pm

Re: Power out notification

Sat May 04, 2019 11:37 am

The thing is that in the 60's computers had memory that by itself was not dependent on the power.
So when the computer was powered off, and back on, everything would still be in memory.
Thus such functionality was "easy" to add, it only required that the state of the CPU itself (registers) was cleanly saved into memory in such a way that it could be restored.
This is similar to what is called "hibernation" on a laptop.

Today, memory is depending on power (so you need backup power), and you need to save it on disk (like hibernation does).
And computers are no longer standalone things, they operate in a network where it brings little to keep the computer alive when all around it the other parts fail.

So while a "dying gasp" packet from the router (that says "my power is failing, I am leaving") would be possible, where are you going to send it when the power on the site is failing?
"to some remote location" is probably not going to work, too many other components in the way that also lost power.
So you would need to send it to a local computer which has battery backup.
When that is possible, it is maybe easier to make battery backup for your router as well (MikroTik has the mUPS device for that!)

When all you want to do is do some forensic research after a failure ("was this a crash? or did the power fail?") this is usually already possible when you login after a
failure and examine the logs and uptimes of several devices at your site.
E.g. when MikroTik logs "system,error,critical - router was rebooted without proper shutdown" it usually points to a power failure.
When a single device shows this it could maybe be attributed to a nasty crash (although other messages like "probably kernel failure" can be logged in that case), however when
several devices at your site show this or similar logs, it likely was a power failure.
 
dsl400
just joined
Topic Author
Posts: 6
Joined: Tue Apr 30, 2019 11:39 am

Re: Power out notification

Sun May 05, 2019 5:39 pm

This discussion is going in the wrong direction. It should be more about how and less about why but if everybody searches for a reason lets do that first
reason 1: Having a bit of information is better than having no information.
reason 2: Devices are located in remote locations and driving 10 miles just to find an equipment that works is a waste of resources
reason 3: installing UPS in 500 locations takes months and costs a lot, a solution like this can be implemented in days
a "dying gasp" packet from the router
the total time from the power disconnect until the CPU or MPU shuts down is usually more than a second
the router CPU runs at 400MHz
there is enough time to send more than a "dying gasp" packet
where are you going to send it when the power on the site is failing?
Usually routers don`t just ping servers for no reason so if a server connected to this network receives a PING from a router that could mean a power outage on that specific router

this being said, can we focus on the how part ?
 
nostromog
Member Candidate
Member Candidate
Posts: 161
Joined: Wed Jul 18, 2018 3:39 pm

Re: Power out notification

Sun May 05, 2019 6:50 pm

Detecting incoming power failure looks hard to impossible, but one possible way to very quickly/statelessly delivering a message is sending a ping of a specific size to a given server. Use the size of the ping as a "return code". You could simply execute something like:
/ping myserver size=666 count=2 # send 2 to minimize probability of lost message
 
pe1chl
Forum Guru
Forum Guru
Posts: 5927
Joined: Mon Jun 08, 2015 12:09 pm

Re: Power out notification

Sun May 05, 2019 10:53 pm

this being said, can we focus on the how part ?
Ok, here it is: it can't be done.
RouterOS does not support it, and probably the hardware (to send the processor an interrupt when the power is failing but not yet completely gone) is not there.

As I already wrote, MikroTik has a product that can do what you want. It relies on a (user-supplied) battery to buy some more time to then be able to use the available ADC to poll the voltage and perform actions when the power drops.

Who is online

Users browsing this forum: No registered users and 8 guests