Community discussions

MikroTik App
 
vk7zms
Member Candidate
Member Candidate
Topic Author
Posts: 227
Joined: Thu Jun 29, 2006 3:01 am
Location: Hobart, Tasmania
Contact:

UPS power down/up alerting 2.9.x

Thu Aug 24, 2006 5:47 pm

Hi, I have written a script that when run, emails the result of the ups.

What I would like to do is make it so that it ONLY emails when the UPS is on battery, and then loops back and continually monitors the UPS until the power is restored, at which time it completes the script and sends the power restored message. Any help would be very much appreciated

Kind Regards Murray

:global datetime ([/system clock get time] . " - " . [:pick[/system clock get date] 4 6] . "-" . [:pick [/system clock get date]0 3] . "-" . [:pick[/system clock get date] 7 11])
/system ups monitor [/system ups find name "ups2"] once do {
:if ($on-battery="yes") do {
/tool e-mail send to="email.address@isp.com.au" subject=("Power Failure At " . $datetime) body=("Power Failure at at " . $datetime)
}
}
/system ups monitor [/system ups find name "ups2"] once do {
:if (!$on-battery="yes") do {
/tool e-mail send to="email.address@isp.com.au" subject=(" Power Restored At " . $datetime) body=("Power Restored at " . $datetime)
}
}
 
vk7zms
Member Candidate
Member Candidate
Topic Author
Posts: 227
Joined: Thu Jun 29, 2006 3:01 am
Location: Hobart, Tasmania
Contact:

Sat Aug 26, 2006 5:43 pm

Thanks to all who took the time to view this post. I have managed to fix the proble using two scripts. There are probably far more elegant ways of doing it. Script A runs once a minute. Script B runs every half hour - this simply resets the trigger and sends another email if power is still off.

I would be very interested to hear from anyone who has done this an easier way.

Kind Regards Murray

Script A (scheduled to run every minute)

:global datetime ([/system clock get time] . " - " . [:pick[/system clock get date] 4 6] . "-" . [:pick [/system clock get date]0 3] . "-" . [:pick[/system clock get date] 7 11])
/system ups monitor [/system ups find name "ups1"] once do {
:if ($on-battery="yes") do {:set trigger ($trigger + 1)
}
}
:if ($trigger=1) do {/tool e-mail send to=my.email@isp.com.au subject=("Power Failure At " . $datetime) body=("Power Failure at office at " . $datetime)
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {
/tool e-mail send to=my.email@isp.com.au subject=(" Power Restored At " . $datetime) body=("Power Restored at office" . $datetime)
}
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {:set trigger 0
}
}

Script B (scheduled to run every half an hour)

:global trigger 0
 
xandor
newbie
Posts: 39
Joined: Wed Mar 30, 2005 6:29 pm

Tue Dec 19, 2006 9:16 am

HI,
Sorry but these scripts must be insterted into scheduler or only as script?
And... Script B (:global trigger 0) must be included into:
/system ups monitor [/system ups find name "ups1"] once do {
:if ($on-battery="yes") do {:set trigger ($trigger + 1)
}
}
:if ($trigger=1) do {/tool e-mail send to=my.email@isp.com.au subject=("Power Failure At " . $datetime) body=("Power Failure at office at " . $datetime)
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {
/tool e-mail send to=my.email@isp.com.au subject=(" Power Restored At " . $datetime) body=("Power Restored at office" . $datetime)
}
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {:set trigger 0
}
}

Can you ask me how I can configure these?

Regards
Xandor
 
vk7zms
Member Candidate
Member Candidate
Topic Author
Posts: 227
Joined: Thu Jun 29, 2006 3:01 am
Location: Hobart, Tasmania
Contact:

Tue Dec 19, 2006 12:49 pm

Hi Xandor, enter the two scripts and call them different names. After entering the two scrips, set scheduler to run the main script say every minute and the secondary script to run say every half an hour.

The result is that every minute, MT OS checks to see if the UPS is running on battery, as soon as it does, it sends an email (I used it through an SMS gateway to message my phone). It the starts checking for mains to be restored and sends another message when this happens.

The function of the second script is to cause the first script to reset and send another email if the UPS is still running on batteries after that time. Its a bit simplistic because the second script running every half hour may reset the first script almost immediately if the UPS goes onto battery just before the half hour is up. Its not a perfect script, but it works well for me.
 
xandor
newbie
Posts: 39
Joined: Wed Mar 30, 2005 6:29 pm

Tue Dec 19, 2006 1:04 pm

HI,
But second script is composed only as :global trigger 0 or as under?

Regards
Xandor

:global trigger 0

/system ups monitor [/system ups find name "ups1"] once do {
:if ($on-battery="yes") do {:set trigger ($trigger + 1)
}
}
:if ($trigger=1) do {/tool e-mail send to=my.email@isp.com.au subject=("Power Failure At " . $datetime) body=("Power Failure at office at " . $datetime)
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {
/tool e-mail send to=my.email@isp.com.au subject=(" Power Restored At " . $datetime) body=("Power Restored at office" . $datetime)
}
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {:set trigger 0
}
}
 
xandor
newbie
Posts: 39
Joined: Wed Mar 30, 2005 6:29 pm

Tue Dec 19, 2006 1:08 pm

HI,
Can you indicated me what SMS gateway do you use?

Regards
Xandor
 
vk7zms
Member Candidate
Member Candidate
Topic Author
Posts: 227
Joined: Thu Jun 29, 2006 3:01 am
Location: Hobart, Tasmania
Contact:

Tue Dec 19, 2006 1:40 pm

 
xandor
newbie
Posts: 39
Joined: Wed Mar 30, 2005 6:29 pm

Tue Dec 19, 2006 2:12 pm

HI,
Can you me reply to my previously question?

Regards
Xandor
 
vk7zms
Member Candidate
Member Candidate
Topic Author
Posts: 227
Joined: Thu Jun 29, 2006 3:01 am
Location: Hobart, Tasmania
Contact:

Tue Dec 19, 2006 2:45 pm

Hi Exandor - not sure which question you are refering to? If it is the Question about which sms gateway I use, I have already posted the URL to there web sight (here it is again). I hope this helps. If you were refering to an early question, let me know which one.

http://www.importantsms.com.au/
 
xandor
newbie
Posts: 39
Joined: Wed Mar 30, 2005 6:29 pm

Tue Dec 19, 2006 2:56 pm

I refer to this.IS CORRECT?

Regards
XANDOR

:global trigger 0

/system ups monitor [/system ups find name "ups1"] once do {
:if ($on-battery="yes") do {:set trigger ($trigger + 1)
}
}
:if ($trigger=1) do {/tool e-mail send to=my.email@isp.com.au subject=("Power Failure At " . $datetime) body=("Power Failure at office at " . $datetime)
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {
/tool e-mail send to=my.email@isp.com.au subject=(" Power Restored At " . $datetime) body=("Power Restored at office" . $datetime)
}
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {:set trigger 0
}
}
 
User avatar
raivis-v
Frequent Visitor
Frequent Visitor
Posts: 55
Joined: Thu Jul 14, 2005 10:21 am
Location: Latvia, Riga

Tue Dec 19, 2006 3:04 pm

xandor:
AS far as I understand from vk7zms's post, he has 2 scripts:
First script is scheduled to run every minute
:global datetime ([/system clock get time] . " - " . [:pick[/system clock get date] 4 6] . "-" . [:pick [/system clock get date]0 3] . "-" . [:pick[/system clock get date] 7 11])
/system ups monitor [/system ups find name "ups1"] once do {
:if ($on-battery="yes") do {:set trigger ($trigger + 1)
}
}
:if ($trigger=1) do {/tool e-mail send to=my.email@isp.com.au subject=("Power Failure At " . $datetime) body=("Power Failure at office at " . $datetime)
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {
/tool e-mail send to=my.email@isp.com.au subject=(" Power Restored At " . $datetime) body=("Power Restored at office" . $datetime)
}
}
/system ups monitor [/system ups find name "ups1"] once do {
:if (($trigger > 0) && (!$on-battery="yes")) do {:set trigger 0
}
} 
Second script just sets trigger to 0 and is scheduled to run every half of an hour
:global trigger 0
 
xandor
newbie
Posts: 39
Joined: Wed Mar 30, 2005 6:29 pm

Tue Dec 19, 2006 3:45 pm

OK,
THANKS....

Regards
Xandor
 
xandor
newbie
Posts: 39
Joined: Wed Mar 30, 2005 6:29 pm

Tue Dec 19, 2006 3:45 pm

OK,
THANKS....

Regards
Xandor
 
vk7zms
Member Candidate
Member Candidate
Topic Author
Posts: 227
Joined: Thu Jun 29, 2006 3:01 am
Location: Hobart, Tasmania
Contact:

Tue Dec 19, 2006 10:02 pm

Hi Xandor, Raivis-v is correct.

Regards Murray
 
xandor
newbie
Posts: 39
Joined: Wed Mar 30, 2005 6:29 pm

Wed Dec 20, 2006 2:15 am

HI Murray,
WHAT IS Raivis-v?

REGARDS
 
User avatar
raivis-v
Frequent Visitor
Frequent Visitor
Posts: 55
Joined: Thu Jul 14, 2005 10:21 am
Location: Latvia, Riga

Wed Dec 20, 2006 7:44 am

Raivis-v is a magic variable in script :lol:


Actually i am raivis-v :wink: