1 package FS::Cron::check;
4 use vars qw( @ISA @EXPORT_OK $DEBUG $FS_RUN $error_msg
5 $SELFSERVICE_USER $SELFSERVICE_MACHINES @SELFSERVICE_MACHINES
13 use FS::Record qw(qsearch);
14 use FS::cust_pay_pending;
16 @ISA = qw( Exporter );
18 check_queued check_selfservice check_apache check_bop_failures
27 _check_fsproc('queued');
30 $SELFSERVICE_USER = '%%%SELFSERVICE_USER%%%';
32 $SELFSERVICE_MACHINES = '%%%SELFSERVICE_MACHINES%%%'; #substituted by Makefile
33 $SELFSERVICE_MACHINES =~ s/^\s+//;
34 $SELFSERVICE_MACHINES =~ s/\s+$//;
35 @SELFSERVICE_MACHINES = split(/\s+/, $SELFSERVICE_MACHINES);
36 @SELFSERVICE_MACHINES = ()
37 if scalar(@SELFSERVICE_MACHINES) == 1
38 && $SELFSERVICE_MACHINES[0] eq '%%%'.'SELFSERVICE_MACHINES'.'%%%';
40 sub check_selfservice {
41 foreach my $machine ( @SELFSERVICE_MACHINES ) {
42 unless ( _check_fsproc("selfservice-server.$SELFSERVICE_USER.$machine") ) {
43 $error_msg = "Self-service daemon not running for $machine";
52 _check_pidfile( "freeside-$arg.pid" );
57 open(PID, "$FS_RUN/$pidfile") or return 0;
58 chomp( my $pid = scalar(<PID>) );
59 close PID; # or return 0;
65 my $ua = new LWP::UserAgent;
66 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
68 my $req = new HTTP::Request GET => 'https://localhost/';
69 my $res = $ua->request($req);
71 return 1 if $res->is_success || $res->status_line =~ /^403/;
72 $error_msg = $res->status_line;
77 #and now for something entirely different...
78 my $num_consecutive_bop_failures = 60;
79 sub check_bop_failures {
81 return 1 if grep { $_->statustext eq 'captured' }
83 'table' => 'cust_pay_pending',
84 'hashref' => { 'status' => 'done' },
85 'order_by' => 'ORDER BY paypendingnum DESC'.
86 " LIMIT $num_consecutive_bop_failures",
88 $error_msg = "Last $num_consecutive_bop_failures real-time payments failed";
99 my( $alert, @emails ) = @_;
101 my $conf = new FS::Conf;
102 my $smtpmachine = $conf->config('smtpmachine');
103 my $company_name = $conf->config('company_name');
105 foreach my $email (@emails) {
106 warn "warning $email about $alert\n" if $DEBUG;
108 my $message = <<"__MESSAGE__";
109 From: support\@freeside.biz
111 Subject: FREESIDE ALERT for $company_name
113 FREESIDE ALERT: $alert
117 my $sender = Email::Send->new({ mailer => 'SMTP' });
118 $sender->mailer_args([ Host => $smtpmachine ]);
119 $sender->send($message);