From e13c04e4a09b5c5ea34dd65f3a4f9cdaadd47079 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Tue, 25 Feb 2020 10:15:51 +0200 Subject: Add example interface scripts * examples/dbload: New file. * examples/inspect: New file. * examples/ipadd: New file. * examples/ipdel: New file. --- examples/ipadd | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 examples/ipadd (limited to 'examples/ipadd') diff --git a/examples/ipadd b/examples/ipadd new file mode 100755 index 0000000..f001950 --- /dev/null +++ b/examples/ipadd @@ -0,0 +1,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 +[B<-U> I] +[B<--url>=I] +I + +=head1 DESCRIPTION + +Adds I to the mutable IP list of the running B daemon. + +=head1 OPTIONS + +=head2 General options + +=over 4 + +=item B<-U>, B<--url>=I + +URL of the running L daemon. Default is C. + +=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, +L. + +=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"; + } +} + + -- cgit v1.2.1