I have a UPS and I am interested in monitoring its status, when the power goes out? when it is on battery, etc. I have found this script but it gives me an error.
:global flagonbatt;
:global flagbattlow;
:global flagbattlowa;
:global shutdownin;
:global shutdown;
:global restored;
:local online;
:local runtimeleft;
:local battcharge;
:local sysname [/system identity get name];
:local datetime "$[/system clock get date] $[/system clock get time]";
:if ([:typeof $flagonbatt]="nothing") do={:set flagonbatt 0}
:if ([:typeof $flagbattlow]="nothing") do={:set flagbattlow 0}
:if ([:typeof $flagbattlowa]="nothing") do={:set flagbattlowa 0}
:if ([:typeof $shutdownin]="nothing") do={:set shutdownin 100}
:if ([:typeof $shutdown]="nothing") do={:set shutdown 0}
:if ([:typeof $restored]="nothing") do={:set restored 0}
/system ups monitor ups1 once do={
:set online $"on-line";
:set runtimeleft $"runtime-left";
:set battcharge $"battery-charge";
:set shutdownin $"offline-after";
}
:if (($online=false) && ($flagonbatt=0)) do={
:set flagonbatt 1;
/tool e-mail send subject="$sysname | **Power Failure** | $datetime | System will shutdown in $shutdownin | Battery Charge at $battcharge%" to=<your@email.com> body="$sysname | **Power Failure** | $datetime | System will shutdown in $shutdownin | Battery Charge at $battcharge% - Good luck to you, let's hope they fix it quickly!..."
:log info ("PowerFailure: EMail sent")
}
:if (($online=true) && ($flagonbatt=1)) do={
:set flagonbatt 0;
:set shutdown 0;
:set flagbattlowa 0;
:set restored 1;
/tool e-mail send subject="$sysname | *Power Restored* | $datetime | Battery Charge at $battcharge%" to=<your@email.com> body="$sysname | *Power Restored* | $datetime | Battery Charge at $battcharge% - They fixed it! Well done to the electric company!..."
:log info ("PowerRestored: EMail sent")
}
:if (($shutdownin <= 00:10:00) && ($shutdown=0)) do={
:set shutdown 1;
/tool e-mail send subject="$sysname | System Warning | $datetime | System will shutdown in 10 minutes | Battery Charge at $battcharge%" to=<your@email.com> body="$sysname | System Warning | $datetime | System will shutdown in 10 minutes | Battery Charge at $battcharge% - Better start praying!..."
:log info ("10MinLeft: Email sent")
}
:if (($shutdownin <= 00:01:00) && ($flagbattlowa=0)) do={
:set flagbattlowa 1;
/tool e-mail send subject="$sysname | System Warning | $datetime | System will shutdown in 1 minute | Battery Charge at $battcharge%" to=<your@email.com> body="$sysname | System Warning | $datetime | System will shutdown in 1 minute | Battery Charge at $battcharge% - Pray for a miracle brother!..."
:log info ("1MinLeft: Email sent")
}
:if (($battcharge=100) && ($restored=1)) do={
:set restored 0;
/tool e-mail send subject="$sysname | Battery | $datetime | Battery is Fully Charged" to=<your@email.com> body="$sysname | Battery | $datetime | Battery is Fully Charged - yeah, we're ready to go again!..."
:log info ("BatteryFull: Email sent")
}