blob: f0019504d9068a127fea7c81d51a5026d7059017 (
plain)
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
99
|
#!/bin/sh
#! -*-perl-*-
eval 'exec perl -x -S $0 ${1+"$@"}'
if 0;
=head1 NAME
ipadd - adds a single IP to the ping903 ip list
=head1 SYNOPSIS
B<ipadd>
[B<-U> I<URL>]
[B<--url>=I<URL>]
I<IP>
=head1 DESCRIPTION
Adds I<IP> to the mutable IP list of the running B<ping903> daemon.
=head1 OPTIONS
=head2 General options
=over 4
=item B<-U>, B<--url>=I<URL>
URL of the running L<ping903> daemon. Default is C<http://localhost:8080>.
=back
=head2 Informative options
=over 4
=item B<-?>
Display short help summary.
=item B<--usage>
Display command line usage summary.
=item B<--help>
Display a detailed program manual.
=back
=head1 SEE ALSO
L<ping903>,
L<DBI>.
=cut
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use Getopt::Long qw(:config gnu_getopt no_ignore_case);
use Pod::Usage;
use Pod::Man;
my $baseurl = 'http://localhost:8080';
GetOptions(
'U|url=s' => \$baseurl,
'help' => sub {
pod2usage(-exitstatus => 0, -verbose => 2);
},
'usage' => sub {
pod2usage(-exitstatus => 0, -verbose => 0);
},
'hh|?' => sub {
pod2usage(-message => "dbload - load IP addresses to ping903",
-exitstatus => 0);
},
) or exit(1);
my $ip = shift @ARGV or die "not enough arguments";
die "too many arguments; try `$0 --help' for more info\n" if @ARGV;
my $ua = new LWP::UserAgent;
my $response = $ua->put("$baseurl/config/ip-list/$ip");
unless ($response->is_success) {
print $response->status_line,"\n";
my $ctype = $response->header('Content-Type');
if ($ctype && $ctype eq 'application/json') {
my $expl = JSON->new->decode($response->decoded_content);
if (exists($expl->{index})) {
print "Item $expl->{index}: ";
}
print "$expl->{message}\n";
}
}
|