aboutsummaryrefslogtreecommitdiff
path: root/examples/inspect
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-02-25 10:15:51 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-02-25 10:15:51 +0200
commite13c04e4a09b5c5ea34dd65f3a4f9cdaadd47079 (patch)
tree8bc8f57434aebfccab24fd4b185bb1c361c0fabc /examples/inspect
parent8ac571387454ab8c728402ccf7ebd1f166204fe6 (diff)
downloadping903-e13c04e4a09b5c5ea34dd65f3a4f9cdaadd47079.tar.gz
ping903-e13c04e4a09b5c5ea34dd65f3a4f9cdaadd47079.tar.bz2
Add example interface scripts
* examples/dbload: New file. * examples/inspect: New file. * examples/ipadd: New file. * examples/ipdel: New file.
Diffstat (limited to 'examples/inspect')
-rwxr-xr-xexamples/inspect115
1 files changed, 115 insertions, 0 deletions
diff --git a/examples/inspect b/examples/inspect
new file mode 100755
index 0000000..beebc17
--- /dev/null
+++ b/examples/inspect
@@ -0,0 +1,115 @@
+#!/bin/sh
+#! -*-perl-*-
+eval 'exec perl -x -S $0 ${1+"$@"}'
+ if 0;
+
+=head1 NAME
+
+inspect - inspect the Ping903 daemon configuration
+
+=head1 SYNOPSIS
+
+B<inspect>
+[B<-U> I<URL>]
+[B<--url>=I<URL>]
+
+=head1 DESCRIPTION
+
+Queries the running B<ping903> instance and displays its configuration on
+standard output.
+
+=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);
+die "too many arguments; try `$0 --help' for more info\n" if @ARGV;
+
+my $ua = new LWP::UserAgent;
+my $response = $ua->get("$baseurl/config");
+unless ($response->is_success) {
+ die $response->status_line;
+}
+
+my $resp = JSON->new->decode($response->decoded_content);
+foreach my $kw (grep { $_ ne 'ip-list' } sort keys %$resp) {
+ my $val = $resp->{$kw} or next;
+ if (ref($val) eq 'ARRAY') {
+ foreach my $sv (@$val) {
+ print "$kw $sv\n";
+ }
+ } else {
+ print "$kw ";
+ if (JSON::is_bool($val)) {
+ print $val ? "on" : "off";
+ } else {
+ print $val
+ }
+ print "\n";
+ }
+}
+
+if (@{$resp->{'ip-list'}}) {
+ print "ip-list <<EOF\n";
+ foreach my $ip (@{$resp->{'ip-list'}}) {
+ print " $ip\n";
+ }
+ print "EOF\n";
+}
+
+

Return to:

Send suggestions and report system problems to the System administrator.