1 package FS::Cron::check;
4 use vars qw( @ISA @EXPORT_OK $DEBUG $FS_RUN $error_msg
5 $SELFSERVICE_USER $SELFSERVICE_MACHINES @SELFSERVICE_MACHINES
11 use FS::Record qw(qsearch);
12 use FS::cust_pay_pending;
14 @ISA = qw( Exporter );
16 check_queued check_selfservice check_apache check_bop_failures
26 _check_fsproc('queued');
29 $SELFSERVICE_USER = '%%%SELFSERVICE_USER%%%';
31 $SELFSERVICE_MACHINES = '%%%SELFSERVICE_MACHINES%%%'; #substituted by Makefile
32 $SELFSERVICE_MACHINES =~ s/^\s+//;
33 $SELFSERVICE_MACHINES =~ s/\s+$//;
34 @SELFSERVICE_MACHINES = split(/\s+/, $SELFSERVICE_MACHINES);
35 @SELFSERVICE_MACHINES = ()
36 if scalar(@SELFSERVICE_MACHINES) == 1
37 && $SELFSERVICE_MACHINES[0] eq '%%%'.'SELFSERVICE_MACHINES'.'%%%';
39 sub check_selfservice {
40 foreach my $machine ( @SELFSERVICE_MACHINES ) {
41 unless ( _check_fsproc("selfservice-server.$SELFSERVICE_USER.$machine") ) {
42 $error_msg = "Self-service daemon not running for $machine";
50 my $conf = new FS::Conf;
51 #different trigger if they ever stop using multicustomer_hack ?
52 return 1 unless $conf->exists('sg-multicustomer_hack');
54 my $ua = new LWP::UserAgent;
55 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
57 my $USER = $conf->config('sg-ping_username');
58 my $PASS = $conf->config('sg-ping_password');
59 my $req = new HTTP::Request GET=>"https://$USER:$PASS\@localhost/sg/ping.cgi";
60 my $res = $ua->request($req);
62 return 1 if $res->is_success
63 && $res->content =~ /OK/;
65 $error_msg = $res->is_success ? $res->content : $res->status_line;
71 my $conf = new FS::Conf;
72 #different trigger if they ever stop using multicustomer_hack ?
73 return 1 unless $conf->exists('sg-multicustomer_hack');
75 eval 'use RPC::XML; use RPC::XML::Client;';
76 if ($@) { $error_msg = $@; return 0; };
78 my $cli = RPC::XML::Client->new('https://localhost/selfservice/xmlrpc.cgi');
79 my $resp = $cli->send_request('FS.SelfService.XMLRPC.ping');
81 return 1 if ref($resp)
84 && $resp->value->{'pong'} == 1;
87 $error_msg = ref($resp)
90 : ( ref($resp->value) ? $resp->value->{'error'}
100 _check_pidfile( "freeside-$arg.pid" );
105 open(PID, "$FS_RUN/$pidfile") or return 0;
106 chomp( my $pid = scalar(<PID>) );
107 close PID; # or return 0;
109 $pid && kill 0, $pid;
113 my $ua = new LWP::UserAgent;
114 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
116 my $req = new HTTP::Request GET => 'https://localhost/';
117 my $res = $ua->request($req);
119 return 1 if $res->is_success || $res->status_line =~ /^403/;
120 $error_msg = $res->status_line;
125 #and now for something entirely different...
126 my $num_consecutive_bop_failures = 50;
127 sub check_bop_failures {
129 return 1 if grep { $_->statustext eq 'captured' }
131 'table' => 'cust_pay_pending',
132 'hashref' => { 'status' => 'done' },
133 'order_by' => 'ORDER BY paypendingnum DESC'.
134 " LIMIT $num_consecutive_bop_failures",
136 $error_msg = "Last $num_consecutive_bop_failures real-time payments failed";
147 my( $alert, @emails ) = @_;
149 my $conf = new FS::Conf;
150 my $smtpmachine = $conf->config('smtpmachine');
151 my $company_name = $conf->config('company_name');
153 foreach my $email (@emails) {
154 warn "warning $email about $alert\n" if $DEBUG;
156 my $message = <<"__MESSAGE__";
157 From: support\@freeside.biz
159 Subject: FREESIDE ALERT for $company_name
161 FREESIDE ALERT: $alert
165 my $sender = Email::Send->new({ mailer => 'SMTP' });
166 $sender->mailer_args([ Host => $smtpmachine ]);
167 $sender->send($message);