Community discussions

MikroTik App
 
User avatar
samrock
just joined
Topic Author
Posts: 20
Joined: Thu Aug 06, 2015 5:17 am

UPS Email notification with CyberPower UPS

Sat Sep 08, 2018 10:24 pm

So I am running a x86 deployment for my BGP edge I would like to monitor the UPS it is connected to. The UPS is a CyberPower LX1500GU and I have it connected with a USB cable..


I have activated the email client on my mikrotik with
/tool e-mail
set address=mail.mywisp.com
set port=587
set from=mikrotik@mywisp.com
set user=mikrotik@mywisp.com
set password=passwordfoo
set start-tls=tls-only





If I issue the following command in the terminal the unit does send the test email.
/tool e-mail send to=noc@mywisp.com subject="email test" body="email test" start-tls=yes


The script I am using to send the UPS email notification I found here on the forum is
#Set the following in scheduler after saving this script as ups-powermonitor
#-----------------------------------------------------------------------
#/system scheduler
#add comment="" disabled=no interval=1m name="ups-powermonitor" on-event=ups-powermonitor start-date=jan/01/1970 start-time=00:00:00
#-----------------------------------------------------------------------
#
#
#
#
# UPS-Script powerfail
# (c) steinmann und weidinger OEG
# www.stone-rich.at
#
# Modified by networker for ROS v6
# All credits to the original author above
#
# WARNING, not lab tested!! Please report any bugs.
#
# Watches ups status and sends emails on power failure and low battery.
# This script will FAIL if:
# - Policies read, write, test, and policy are not set
# - The system name contains non-standard characters (space, /, ...)
#
# user-configurable parameters below:

:local mailserver [:mail.mywisp.com];
:local mailfrom "mikrotik@mywisp.com";
:local mailto "noc@mywisp.com";
:local upsName "ups1";

#
# do NOT make changes below!
#

:global flagonbatt;
:global flagbattlow;

:local battalarm 15;
:local battok 40;

:local curonline;
:local curcharge;

:local sysname [/system identity get name];
:local datetime "$[/system clock get date] $[/system clock get time]";

# First run? If so, we need to initialize the global flags
:if ([:typeof $flagonbatt]="nothing") do={:set flagonbatt 0}
:if ([:typeof $flagbattlow]="nothing") do={:set flagbattlow 0}

:set curonline true;
:set curcharge 100;
/system ups monitor [/system ups find name=$upsName] once do={
  :set curonline $"on-line"; :set curcharge $"battery-charge";
}

:if (($curonline=false) && ($flagonbatt=0)) do={
  :set flagonbatt 1;
 /tool e-mail send from=$mailfrom  to=$mailto server=$mailserver subject="$sysname: Power failure!" \
    body="$sysname  is on battery since $datetime";
  :log info "Power-Fail: EMail sent to $mailto";
}

:if (($curonline) && ($flagonbatt=1)) do={
 :set flagonbatt 0;
 /tool e-mail send from=$mailfrom  to=$mailto server=$mailserver subject="$sysname: Power is back" \
    body="$sysname is back on power since $datetime";
  :log info "Power-Restore: Email sent to $mailto";
}

:if (($curcharge <= $battalarm) && ($flagbattlow=0)) do={
  :set flagbattlow 1;
  /tool e-mail send from=$mailfrom  to=$mailto server=$mailserver subject="$sysname: Low battery!" \
    body="$sysname battery is at $curcharge %! $datetime";
  :log info "Batt-Low: Email sent to $mailto";
}

:if (($curcharge >= $battok) && ($flagbattlow=1)) do={
  :set flagbattlow 0;
  /tool e-mail send from=$mailfrom  to=$mailto server=$mailserver subject="$sysname: Battery recharged" \
    body="$sysname Battery recharged to $curcharge% $datetime";
  :log info "Batt-Recharged: Email sent to $mailto";
}




When that did not work I read over the script and modified it to include the tls command that I used in to send my test email..
#Set the following in scheduler after saving this script as ups-powermonitor
#-----------------------------------------------------------------------
#/system scheduler
#add comment="" disabled=no interval=1m name="ups-powermonitor" on-event=ups-powermonitor start-date=jan/01/1970 start-time=00:00:00
#-----------------------------------------------------------------------
#
#
#
#
# UPS-Script powerfail
# (c) steinmann und weidinger OEG
# www.stone-rich.at
#
# Modified by networker for ROS v6
# All credits to the original author above
#
# WARNING, not lab tested!! Please report any bugs.
#
# Watches ups status and sends emails on power failure and low battery.
# This script will FAIL if:
# - Policies read, write, test, and policy are not set
# - The system name contains non-standard characters (space, /, ...)
#
# user-configurable parameters below:

:local mailserver [:mail.mywisp.com];
:local mailfrom "mikrotik@mywisp.com";
:local mailto "noc@mywisp.com";
:local upsName "ups1";

#
# do NOT make changes below!
#

:global flagonbatt;
:global flagbattlow;

:local battalarm 15;
:local battok 40;

:local curonline;
:local curcharge;

:local sysname [/system identity get name];
:local datetime "$[/system clock get date] $[/system clock get time]";

# First run? If so, we need to initialize the global flags
:if ([:typeof $flagonbatt]="nothing") do={:set flagonbatt 0}
:if ([:typeof $flagbattlow]="nothing") do={:set flagbattlow 0}

:set curonline true;
:set curcharge 100;
/system ups monitor [/system ups find name=$upsName] once do={
  :set curonline $"on-line"; :set curcharge $"battery-charge";
}

:if (($curonline=false) && ($flagonbatt=0)) do={
  :set flagonbatt 1;
 /tool e-mail send from=$mailfrom  to=$mailto server=$mailserver subject="$sysname: Power failure!" \
    body="$sysname  is on battery since $datetime" start-tls=yes;
  :log info "Power-Fail: EMail sent to $mailto";
}

:if (($curonline) && ($flagonbatt=1)) do={
 :set flagonbatt 0;
 /tool e-mail send from=$mailfrom  to=$mailto server=$mailserver subject="$sysname: Power is back" \
    body="$sysname is back on power since $datetime" start-tls=yes;
  :log info "Power-Restore: Email sent to $mailto";
}

:if (($curcharge <= $battalarm) && ($flagbattlow=0)) do={
  :set flagbattlow 1;
  /tool e-mail send from=$mailfrom  to=$mailto server=$mailserver subject="$sysname: Low battery!" \
    body="$sysname battery is at $curcharge %! $datetime" start-tls=yes;
  :log info "Batt-Low: Email sent to $mailto";
}

:if (($curcharge >= $battok) && ($flagbattlow=1)) do={
  :set flagbattlow 0;
  /tool e-mail send from=$mailfrom  to=$mailto server=$mailserver subject="$sysname: Battery recharged" \
    body="$sysname Battery recharged to $curcharge% $datetime" start-tls=yes;
  :log info "Batt-Recharged: Email sent to $mailto";
}



But it still does not work..

Does any one know how to get this working?
 
User avatar
samrock
just joined
Topic Author
Posts: 20
Joined: Thu Aug 06, 2015 5:17 am

Re: UPS Email notification with CyberPower UPS

Sat Sep 08, 2018 10:27 pm

/sys ups mon ups1 returns
                                   
         on-line: yes
    runtime-left: 1h
  battery-charge: 96%
    line-voltage: 120V
  output-voltage: 120V
            load: 17%



So I do know ros can see the UPS
 
User avatar
samrock
just joined
Topic Author
Posts: 20
Joined: Thu Aug 06, 2015 5:17 am

Re: UPS Email notification with CyberPower UPS

Mon Sep 10, 2018 7:10 am

Come on, Out of all the people on this forum no one has their tick sending UPS status updates over email?
 
boredwitless
just joined
Posts: 6
Joined: Tue Jul 10, 2018 12:19 pm

Re: UPS Email notification with CyberPower UPS

Sun Nov 11, 2018 12:45 am

Just looking into setting this up myself.

Simple 'UPS Offline' / 'UPS Online' notification is simples... but I think we all want more.

Check this thread:

viewtopic.php?t=73899

Who is online

Users browsing this forum: Google [Bot] and 42 guests