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/
64 && $res->content !~ /error/i; #doh, the error message includes "OK"
66 $error_msg = $res->is_success ? $res->content : $res->status_line;
72 my $conf = new FS::Conf;
73 #different trigger if they ever stop using multicustomer_hack ?
74 return 1 unless $conf->exists('sg-multicustomer_hack');
76 eval 'use RPC::XML; use RPC::XML::Client;';
77 if ($@) { $error_msg = $@; return 0; };
79 my $cli = RPC::XML::Client->new('https://localhost/selfservice/xmlrpc.cgi');
80 my $resp = $cli->send_request('FS.SelfService.XMLRPC.ping');
82 return 1 if ref($resp)
85 && $resp->value->{'pong'} == 1;
88 $error_msg = ref($resp)
91 : ( ref($resp->value) ? $resp->value->{'error'}
101 _check_pidfile( "freeside-$arg.pid" );
106 open(PID, "$FS_RUN/$pidfile") or return 0;
107 chomp( my $pid = scalar(<PID>) );
108 close PID; # or return 0;
110 $pid && kill 0, $pid;
114 my $ua = new LWP::UserAgent;
115 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
117 my $req = new HTTP::Request GET => 'https://localhost/';
118 my $res = $ua->request($req);
120 return 1 if $res->is_success || $res->status_line =~ /^403/;
121 $error_msg = $res->status_line;
126 #and now for something entirely different...
127 my $num_consecutive_bop_failures = 50;
128 sub check_bop_failures {
130 return 1 if grep { $_->statustext eq 'captured' }
132 'table' => 'cust_pay_pending',
133 'hashref' => { 'status' => 'done' },
134 'order_by' => 'ORDER BY paypendingnum DESC'.
135 " LIMIT $num_consecutive_bop_failures",
137 $error_msg = "Last $num_consecutive_bop_failures real-time payments failed";
148 my( $alert, @emails ) = @_;
150 my $conf = new FS::Conf;
151 my $smtpmachine = $conf->config('smtpmachine');
152 my $company_name = $conf->config('company_name');
154 foreach my $email (@emails) {
155 warn "warning $email about $alert\n" if $DEBUG;
157 my $message = <<"__MESSAGE__";
158 From: support\@freeside.biz
160 Subject: FREESIDE ALERT for $company_name
162 FREESIDE ALERT: $alert
166 my $sender = Email::Send->new({ mailer => 'SMTP' });
167 $sender->mailer_args([ Host => $smtpmachine ]);
168 $sender->send($message);