add SG and SGNG ping, RT#4610
authorivan <ivan>
Thu, 24 Sep 2009 03:14:32 +0000 (03:14 +0000)
committerivan <ivan>
Thu, 24 Sep 2009 03:14:32 +0000 (03:14 +0000)
FS/FS/ClientAPI/SGNG.pm
FS/FS/Cron/check.pm
FS/bin/freeside-check
fs_selfservice/FS-SelfService/SelfService.pm

index 872148a..7f784dc 100644 (file)
@@ -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;
index c4e712c..b331014 100644 (file)
@@ -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" );
index f2d596b..ac2fc3d 100644 (file)
@@ -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);
 
index aa162ee..36928d0 100644 (file)
@@ -62,6 +62,7 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'agent_info'                => 'Agent/agent_info',
   'agent_list_customers'      => 'Agent/agent_list_customers',
   #sg
+  'ping'                      => 'SGNG/ping',
   'decompify_pkgs'            => 'SGNG/decompify_pkgs',
   'previous_payment_info'     => 'SGNG/previous_payment_info',
   'previous_payment_info_renew_info'