Community discussions

MikroTik App
 
User avatar
dasiu
Trainer
Trainer
Topic Author
Posts: 231
Joined: Fri Jan 30, 2009 11:41 am
Location: Reading, UK
Contact:

PUSHOVER - ready MikroTik script to send messages

Fri Jun 29, 2018 12:19 am

I've just written a script (function) to send the Pushover messages directly from MikroTik, not using e-mail but direct API (faster). Just run once on bootup to "install" the functions:
:global urlEncode do={
  :local output ""
  :local input [:toarray $1]
  :if ([:len $input] > 0) do={
    :local input1 [:tostr [:pick $input 0]]
    :local conversion {" "="%20";"!"="%21";"\""="%22";"#"="%23";"\$"="%24";"%"="%25";"&"="%26";"'"="%27";"-"="%2D";"("="%28";")"="%29";"*"="%2A";"+"="%2B";","="%2C";"/"="%2F";":"="%3A";";"="%3B";"<"="%3C";">"="%3E";"="="%3D";"?"="%3F";"@"="%40";"["="%5B";"]"="%5D";"{"="%7B";"}"="%7D"};
    :for i from=0 to=([:len $input1] - 1) do={ 
      :local char [:pick $input1 $i]
      :if ([:typeof ($conversion->[:tostr $char])]!="nothing") do={:set $char ($conversion->[:tostr $char]);}
      :set output ($output . $char)
    }
    :set output [:tostr $output]
    :set output [:toarray $output]
  }
  :return $output
}

:global pushover do={
:global urlEncode;
  :if ([:typeof $message]!="nothing") do={
    :local api "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    :local user "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    :local urlmessage [$urlEncode $message];
    :local string "token=$api&user=$user&message=$urlmessage";
    :if ([:typeof $title]!="nothing") do={:set $string ($string . "&title=$[$urlEncode $title]");}
    :if ([:typeof $priority]!="nothing") do={:set $string ($string . "&priority=$priority");}
    :if ([:typeof $sound]!="nothing") do={:set $string ($string . "&sound=$sound");}
    /tool fetch mode=https url="https://api.pushover.net/1/messages.json" http-method=post http-data="$string";
  }
}
Of course, in "api" and "user" variables I have my keys from Pushover (you need to create application in the Pushover panel). Then I can just do:
$pushover message="This is a simple Pushover message."
Or more advanced:
:local title "Important message from router $[/system identity get name]";                              
:local message "Just writing to inform you that my temperature is $[/system health get temperature] degrees Celsius!" 
$pushover title=$title message=$message priority=1 sound="tugboat"
I used the urlEncode function written by few people in this thread.
 
cantanko
newbie
Posts: 39
Joined: Mon Apr 05, 2010 12:53 am

Re: PUSHOVER - ready MikroTik script to send messages

Wed Apr 03, 2019 9:12 pm

Thank you for this - it's proven to be a very helpful chunk of code!
 
danielcada
just joined
Posts: 3
Joined: Sat Jan 27, 2018 10:02 am

Re: PUSHOVER - ready MikroTik script to send messages

Tue Mar 03, 2020 7:16 pm

Works well on FW 6.45.5 including getting PUSHOVER from NETWATCH.

On FW 6.46.4 works only to send PUSHOVER manualy runing script, but doesn't work to send PUSHOVER from NETWATCH.

Any suggestion?
 
User avatar
dreamind
just joined
Posts: 10
Joined: Thu Apr 18, 2013 9:15 pm
Location: Germany
Contact:

Re: PUSHOVER - ready MikroTik script to send messages

Wed Apr 15, 2020 2:15 am

If you set keep-result=no on the fetch command in the script it works.

Also make sure you set the policy to something like policy=read,write,test on scripts that you want to run from netwatch.
 
Belikearu
just joined
Posts: 4
Joined: Mon Dec 30, 2019 5:53 am
Location: General Santos City, Philippines

Re: PUSHOVER - ready MikroTik script to send messages

Wed Apr 15, 2020 2:37 am

How do you exactly do this? pasting the script on the winbox terminal? and what about the API Keys?
Would you mind elaborating this one? thankyou
 
lacibsd
Frequent Visitor
Frequent Visitor
Posts: 56
Joined: Thu Mar 10, 2016 9:48 pm

Re: PUSHOVER - ready MikroTik script to send messages

Sun May 02, 2021 3:43 am

@Belikearu, In Winbox or webintraface you can place it under System->Scripts
@dasiu, awesome script, I was looking for a pushover integration
 
tmiklas
just joined
Posts: 9
Joined: Mon Apr 02, 2007 12:06 pm

Re: PUSHOVER - ready MikroTik script to send messages

Mon May 03, 2021 1:04 pm

Amazing - thank you!
 
Lilarcor
Frequent Visitor
Frequent Visitor
Posts: 54
Joined: Sun Oct 08, 2017 3:16 am

Re: PUSHOVER - ready MikroTik script to send messages

Fri May 21, 2021 9:06 am

I tried to use it in net watch, but it didn't work even I add keep-result=no in script
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 18959
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: PUSHOVER - ready MikroTik script to send messages

Sat May 22, 2021 4:33 am

I use telegram to send me messages from my router.
Is pushover easier/better to use??
 
Lilarcor
Frequent Visitor
Frequent Visitor
Posts: 54
Joined: Sun Oct 08, 2017 3:16 am

Re: PUSHOVER - ready MikroTik script to send messages

Thu Oct 14, 2021 8:35 am

$pushover message="xyz" does work in terminal, but it doesn't work in scripts

update:
add
:global pushover
and I can use $pushover now
 
RandyRiver88
just joined
Posts: 14
Joined: Fri May 15, 2020 7:28 pm

Re: PUSHOVER - ready MikroTik script to send messages

Thu May 26, 2022 11:52 pm

$pushover message="xyz" does work in terminal, but it doesn't work in scripts

update:
add
:global pushover
and I can use $pushover now
Hi,

Where did you fix this? I am able to send using terminal but not in from inside of scripts….

Can you tell me which line to changed?

Thanks.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: PUSHOVER - ready MikroTik script to send messages

Fri May 27, 2022 12:02 am

Simply READ carefully pervious post...
 
RandyRiver88
just joined
Posts: 14
Joined: Fri May 15, 2020 7:28 pm

Re: PUSHOVER - ready MikroTik script to send messages

Fri May 27, 2022 5:03 am

Simply READ carefully pervious post...
The post is not clear. It does not state where to add it.

The correct answer would have been:

Add :global pushover in the script you are calling $pushover in.

No need to be a dick.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: PUSHOVER - ready MikroTik script to send messages

Fri May 27, 2022 10:29 am

I was helpful, seen? Now you have read it carefully...

Who is online

Users browsing this forum: No registered users and 15 guests