Monitor input voltage on RB333/433AH
From MikroTik Wiki
Hourly monitor and report via email low voltage warnings and daily voltage levels. Requires /tool e-mail set up correctly to send email.
This requires three scripts.
The first is voltstart. It should be scheduled to run on startup/reboot in the system scheduler.
voltstart
:global voltage [/system health get voltage] :global highvolt $voltage :global lowvolt $voltage :global hivolttime ([/system clock get time] . " " . [/system clock get date]) :global lovolttime $hivolttime
The second is voltmonitor. It should be scheduled to run once an hour on the hour (or within a minute or so)
voltmonitor
#set lowvoltalarm to desired alarm voltage in tenths of a volt. 125 = 12.5v
:global lowvoltalarm 125
: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 voltint [:pick $voltage 0 2]
:local voltrem [:pick $voltage 2 3]
:local voltstr ($voltint . "." . $voltrem)
:local emessage ($thisbox . " voltage is " . $voltstr)
# set your email address in the next line
:if ($voltage <= $lowvoltalarm) do={/tool e-mail send to="youremail@yourdomain.com" subject="$thisbox low voltage" 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
}
The third is voltreport. It does not need to be scheduled. It is executed by voltmonitor at 11PM every day.
voltreport
:global voltage
:global highvolt
:global lowvolt
:global hivolttime
:global lovolttime
:global starttime
:global vh
:local tvolt
:local thisdate [/system clock get date]
:local thishour
:local emessage "Daily voltage report for $thisdate\n\n"
:if ([:len $vh] > 0) do={
:for x from=0 to=([:len $vh]-1) step=1 do={
:set tvolt [:tostr [:pick $vh $x]]
:if ($x = 23) do={:set thishour "00"} else={
:if ($x > 13) do={:set thishour ("0" . [:tostr (23 - $x)])} else={:set thishour [:tostr (23 - $x)]}
}
:set emessage ($emessage . $thishour . ":00 = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] . "v\n")
}
:set emessage ($emessage . "\nSince recording started on " . $starttime . "\n")
:set tvolt [:tostr $highvolt]
:set emessage ($emessage . "Maximum = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] . "v at " . $hivolttime . "\n")
:set tvolt [:tostr $lowvolt]
:set emessage ($emessage . "Minimum = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] . "v at " . $lovolttime . "\n")
# set email address in next line
/tool e-mail send to="youremail@yourdomain.com" subject="Voltage Report" body=$emessage
}
# remark out the next line for testing to avoid resetting the voltage array
:set vh