EasyGateway SOAP poller
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 3 Jul 2011 19:30:55 +0000 (21:30 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 3 Jul 2011 19:30:55 +0000 (21:30 +0200)
Makefile.PL
lib/APKPM/EasyGateway.pm [new file with mode: 0644]
t/EasyGateway.t [new file with mode: 0755]

index bda893d..0fd7c1c 100644 (file)
@@ -12,6 +12,7 @@ WriteMakefile(
                'DBD::Pg' => 0,
                'Regexp::Common' => 0,
                'Redis' => 0,
+               'SOAP::Lite' => 0,
        },
        AUTHOR       => 'Dobrica Pavlinusic <dpavlin@rot13.org>',
 #      ABSTRACT_FROM => 'lib/APKPM.pm',
diff --git a/lib/APKPM/EasyGateway.pm b/lib/APKPM/EasyGateway.pm
new file mode 100644 (file)
index 0000000..6aec408
--- /dev/null
@@ -0,0 +1,55 @@
+package APKPM::EasyGateway;
+
+use base qw(Gearman::Driver::Worker);
+use Moose;
+use Time::HiRes;
+use Data::Dump qw(dump);
+
+with 'APKPM::Config';
+with 'APKPM::Gearman::Client';
+with 'APKPM::Gearman';
+
+use Redis;
+use SOAP::Lite;
+
+sub prefix { 'EasyGateway_' }
+
+sub info : Job : Decode(d_array) : Encode(e_json) {
+       my ( $self, $job, $workload ) = @_;
+       warn "# workload = ", dump $workload;
+
+       my $ip = $workload;
+
+       return { error => "invalid workload", expected => 'cpe.ip', workload => $workload } unless $ip;
+
+       my $ret;
+
+       my $soap = SOAP::Lite
+               ->service('http://10.99.0.74:9090/cpews/services/Cpe112DiagnosisSoapImpl?WSDL');
+
+       my $out = $soap->getWanDslStatus( "IP=$ip" );
+
+       $ret->{$_} = $out->{$_} foreach keys %$out;
+
+       my $out = $soap->getCpeBasicInfo( "IP=$ip" ); # mac, username, uptime
+
+       foreach ( keys %$out ) {
+               next unless defined $out->{$_}; # skip undef values
+               $ret->{$_} = $out->{$_};
+       }
+
+       $self->do_background_json( 'Store_insert', {
+               _table => 'easygateway',
+               ip => $ip,
+               username => $ret->{customerName},
+               timestamp => $self->datetime_now,
+               h => $self->to_hstore( $ret ),
+       });
+
+       my $redis = Redis->new;
+       $redis->sadd( 'poll.EasyGateway.ok' => $ip );
+
+       return $ret;
+}
+
+1;
diff --git a/t/EasyGateway.t b/t/EasyGateway.t
new file mode 100755 (executable)
index 0000000..66e80e5
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+use Data::Dump qw(dump);
+
+use lib 'lib';
+
+use_ok 'APKPM::EasyGateway';
+
+ok my $o = APKPM::EasyGateway->new, 'new';
+
+ok my $r = $o->info( 'job', $ARGV[0] || '10.16.4.239' ), 'info';
+diag dump($r);