-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpushover.pl
executable file
·98 lines (74 loc) · 3.15 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use Getopt::Std;
use Pod::Usage;
my $priority_setting = 0;
my $options = {};
getopt('akmtdurh:sbpi:', $options);
if (!defined($options->{'a'}) || !defined($options->{'k'})) {
pod2usage( -message => "Specify APP_TOKEN or USER_KEY", -exitval => 1);
}
if (!defined($options->{'m'}) && !exists($options->{'i'})) {
pod2usage( -message => "User -m or -i to supply message", -exitval => 1);
}
$priority_setting = 1 if (defined($options->{'h'}));
# -p overrides priority setting
if (defined($options->{'p'}))
{
# accept -2,-1,0,1,+1,2,+2
if ($options->{'p'} !~ /^(-[1-2]|0|\+{0,1}[1-2])$/)
{
pod2usage( -message => "ERROR: invalid priority value", -exitval => 1);
}
# strip leading +
($priority_setting) = ($options->{'p'} =~ s/^\+//g);
}
delete $options->{'r'} if (defined($options->{'r'}) && !defined($options->{'u'}));
if (exists($options->{'i'})) {
print "Enter your message (Ctrl+D to send):\n";
my @message;
while(<STDIN>) {
push(@message, $_);
}
$options->{'m'} = join('', @message);
}
my %push_options = (
'token' => $options->{'a'},
'user' => $options->{'k'},
'message' => $options->{'m'}
);
$push_options{'title'} = $options->{'t'} if (defined($options->{'t'}));
$push_options{'device'} = $options->{'d'} if (defined($options->{'d'}));
$push_options{'url'} = $options->{'u'} if (defined($options->{'u'}));
$push_options{'url_title'} = $options->{'r'} if (defined($options->{'r'}));
$push_options{'priority'} = $priority_setting;
$push_options{'timestamp'} = $options->{'s'} if (defined($options->{'s'}));
$push_options{'sound'} = $options->{'b'} if (defined($options->{'b'}));
LWP::UserAgent->new()->post("https://api.pushover.net/1/messages", \%push_options);
__END__
=head1 NAME
pushover.pl -- Send pushover notifications from command line
=head1 SYNOPSIS
Usage: **pushover.pl _[options]_**
Required command-line arguments:
-a APP_TOKEN Your application's token
-k USER_KEY Your User token
-m MESSAGE The message you want to send
Optional command-line arguments:
-t TITLE The title of your message
-d DEVICE Send the message only to DEVICE
-u URL A URL to send
-r URL_TITLE Optional title for the URL
-h The message is high priority - bypass quiet hours. Equivalent to -p 1
-s UNIX_TIMESTAMP Unix timestamp of the message
-b SOUND The Sound file to play (see https://pushover.net/api#sounds)
-p PRIORITY Priority number (-2 to 2 / Lowest to Highest). Overrides -h
-i Use STDIN for message input - useful if you want to have new lines in your message
Supplying an application token, a user key and a message is mandatory.
The message can be given either as a command line parameter following the -m argument or interactively using the -i argument.
The latter case is useful if you want your push message to include new lines
=head1 DESCRIPTION
This is a simple pushover.net client for sending push messages from the command line to devices that have the Pushover app installed.
=cut