1 package FS::Cron::check;
4 use vars qw( @ISA @EXPORT_OK $DEBUG $FS_RUN $error_msg
5 $SELFSERVICE_USER $SELFSERVICE_MACHINES @SELFSERVICE_MACHINES
10 use FS::Record qw(qsearch);
11 use FS::cust_pay_pending;
13 @ISA = qw( Exporter );
15 check_queued check_selfservice check_apache check_bop_failures
25 _check_fsproc('queued');
28 $SELFSERVICE_USER = '%%%SELFSERVICE_USER%%%';
30 $SELFSERVICE_MACHINES = '%%%SELFSERVICE_MACHINES%%%'; #substituted by Makefile
31 $SELFSERVICE_MACHINES =~ s/^\s+//;
32 $SELFSERVICE_MACHINES =~ s/\s+$//;
33 @SELFSERVICE_MACHINES = split(/\s+/, $SELFSERVICE_MACHINES);
34 @SELFSERVICE_MACHINES = ()
35 if scalar(@SELFSERVICE_MACHINES) == 1
36 && $SELFSERVICE_MACHINES[0] eq '%%%'.'SELFSERVICE_MACHINES'.'%%%';
38 sub check_selfservice {
39 foreach my $machine ( @SELFSERVICE_MACHINES ) {
40 unless ( _check_fsproc("selfservice-server.$SELFSERVICE_USER.$machine") ) {
41 $error_msg = "Self-service daemon not running for $machine";
49 my $conf = new FS::Conf;
50 return 1 unless $conf->exists('sg-multicustomer_hack');
52 my $ua = new LWP::UserAgent;
53 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
58 my $req = new HTTP::Request GET=>"https://$USER:$PASS\@localhost/sg/ping.cgi";
59 my $res = $ua->request($req);
61 return 1 if $res->is_success
62 && $res->content =~ /OK/;
64 $error_msg = $res->is_success ? $res->content : Rres->status_line;
70 my $conf = new FS::Conf;
71 return 1 unless $conf->exists('sg-multicustomer_hack');
73 eval 'use RPC::XML; use RPC::XML::Client;';
74 if ($@) { $error_msg = $@; return 0; };
76 my $cli = RPC::XML::Client->new('https://localhost/selfservice/xmlrpc.cgi');
77 my $resp = $cli->send_request('FS.SelfService.XMLRPC.ping');
79 return 1 if ref($resp)
82 && $resp->value->{'pong'} == 1;
85 $error_msg = ref($resp)
88 : ( ref($resp->value) ? $resp->value->{'error'}
98 _check_pidfile( "freeside-$arg.pid" );
103 open(PID, "$FS_RUN/$pidfile") or return 0;
104 chomp( my $pid = scalar(<PID>) );
105 close PID; # or return 0;
107 $pid && kill 0, $pid;
111 my $ua = new LWP::UserAgent;
112 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
114 my $req = new HTTP::Request GET => 'https://localhost/';
115 my $res = $ua->request($req);
117 return 1 if $res->is_success || $res->status_line =~ /^403/;
118 $error_msg = $res->status_line;
123 #and now for something entirely different...
124 my $num_consecutive_bop_failures = 50;
125 sub check_bop_failures {
127 return 1 if grep { $_->statustext eq 'captured' }
129 'table' => 'cust_pay_pending',
130 'hashref' => { 'status' => 'done' },
131 'order_by' => 'ORDER BY paypendingnum DESC'.
132 " LIMIT $num_consecutive_bop_failures",
134 $error_msg = "Last $num_consecutive_bop_failures real-time payments failed";
145 my( $alert, @emails ) = @_;
147 my $conf = new FS::Conf;
148 my $smtpmachine = $conf->config('smtpmachine');
149 my $company_name = $conf->config('company_name');
151 foreach my $email (@emails) {
152 warn "warning $email about $alert\n" if $DEBUG;
154 my $message = <<"__MESSAGE__";
155 From: support\@freeside.biz
157 Subject: FREESIDE ALERT for $company_name
159 FREESIDE ALERT: $alert
163 my $sender = Email::Send->new({ mailer => 'SMTP' });
164 $sender->mailer_args([ Host => $smtpmachine ]);
165 $sender->send($message);