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 #different trigger if they ever stop using multicustomer_hack ?
51 return 1 unless $conf->exists('sg-multicustomer_hack');
53 my $ua = new LWP::UserAgent;
54 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
56 my $USER = $conf->config('sg-ping_username');
57 my $PASS = $conf->config('sg-ping_password');
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 #different trigger if they ever stop using multicustomer_hack ?
72 return 1 unless $conf->exists('sg-multicustomer_hack');
74 eval 'use RPC::XML; use RPC::XML::Client;';
75 if ($@) { $error_msg = $@; return 0; };
77 my $cli = RPC::XML::Client->new('https://localhost/selfservice/xmlrpc.cgi');
78 my $resp = $cli->send_request('FS.SelfService.XMLRPC.ping');
80 return 1 if ref($resp)
83 && $resp->value->{'pong'} == 1;
86 $error_msg = ref($resp)
89 : ( ref($resp->value) ? $resp->value->{'error'}
99 _check_pidfile( "freeside-$arg.pid" );
104 open(PID, "$FS_RUN/$pidfile") or return 0;
105 chomp( my $pid = scalar(<PID>) );
106 close PID; # or return 0;
108 $pid && kill 0, $pid;
112 my $ua = new LWP::UserAgent;
113 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
115 my $req = new HTTP::Request GET => 'https://localhost/';
116 my $res = $ua->request($req);
118 return 1 if $res->is_success || $res->status_line =~ /^403/;
119 $error_msg = $res->status_line;
124 #and now for something entirely different...
125 my $num_consecutive_bop_failures = 50;
126 sub check_bop_failures {
128 return 1 if grep { $_->statustext eq 'captured' }
130 'table' => 'cust_pay_pending',
131 'hashref' => { 'status' => 'done' },
132 'order_by' => 'ORDER BY paypendingnum DESC'.
133 " LIMIT $num_consecutive_bop_failures",
135 $error_msg = "Last $num_consecutive_bop_failures real-time payments failed";
146 my( $alert, @emails ) = @_;
148 my $conf = new FS::Conf;
149 my $smtpmachine = $conf->config('smtpmachine');
150 my $company_name = $conf->config('company_name');
152 foreach my $email (@emails) {
153 warn "warning $email about $alert\n" if $DEBUG;
155 my $message = <<"__MESSAGE__";
156 From: support\@freeside.biz
158 Subject: FREESIDE ALERT for $company_name
160 FREESIDE ALERT: $alert
164 my $sender = Email::Send->new({ mailer => 'SMTP' });
165 $sender->mailer_args([ Host => $smtpmachine ]);
166 $sender->send($message);