Difference between revisions of "Monitor input voltage on RB333/433AH"

From MikroTik Wiki
Jump to: navigation, search
m (HowTo: add press Control-o...)
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
Monitor and report via email low voltage warnings and daily voltage levels
+
Hourly monitor and report via email low voltage warnings and daily voltage levels.
  
This requires three scripts.
+
This applies to the '''RB333''' and '''RB433AH with V3.11''' or greater '''ONLY!'''
  
The first is voltstart. It should be scheduled to run on startup/reboot in the system scheduler.
+
== Low Voltage Report ==
  
:global voltage [/system health get voltage]
+
This report is sent hourly to the email address in the voltmonitor script when the input voltage is at or below the alarm voltage.
:global highvolt $voltage
+
 
:global lowvolt $voltage
+
<pre>
:global hivolttime ([/system clock get time] . " " . [/system clock get date])
+
ThisBox voltage is 12.5
:global lovolttime $hivolttime
+
</pre>
 +
 
 +
== Daily Voltage Report ==
 +
 
 +
This report is sent daily at 11PM to the email address in the voltreport script.
 +
 
 +
<pre>
 +
Daily voltage report for ThisBox on aug/29/2008
 +
 
 +
23:00 = 12.8
 +
22:00 = 12.8
 +
21:00 = 12.9
 +
20:00 = 13.0
 +
19:00 = 13.0
 +
18:00 = 13.3
 +
17:00 = 14.1
 +
16:00 = 14.0
 +
15:00 = 14.0
 +
14:00 = 13.9
 +
13:00 = 13.9
 +
12:00 = 13.9
 +
11:00 = 13.9
 +
10:00 = 13.5
 +
09:00 = 13.2
 +
08:00 = 12.6
 +
07:00 = 12.5
 +
06:00 = 12.5
 +
05:00 = 12.5
 +
04:00 = 12.6
 +
03:00 = 12.6
 +
02:00 = 12.6
 +
01:00 = 12.7
 +
00:00 = 12.7
 +
 
 +
Since voltmonitor started on 13:00:00 aug/28/2008
 +
Maximum = 14.2v at 13:00:00 aug/28/2008
 +
Minimum = 12.5v at 05:00:00 aug/29/2008
 +
</pre>
 +
 
 +
== Requirements ==
 +
 
 +
/tool e-mail must be set correctly to send email,
 +
 
 +
/system ntp client must be set correctly for the correct time after a reboot,
 +
 
 +
/system identity should be set to identify the router in the Low Voltage Report,
 +
 
 +
and the following two scripts:
  
 +
== voltmonitor ==
  
The second is voltmonitor. It should be scheduled to run once an hour on the hour (or within a minute or so)
+
The first is voltmonitor. It should be scheduled to run once every hour on the hour (or within a minute after) in /system schedule.
  
# set lowvoltalarm to desired alarm voltage in tenths of a volt. 125 = 12.5v
+
<pre>
 +
#set lowvoltalarm to desired alarm voltage in tenths of a volt. 125 = 12.5v
 
:global lowvoltalarm 125
 
:global lowvoltalarm 125
 
:global highvolt
 
:global highvolt
Line 27: Line 76:
 
:local thisdate [/system clock get date]
 
:local thisdate [/system clock get date]
 
:local thishour [:pick $thistime 0 2]
 
:local thishour [:pick $thistime 0 2]
:local voltint [:pick $voltage 0 2]
+
:local emessage ($thisbox . " voltage is " . [:pick $voltage 0 2] . "." . [:pick $voltage 2 3])
:local voltrem [:pick $voltage 2 3]
+
:if ([:len $lowvolt] < 1) do={:set lowvolt 999; :set highvolt 0}
:local voltstr ($voltint . "." . $voltrem)
 
:local emessage ($thisbox . " voltage is " . $voltstr)
 
 
# set your email address in the next line
 
# 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 <= $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 > $highvolt) do={:set highvolt $voltage; :set hivolttime ($thistime . " " . $thisdate)}
 
:if ($voltage < $lowvolt) do={:set lowvolt $voltage; :set lovolttime ($thistime . " " . $thisdate)}
 
:if ($voltage < $lowvolt) do={:set lowvolt $voltage; :set lovolttime ($thistime . " " . $thisdate)}
:if ([:len $vh] > 0) do={
+
:if ([:len $vh] > 0) do={:set vh ([:toarray $voltage] + $vh)} else={:set vh [:toarray $voltage]}
        :set vh ([:toarray $voltage] + $vh)
+
:if ([:len $starttime] < 1) do={:set starttime ($thistime . " " . $thisdate)}
    } else={
+
:if ($thishour = "23") do={:execute voltreport}
        :set vh [:toarray $voltage]
+
</pre>
    }
+
 
:if ([:len $starttime] < 1) do={
+
== voltreport ==
    :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 voltreport at 11PM every day.
+
The second is voltreport. It does not need to be scheduled. It is executed by voltmonitor at 11PM every day.
  
:global voltage
+
<pre>
 
:global highvolt
 
:global highvolt
 
:global lowvolt
 
:global lowvolt
Line 57: Line 99:
 
:global vh
 
:global vh
 
:local tvolt
 
:local tvolt
 +
:local thisbox [/system identity get name]
 
:local thisdate [/system clock get date]
 
:local thisdate [/system clock get date]
 
:local thishour
 
:local thishour
:local emessage "Daily voltage report for $thisdate\n\n"
+
:local emessage "Daily voltage report for $thisbox on $thisdate\n\n"
 
:if ([:len $vh] > 0) do={
 
:if ([:len $vh] > 0) do={
 
     :for x from=0 to=([:len $vh]-1) step=1 do={
 
     :for x from=0 to=([:len $vh]-1) step=1 do={
 
         :set tvolt [:tostr [:pick $vh $x]]
 
         :set tvolt [:tostr [:pick $vh $x]]
         :if ($x = 23) do={:set thishour "00"} else={
+
         :set thishour [:tostr (23 - $x)]
            :if ($x > 13) do={:set thishour ("0" . [:tostr (23 - $x)])} else={:set thishour [:tostr (23 - $x)]}
+
        :while ([:len $thishour] < 2) do={:set thishour ("0" . $thishour)}
        }
+
         :set emessage ($emessage . $thishour . ":00 = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] .  "\n")
         :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 emessage ($emessage . "\nSince voltmonitor started on " . $starttime . "\n")
 
     :set tvolt [:tostr $highvolt]
 
     :set tvolt [:tostr $highvolt]
 
     :set emessage ($emessage . "Maximum = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] . "v at " . $hivolttime . "\n")
 
     :set emessage ($emessage . "Maximum = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] . "v at " . $hivolttime . "\n")
Line 74: Line 116:
 
     :set emessage ($emessage . "Minimum = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] . "v at " . $lovolttime . "\n")
 
     :set emessage ($emessage . "Minimum = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] . "v at " . $lovolttime . "\n")
 
# set email address in next line
 
# set email address in next line
     /tool e-mail send to="youremail@yourdomain.com" subject="Voltage Report" body=$emessage
+
     /tool e-mail send to="youremail@yourdomain.com" subject="$thisbox Voltage Report" body=$emessage
 
}
 
}
 
# remark out the next line for testing to avoid resetting the voltage array
 
# remark out the next line for testing to avoid resetting the voltage array
 
:set vh
 
:set vh
 +
</pre>
 +
 +
Note: If you are subject to Daylight Saving Time, there will be one day in the spring that will have only 23 hours, and in the autumn, you will actually get to see a "-1:00". Minus one o'clock?
 +
 +
 +
== HowTo ==
 +
 +
Command Line:
 +
 +
Login to your router with ssh with your terminal console. I use Konsole in this example.
 +
 +
Highlight the script text for voltmonitor above and copy to clipboard. (Select and Copy).
 +
 +
Then in your router:
 +
 +
<pre>
 +
/system script add name=voltmonitor
 +
/system script edit voltmonitor source
 +
</pre>
 +
 +
In the Konsole toolbar, select "Edit/Paste". The script should be inserted correctly without any typos. The Control-y paste in the terminal window does '''not''' paste from the clipboard.
 +
 +
Edit the email address to your email address.
 +
 +
Press Control-o to save and exit the editor.
 +
 +
Do the same for voltreport.
 +
 +
Then add the voltmonitor script to the system schedule:
 +
 +
<pre>
 +
/system schedule add name=voltmonitor on-event=voltmonitor start-time=00:00:00 interval=1h
 +
</pre>

Latest revision as of 15:01, 2 September 2008

Hourly monitor and report via email low voltage warnings and daily voltage levels.

This applies to the RB333 and RB433AH with V3.11 or greater ONLY!

Low Voltage Report

This report is sent hourly to the email address in the voltmonitor script when the input voltage is at or below the alarm voltage.

ThisBox voltage is 12.5

Daily Voltage Report

This report is sent daily at 11PM to the email address in the voltreport script.

Daily voltage report for ThisBox on aug/29/2008

23:00 = 12.8
22:00 = 12.8
21:00 = 12.9
20:00 = 13.0
19:00 = 13.0
18:00 = 13.3
17:00 = 14.1
16:00 = 14.0
15:00 = 14.0
14:00 = 13.9
13:00 = 13.9
12:00 = 13.9
11:00 = 13.9
10:00 = 13.5
09:00 = 13.2
08:00 = 12.6
07:00 = 12.5
06:00 = 12.5
05:00 = 12.5
04:00 = 12.6
03:00 = 12.6
02:00 = 12.6
01:00 = 12.7
00:00 = 12.7

Since voltmonitor started on 13:00:00 aug/28/2008
Maximum = 14.2v at 13:00:00 aug/28/2008
Minimum = 12.5v at 05:00:00 aug/29/2008

Requirements

/tool e-mail must be set correctly to send email,

/system ntp client must be set correctly for the correct time after a reboot,

/system identity should be set to identify the router in the Low Voltage Report,

and the following two scripts:

voltmonitor

The first is voltmonitor. It should be scheduled to run once every hour on the hour (or within a minute after) in /system schedule.

#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 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="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}

voltreport

The second is voltreport. It does not need to be scheduled. It is executed by voltmonitor at 11PM every day.

:global highvolt
:global lowvolt
:global hivolttime
:global lovolttime
:global starttime
:global vh
:local tvolt
:local thisbox [/system identity get name]
:local thisdate [/system clock get date]
:local thishour
:local emessage "Daily voltage report for $thisbox on $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]]
        :set thishour [:tostr (23 - $x)]
        :while ([:len $thishour] < 2) do={:set thishour ("0" . $thishour)}
        :set emessage ($emessage . $thishour . ":00 = " . [:pick $tvolt 0 2] . "." . [:pick $tvolt 2 3] .  "\n")
    }
    :set emessage ($emessage . "\nSince voltmonitor 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="$thisbox Voltage Report" body=$emessage
}
# remark out the next line for testing to avoid resetting the voltage array
:set vh

Note: If you are subject to Daylight Saving Time, there will be one day in the spring that will have only 23 hours, and in the autumn, you will actually get to see a "-1:00". Minus one o'clock?


HowTo

Command Line:

Login to your router with ssh with your terminal console. I use Konsole in this example.

Highlight the script text for voltmonitor above and copy to clipboard. (Select and Copy).

Then in your router:

/system script add name=voltmonitor
/system script edit voltmonitor source

In the Konsole toolbar, select "Edit/Paste". The script should be inserted correctly without any typos. The Control-y paste in the terminal window does not paste from the clipboard.

Edit the email address to your email address.

Press Control-o to save and exit the editor.

Do the same for voltreport.

Then add the voltmonitor script to the system schedule:

/system schedule add name=voltmonitor on-event=voltmonitor start-time=00:00:00 interval=1h