add login check to FS::ClientAPI::SG/SGNG checks. RT#4610
authorivan <ivan>
Thu, 1 Oct 2009 00:29:06 +0000 (00:29 +0000)
committerivan <ivan>
Thu, 1 Oct 2009 00:29:06 +0000 (00:29 +0000)
FS/FS/Conf.pm
FS/FS/Cron/check.pm
FS/bin/freeside-check

index d5304af..7112417 100644 (file)
@@ -3007,6 +3007,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'sg-login_username',
+    'section'     => '',
+    'description' => "Don't use this.",
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'disable-cust-pkg_class',
     'section'     => 'UI',
     'description' => 'Disable the two-step dropdown for selecting package class and package, and return to the classic single dropdown.',
index f38cb5f..9d3ffbd 100644 (file)
@@ -6,6 +6,8 @@ use vars qw( @ISA @EXPORT_OK $DEBUG $FS_RUN $error_msg
            );
 use Exporter;
 use LWP::UserAgent;
+use HTTP::Request;
+use URI::Escape;
 use Email::Send;
 use FS::Conf;
 use FS::Record qw(qsearch);
@@ -14,7 +16,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
+  check_sg check_sg_login check_sgng
   alert error_msg
 );
 
@@ -65,7 +67,30 @@ sub check_sg {
 
   $error_msg = $res->is_success ? $res->content : $res->status_line;
   return 0;
+}
+
+sub check_sg_login {
+  my $conf = new FS::Conf;
+  #different trigger if they ever stop using multicustomer_hack ?
+  return 1 unless $conf->exists('sg-multicustomer_hack');
+
+  my $ua = new LWP::UserAgent;
+  $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
 
+  my $USER = $conf->config('sg-ping_username');
+  my $PASS = $conf->config('sg-ping_password');
+  my $USERNAME = $conf->config('sg-login_username');
+  my $req = new HTTP::Request
+    GET=>"https://$USER:$PASS\@localhost/sg/start.cgi?".
+         'username='. uri_escape($USERNAME);
+  my $res = $ua->request($req);
+
+  return 1 if $res->is_success
+           && $res->content =~ /[\da-f]{32}/i #session_id
+           && $res->content !~ /error/i;
+
+  $error_msg = $res->is_success ? $res->content : $res->status_line;
+  return 0;
 }
 
 sub check_sgng {
@@ -124,7 +149,7 @@ sub check_apache {
 }
 
 #and now for something entirely different...
-my $num_consecutive_bop_failures = 50;
+my $num_consecutive_bop_failures = 60;
 sub check_bop_failures {
 
   return 1 if grep { $_->statustext eq 'captured' }
index 9c9da76..9930aae 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 use FS::UID qw( adminsuidsetup );
 use FS::Cron::check qw(
   check_queued check_selfservice check_apache check_bop_failures
-  check_sg check_sgng
+  check_sg check_sg_login check_sgng
   alert error_msg
 );
 
@@ -23,7 +23,8 @@ check_apache       or alert('Apache not running: '. error_msg(), @emails);
 
 #no-ops unless you are sg
 my $sg = 'FS::ClientAPI::SG';
-check_sg           or alert("$sg not responding: ". error_msg(),     @emails);
+check_sg           or alert("$sg not responding: ".     error_msg(), @emails);
+check_sg_login     or alert("$sg login errort: ".       error_msg(), @emails);
 check_sgng         or alert("${sg}NG not responding: ". error_msg(), @emails);
 
 check_bop_failures or alert(error_msg(), @emails);