-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify_pushover.pl
54 lines (42 loc) · 1.53 KB
/
notify_pushover.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Category=Home_Network
#
#@ Sends Notification message to Pushover
use strict;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$v_notify_pushover = new Voice_Cmd("Test Pushover Notify");
if ($Startup) {
# Notify the on startup / restart
print_log("System Restarted, Notifying Pushover") if $Debug{pushover};
notify_pushover("System Restarted", "Misterhouse has been restarted");
}
if (said $v_notify_pushover) {
# Send a test notification
print_log("Sending test notification") if $Debug{pushover};
notify_pushover("Test Notification", "This is a test notification!!");
}
sub notify_pushover {
my ($title, $text, $priority) = @_;
unless($config_parms{pushover_app_token}){
print_log("pushover_app_token has not been set in mh.ini, Unable to notify pushover.");
return;
}
unless($config_parms{pushover_user_key}){
print_log("pushover_user_key has not been set in mh.ini, Unable to notify pushover.");
return;
}
print_log("Sending notification to Pushover") if $Debug{pushover};
my $url = "https://api.pushover.net/1/messages.json";
print_log("pushover: title: $title, text: $text");
my $ua = LWP::UserAgent->new();
my $req = POST $url, [
token => $config_parms{pushover_app_token},
user => $config_parms{pushover_user_key},
message => $text,
title => $title,
priority => $priority,
expire => 3600,
retry => 300,
];
my $content = $ua->request($req)->as_string;
}