From 25cf511573ebff303700ce71611450ad72debcbc Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 24 Sep 2009 03:14:27 +0000 Subject: [PATCH] add SG and SGNG ping, RT#4610 --- FS/FS/ClientAPI/SGNG.pm | 7 ++++ FS/FS/Cron/check.pm | 49 ++++++++++++++++++++++++++++ FS/bin/freeside-check | 9 +++-- fs_selfservice/FS-SelfService/SelfService.pm | 1 + 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/FS/FS/ClientAPI/SGNG.pm b/FS/FS/ClientAPI/SGNG.pm index 872148abd..7f784dcd0 100644 --- a/FS/FS/ClientAPI/SGNG.pm +++ b/FS/FS/ClientAPI/SGNG.pm @@ -20,6 +20,13 @@ sub _cache { } ); } +sub ping { + #my $p = shift; + + return { 'pong' => '1' }; + +} + #this might almost be general-purpose sub decompify_pkgs { my $p = shift; diff --git a/FS/FS/Cron/check.pm b/FS/FS/Cron/check.pm index c4e712c61..b331014ab 100644 --- a/FS/FS/Cron/check.pm +++ b/FS/FS/Cron/check.pm @@ -13,6 +13,7 @@ use FS::cust_pay_pending; @ISA = qw( Exporter ); @EXPORT_OK = qw( check_queued check_selfservice check_apache check_bop_failures + check_sg check_sgng alert error_msg ); @@ -44,6 +45,54 @@ sub check_selfservice { return 1; } +sub check_sg { + my $conf = new FS::Conf; + return 1 unless $conf->exists('sg-multicustomer_hack'); + + my $ua = new LWP::UserAgent; + $ua->agent("FreesideCronCheck/0.1 " . $ua->agent); + + #XXX shiiiiit. + my $USER = ''; + my $PASS = ''; + my $req = new HTTP::Request GET=>"https://$USER:$PASS\@localhost/sg/ping.cgi"; + my $res = $ua->request($req); + + return 1 if $res->is_success + && $res->content =~ /OK/; + + $error_msg = $res->is_success ? $res->content : Rres->status_line; + return 0; + +} + +sub check_sgng { + my $conf = new FS::Conf; + return 1 unless $conf->exists('sg-multicustomer_hack'); + + eval 'use RPC::XML; use RPC::XML::Client;'; + if ($@) { $error_msg = $@; return 0; }; + + my $cli = RPC::XML::Client->new('https://localhost/selfservice/xmlrpc.cgi'); + my $resp = $cli->send_request('FS.SelfService.XMLRPC.ping'); + + return 1 if ref($resp) + && ! $resp->is_fault + && ref($resp->value) + && $resp->value->{'pong'} == 1; + + #hua + $error_msg = ref($resp) + ? ( $resp->is_fault + ? $resp->string + : ( ref($resp->value) ? $resp->value->{'error'} + : $resp->value + ) + ) + : $resp; + return 0; +} + sub _check_fsproc { my $arg = shift; _check_pidfile( "freeside-$arg.pid" ); diff --git a/FS/bin/freeside-check b/FS/bin/freeside-check index f2d596b80..ac2fc3d03 100644 --- a/FS/bin/freeside-check +++ b/FS/bin/freeside-check @@ -6,6 +6,7 @@ use Email::Send; use FS::UID qw( adminsuidsetup ); use FS::Cron::check qw( check_queued check_selfservice check_apache check_bop_failures + check_sg check_sgng alert error_msg ); @@ -17,9 +18,13 @@ eval { adminsuidsetup $user }; if ( $@ ) { alert("Database down: $@", @emails); exit; } -check_queued or alert("Queue daemon not running", @emails); +check_queued or alert('Queue daemon not running', @emails); check_selfservice or alert(error_msg(), @emails); -check_apache or alert("Apache not running: ". error_msg(), @emails); +check_apache or alert('Apache not running: '. error_msg(), @emails); + +#no-ops unless you are sg +check_sg or alert('FS::ClientAPI::SG not responding', @emails); +check_sgng or alert('FS::ClientAPI::SGNG not responding', @emails); check_bop_failures or alert(error_msg(), @emails); diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 4173e28d6..49629d423 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -76,6 +76,7 @@ $socket .= '.'.$tag if defined $tag && length($tag); 'bulk_processrow' => 'Bulk/processrow', 'check_username' => 'Bulk/check_username', #sg + 'ping' => 'SGNG/ping', 'decompify_pkgs' => 'SGNG/decompify_pkgs', 'previous_payment_info' => 'SGNG/previous_payment_info', 'previous_payment_info_renew_info' -- 2.11.0