From ea771de9552fe4b22d49ecb6b73614cbcc995223 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 1 Oct 2009 00:29:06 +0000 Subject: [PATCH] add login check to FS::ClientAPI::SG/SGNG checks. RT#4610 --- FS/FS/Conf.pm | 7 +++++++ FS/FS/Cron/check.pm | 29 +++++++++++++++++++++++++++-- FS/bin/freeside-check | 5 +++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index d5304afab..7112417d5 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -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.', diff --git a/FS/FS/Cron/check.pm b/FS/FS/Cron/check.pm index f38cb5f6b..9d3ffbdbd 100644 --- a/FS/FS/Cron/check.pm +++ b/FS/FS/Cron/check.pm @@ -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' } diff --git a/FS/bin/freeside-check b/FS/bin/freeside-check index 9c9da7646..9930aae6c 100644 --- a/FS/bin/freeside-check +++ b/FS/bin/freeside-check @@ -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); -- 2.11.0