From 61afb166ed60df3f637f80d71e5699fe420c9872 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 3 Jul 2011 21:30:55 +0200 Subject: [PATCH] EasyGateway SOAP poller --- Makefile.PL | 1 + lib/APKPM/EasyGateway.pm | 55 ++++++++++++++++++++++++++++++++++++++++ t/EasyGateway.t | 15 +++++++++++ 3 files changed, 71 insertions(+) create mode 100644 lib/APKPM/EasyGateway.pm create mode 100755 t/EasyGateway.t diff --git a/Makefile.PL b/Makefile.PL index bda893d..0fd7c1c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,6 +12,7 @@ WriteMakefile( 'DBD::Pg' => 0, 'Regexp::Common' => 0, 'Redis' => 0, + 'SOAP::Lite' => 0, }, AUTHOR => 'Dobrica Pavlinusic ', # ABSTRACT_FROM => 'lib/APKPM.pm', diff --git a/lib/APKPM/EasyGateway.pm b/lib/APKPM/EasyGateway.pm new file mode 100644 index 0000000..6aec408 --- /dev/null +++ b/lib/APKPM/EasyGateway.pm @@ -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 index 0000000..66e80e5 --- /dev/null +++ b/t/EasyGateway.t @@ -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); -- 2.20.1