Community discussions

MUM Europe 2020
 
Trezona
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 59
Joined: Wed Feb 22, 2006 6:34 pm

Voltage Monitoring

Fri Jan 22, 2016 9:20 am

Hello,

I have been running a voltage monitoring script with great success for a while now.

I am now trying to run this same script on the latest firmware (6.33.5) and it is not running at all.

Here is my script:

#set lowvoltalarm to desired alarm voltage in tenths of a volt. 125 = 12.5v
:global lowvoltalarm 200
:global highvoltalarm 280
:global highvolt
:global lowvolt
:global starttime
:global hivolttime
:global lovolttime
:global vh
:local thisbox [/system identity get name]
:global voltage [/system health get voltage]
:local thistime [/system clock get time]
:local thisdate [/system clock get date]
:local thishour [:pick $thistime 0 2]
:local emessage ($thisbox . " voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])
:if ([:len $lowvolt] < 1) do={:set lowvolt 999; :set highvolt 0}
# set your email address in the next line
:if ($voltage <= $lowvoltalarm) do={/tool e-mail send to="test@test.com" subject="$thisbox Voltage Statistics" body=$emessage}
:if ($voltage >= $highvoltalarm) do={/tool e-mail send to="test@test.com" subject="$thisbox Voltage Statistics" body=$emessage}
:if ($voltage > $highvolt) do={:set highvolt $voltage; :set hivolttime ($thistime . " " . $thisdate)}
:if ($voltage < $lowvolt) do={:set lowvolt $voltage; :set lovolttime ($thistime . " " . $thisdate)}
:if ([:len $vh] > 0) do={:set vh ([:toarray $voltage] + $vh)} else={:set vh [:toarray $voltage]}
:if ([:len $starttime] < 1) do={:set starttime ($thistime . " " . $thisdate)}
:if ($thishour = "23") do={:execute voltreport}

I run this every 30 minutes.

Could somone one please tell me why this now does not work on all versions higher than 6.30?

Thanks.
 
plisken
Forum Guru
Forum Guru
Posts: 2435
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Voltage Monitoring

Sun Jan 24, 2016 7:36 pm

I have try this script and indeed it don't work.
Who can help us?
 
mperdue
Member Candidate
Member Candidate
Posts: 288
Joined: Wed Jun 30, 2004 8:18 pm

Re: Voltage Monitoring

Sun Jan 24, 2016 8:31 pm

Along the same idea, I'm wanting a script that would monitor voltage and if it droped below a set value it would disable the poe on a single ethernet port. Anyone have that script?
 
marrold
Member
Member
Posts: 417
Joined: Wed Sep 04, 2013 10:45 am

Re: Voltage Monitoring

Sun Jan 24, 2016 9:05 pm

I have try this script and indeed it don't work.
Who can help us?
Run it line by line and see where it fails, or add some lines to indicate where if fails, e.g -
:put "The script has made it this far [1]"
:put "The script has made it this far [2]"
I'm a SIP / VoIP engineer. Feel free to ask questions...
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 283
Joined: Tue Feb 10, 2015 3:21 pm

Re: Voltage Monitoring

Mon Jan 25, 2016 12:02 pm

There is an error in last line:
:if ($thishour = "23") do={:execute voltreport}

if voltreport is supposed to a variable - then it is missing $ and also it is not defined.

If you change this line, then the script works fine in 6.33.5
 
plisken
Forum Guru
Forum Guru
Posts: 2435
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Voltage Monitoring

Mon Jan 25, 2016 12:11 pm

Where must $ comming in the line?
Can you make the last line please
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 283
Joined: Tue Feb 10, 2015 3:21 pm

Re: Voltage Monitoring

Mon Jan 25, 2016 12:47 pm

Where must $ comming in the line?
Can you make the last line please
:if ($thishour = "23") do={:execute $voltreport}

$voltreport is the second script or function which is not defined here.

Here you will find step by step instructions how this script works:
http://wiki.mikrotik.com/wiki/Monitor_i ... B333/433AH
 
Trezona
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 59
Joined: Wed Feb 22, 2006 6:34 pm

Re: Voltage Monitoring

Tue Jan 26, 2016 8:36 am

Thanks Paul,

Its working great now!

I am actually not using the second part of the script so i just hashed it out!

Thanks once again for you help!

Clive.
 
plisken
Forum Guru
Forum Guru
Posts: 2435
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Voltage Monitoring

Tue Jan 26, 2016 2:38 pm

Working like a charm Paul
Thank you
 
p3rad0x
Long time Member
Long time Member
Posts: 604
Joined: Fri Sep 18, 2015 5:42 pm
Location: South Africa
Contact:

Re: Voltage Monitoring

Tue Feb 02, 2016 12:05 pm

I use this line,
:if ($thishour = "23") do={/system script run voltreport}
There you go then you touched something ;-) : it only takes a change in wind direction to screw with your nat :-)
 
BobcatGuy
Member Candidate
Member Candidate
Posts: 231
Joined: Thu Apr 19, 2007 7:41 am

Re: Voltage Monitoring

Thu Jul 07, 2016 9:55 am

If anyone is handy with scripting and willing to help a buddy out....  I am looking for a way to monitor voltage, to use as a notification if the power went out.  Basically the same script idea, but with a couple twists.

The point it to monitor volts, while AC power is on and power supply provides 13.5 volts exactly, when the AC power goes off, the power supply switched to 12 volt battery, and provides power at about 12.8 volts.  So, that's the easy part to do that.  I can hack this script apart and get that to work, but it would send an email every time the script is run, say I have it set to run every 5 minutes.

I would like to only send the email one time, until power is restored, volts goes back up, then another email is sent stating, power is back on.  Basically I guess it would be a "compare $lastvolts to $currentvolts and if current volts is less than $alarmvolts, and variable of $lastvolts was also less than $alarmvolts to then send email.  That's the jist, basicaly compare the last check and if it was already on battery, to not send email again,  emails every 5 minutes would get annoying.

Would be nice to also set a value for "critical Low" level, say 11.0 Volts, will also send an email.. This way you know that the battery is at critical level, and may not send any more notifications.  Also a notification that its back up to the charge voltage to indicate battery is charging and AC back on.

Any other cool ideas too if anyone has them.
poor mans UPS :-)

Thanks.
 
n21roadie
Forum Guru
Forum Guru
Posts: 1896
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: Voltage Monitoring

Fri Jul 08, 2016 1:06 am

If anyone is handy with scripting and willing to help a buddy out....  I am looking for a way to monitor voltage, to use as a notification if the power went out.  Basically the same script idea, but with a couple twists.

The point it to monitor volts, while AC power is on and power supply provides 13.5 volts exactly, when the AC power goes off, the power supply switched to 12 volt battery, and provides power at about 12.8 volts.  So, that's the easy part to do that.  I can hack this script apart and get that to work, but it would send an email every time the script is run, say I have it set to run every 5 minutes.

I would like to only send the email one time, until power is restored, volts goes back up, then another email is sent stating, power is back on.  Basically I guess it would be a "compare $lastvolts to $currentvolts and if current volts is less than $alarmvolts, and variable of $lastvolts was also less than $alarmvolts to then send email.  That's the jist, basicaly compare the last check and if it was already on battery, to not send email again,  emails every 5 minutes would get annoying.

Would be nice to also set a value for "critical Low" level, say 11.0 Volts, will also send an email.. This way you know that the battery is at critical level, and may not send any more notifications.  Also a notification that its back up to the charge voltage to indicate battery is charging and AC back on.

Any other cool ideas too if anyone has them.
poor mans UPS :-)

Thanks.
Because all of our network has battery back up, AC monitor from a routerboard was not the best solution, however using a simple GSM Alarm / relay unit which serves two purposes was our solution, (1) it automatically sends SMS text alert of AC outage and AC power restoration  (2) We can use the built in relay to disconnect DC power to locked up boards so they can restart ? 
N21roadie,
Network 100% MT for Now?
 
BobcatGuy
Member Candidate
Member Candidate
Posts: 231
Joined: Thu Apr 19, 2007 7:41 am

Re: Voltage Monitoring

Sat Jul 09, 2016 10:43 am

Hmm found a simple solution.  Added global variable :global lastvoltage
And modified the two lines as seen below.

:if ($voltage <= $lowvoltalarm and $lastvoltage > $lowvoltalarm) do={/tool e-mail send to="myemail@domain.com" subject="$thisbox Voltage Statistics" body=$emessage}

:if ($voltage >= $lowvoltalarm and $lastvoltage < $lowvoltalarm) do={/tool e-mail send to="myemail@domain.com" subject="$thisbox Voltage Statistics" body=$emessage}


Then added
:set $lastvoltage $voltage
as the last line so that the two lines above compare the values. Basically if it was in low volt already, and the last time the script ran, it will not send the email, since all conditions are not met. I am running this on a 12 volt system, so I have it set to 12.4 volts, when the AC power fails, it switches to battery.  The 12.4 volts is because this particular unit I was testing on had about 75 feet of cat 5 and the voltage was lower at the MT board.  Adjust it to your desired voltage.

I will tweek this script a bit more for my use and might post it later.  I would like to set it up so that it reports the voltage every hour as well while on battery, so that I can monitor its state and know when it will shut down. 


#set lowvoltalarm to desired alarm voltage in tenths of a volt. 125 = 12.5v
:global lowvoltalarm 124
:global highvoltalarm 280
:global highvolt
:global lowvolt
:global starttime
:global hivolttime
:global lovolttime
:global vh
:global lastvoltage
:local thisbox [/system identity get name]
:global voltage [/system health get voltage]
:local thistime [/system clock get time]
:local thisdate [/system clock get date]
:local thishour [:pick $thistime 0 2]
:local emessage ($thisbox . "Voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])
:if ([:len $lowvolt] < 1) do={:set lowvolt 999; :set highvolt 0}
# set your email address in the next line
:if ($voltage <= $lowvoltalarm and $lastvoltage > $lowvoltalarm) do={/tool e-mail send to="myemail@domain.com" subject="$thisbox Voltage Statistics" body=$emessage}
:if ($voltage >= $lowvoltalarm and $lastvoltage < $lowvoltalarm) do={/tool e-mail send to="myemail@domain.com" subject="$thisbox Voltage Statistics" body=$emessage}
:if ($voltage >= $highvoltalarm) do={/tool e-mail send to="myemail@domain.com" subject="$thisbox Voltage Statistics" body=$emessage}
:if ($voltage > $highvolt) do={:set highvolt $voltage; :set hivolttime ($thistime . " " . $thisdate)}
:if ($voltage < $lowvolt) do={:set lowvolt $voltage; :set lovolttime ($thistime . " " . $thisdate)}
:if ([:len $vh] > 0) do={:set vh ([:toarray $voltage] + $vh)} else={:set vh [:toarray $voltage]}
:if ([:len $starttime] < 1) do={:set starttime ($thistime . " " . $thisdate)}
:if ($thishour = "23") do={:execute $voltreport}
:set $lastvoltage $voltage

 
 
eliemacho
just joined
Posts: 22
Joined: Thu May 02, 2019 12:20 pm

Re: Voltage Monitoring

Sat May 11, 2019 1:17 pm

@bobcatguy

thanks dude it works very well
 
plisken
Forum Guru
Forum Guru
Posts: 2435
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Voltage Monitoring

Mon May 13, 2019 4:35 pm

Thanks Bobcatguy good work and a appresiate that.
 
vaio
just joined
Posts: 5
Joined: Wed Oct 12, 2011 10:52 am

Re: Voltage Monitoring

Sun Oct 20, 2019 9:39 am

Hi everybody...
I want to ask if I could edit the script like this ...
So, I need to monitor the voltage level and send info to the Telegram application ...

Specifically:

The script will check the voltage of XX_Volt

In the event of a power failure, the system is working on a backup battery to detect this by dropping the voltage to XX_Volt...

Then I need it to send me a message on the Telegram (example: "ATTENTION - Power outage-battery powered")

So he will check the voltage every minute and after a drop of 0.5Volt will send me a message about the current voltage, ..

When the power comes on and the system detects that the voltage is XX_Volt, it sends me a message (example: "Power restored, Current voltage is XX_Volt"), and continues to control the power and voltage drop, but does not send more messages only if the power drops to XX_Volt ...)
 
flynno
Member Candidate
Member Candidate
Posts: 247
Joined: Wed Aug 27, 2014 8:11 pm

Re: Voltage Monitoring

Wed Nov 27, 2019 1:30 pm

Edited above script to add telegram

#set lowvoltalarm to desired alarm voltage in tenths of a volt. 125 = 12.5v
:global lowvoltalarm 233
:global highvoltalarm 280
:global highvolt
:global lowvolt
:global starttime
:global hivolttime
:global lovolttime
:global vh
:global lastvoltage
:global telegramBOT
:local thisbox [/system identity get name]
:global voltage [/system health get voltage]
:local thistime [/system clock get time]
:local thisdate [/system clock get date]
:local thishour [:pick $thistime 0 2]
:local emessage ($thisbox . "Voltage is: " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])
:set telegramBOT [/tool fetch url="https://api.telegram.org/bot&text=Time: $thistime Router: $thisbox Voltage: $voltage"]
:if ([:len $lowvolt] < 1) do={:set lowvolt 999; :set highvolt 0}
# set your email address in the next line
:if ($voltage <= $lowvoltalarm and $lastvoltage > $lowvoltalarm) do={/tool e-mail send to="info@email.com" subject="$thisbox Voltage Statistics" body=$emessage}
:if ($voltage >= $lowvoltalarm and $lastvoltage < $lowvoltalarm) do={/tool e-mail send to="info@email.com" subject="$thisbox Voltage Statistics" body=$emessage}
#telegram send message
:if ($voltage >= $lowvoltalarm and $lastvoltage > $lowvoltalarm) do={:execute $telegramBOT}
:if ($voltage >= $highvoltalarm) do={/tool e-mail send to="info@email.com" subject="$thisbox Voltage Statistics" body=$emessage}
:if ($voltage > $highvolt) do={:set highvolt $voltage; :set hivolttime ($thistime . " " . $thisdate)}
:if ($voltage < $lowvolt) do={:set lowvolt $voltage; :set lovolttime ($thistime . " " . $thisdate)}
:if ([:len $vh] > 0) do={:set vh ([:toarray $voltage] + $vh)} else={:set vh [:toarray $voltage]}
:if ([:len $starttime] < 1) do={:set starttime ($thistime . " " . $thisdate)}
:if ($thishour = "23") do={:execute $voltreport}
:set $lastvoltage $voltage
 
User avatar
eworm
Member
Member
Posts: 446
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Voltage Monitoring

Wed Nov 27, 2019 5:58 pm

I have a solution that covers a lot of what has been requested, and more.
To use this you need to install and configure the basic scripts, see RouterOS scripts. Then install check-health and add a scheduler.
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1315
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Voltage Monitoring

Thu Nov 28, 2019 2:40 pm

Or use Splunk for Mikrotik that I have made here:

viewtopic.php?t=137338

You do get nice graphs.
temp.jpg
You do not have the required permissions to view the files attached to this post.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
plisken
Forum Guru
Forum Guru
Posts: 2435
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Voltage Monitoring

Fri Dec 27, 2019 2:31 pm

@Jotne, cool, but i don't nothing about splunk.

Have you a tutorial how to install splunk?

Greatings
 
leolesotho
just joined
Posts: 1
Joined: Wed Nov 07, 2018 1:59 pm

Re: Voltage Monitoring

Mon Jan 13, 2020 2:37 pm

Hello Everyone

I run my equipment on 24v batteries with a battery charger connected and would like to receive notifications when the mains power drops, with the charger on the Mikrotik will read 27v, when the mains fails I would like to get notifications say at ever 1 volt drop this way I know how much time I have to get to the site

Help would be appreciated
John
 
User avatar
macsrwe
Forum Veteran
Forum Veteran
Posts: 732
Joined: Mon Apr 02, 2007 5:43 am
Location: Arizona, USA
Contact:

Re: Voltage Monitoring

Tue Jan 14, 2020 8:50 am

What's your equipment?

If you're running a unit like a CCR that has two power connectors, you can put one in the wall outlet and write a script to tell if the wall outlet goes off:
# detects and reports wall power failure (still running on UPS)

:global PrevPowerState;

{
  :local statusMessage "";
  :local curPowerState [/system health get psu1-state];

  :if ($PrevPowerState = nil) do={:set PrevPowerState true;};

  :if ($curPowerState = "ok") do=\
      {
       :if ($PrevPowerState = false) do=\
          {
           :set statusMessage "Street power has been restored."; :set PrevPowerState true;
          }
      } else=\
      {
       :if ($PrevPowerState = true) do=\
          {
           :set statusMessage "Street power failed -- running on UPS."; :set PrevPowerState false;
          }
      }

   :if ($statusMessage != "") do=\
      {
       :log error $statusMessage;
       /tool e-mail send to="you@wherever" body=$statusMessage subject="Powerfail status";
      }

}
If you are running a smaller routerboard, you can often do much the same thing by providing 18V POE in and 24V to the DC power input jack, then make a similar script to examine the voltage regularly.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1315
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Voltage Monitoring

Sat Jan 18, 2020 1:34 pm

Have you a tutorial how to install splunk?
Look at my tutorial here:
viewtopic.php?t=137338
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 

Who is online

Users browsing this forum: No registered users and 24 guests