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
24 _check_fsproc('queued');
27 $SELFSERVICE_USER = '%%%SELFSERVICE_USER%%%';
29 $SELFSERVICE_MACHINES = '%%%SELFSERVICE_MACHINES%%%'; #substituted by Makefile
30 $SELFSERVICE_MACHINES =~ s/^\s+//;
31 $SELFSERVICE_MACHINES =~ s/\s+$//;
32 @SELFSERVICE_MACHINES = split(/\s+/, $SELFSERVICE_MACHINES);
33 @SELFSERVICE_MACHINES = ()
34 if scalar(@SELFSERVICE_MACHINES) == 1
35 && $SELFSERVICE_MACHINES[0] eq '%%%'.'SELFSERVICE_MACHINES'.'%%%';
37 sub check_selfservice {
38 foreach my $machine ( @SELFSERVICE_MACHINES ) {
39 unless ( _check_fsproc("selfservice-server.$SELFSERVICE_USER.$machine") ) {
40 $error_msg = "Self-service daemon not running for $machine";
49 _check_pidfile( "freeside-$arg.pid" );
54 open(PID, "$FS_RUN/$pidfile") or return 0;
55 chomp( my $pid = scalar(<PID>) );
56 close PID; # or return 0;
62 my $ua = new LWP::UserAgent;
63 $ua->agent("FreesideCronCheck/0.1 " . $ua->agent);
65 my $req = new HTTP::Request GET => 'https://localhost/';
66 my $res = $ua->request($req);
68 return 1 if $res->is_success || $res->status_line =~ /^403/;
69 $error_msg = $res->status_line;
74 #and now for something entirely different...
75 my $num_consecutive_bop_failures = 40;
76 sub check_bop_failures {
78 return 1 if grep { $_->statustext eq 'captured' }
80 'table' => 'cust_pay_pending',
81 'hashref' => { 'status' => 'done' },
82 'order_by' => 'ORDER BY paypendingnum DESC'.
83 " LIMIT $num_consecutive_bop_failures",
85 $error_msg = "Last $num_consecutive_bop_failures real-time payments failed";
96 my( $alert, @emails ) = @_;
98 my $conf = new FS::Conf;
99 my $smtpmachine = $conf->config('smtpmachine');
100 my $company_name = $conf->config('company_name');
102 foreach my $email (@emails) {
103 warn "warning $email about $alert\n" if $DEBUG;
105 my $message = <<"__MESSAGE__";
106 From: support\@freeside.biz
108 Subject: FREESIDE ALERT for $company_name
110 FREESIDE ALERT: $alert
114 my $sender = Email::Send->new({ mailer => 'SMTP' });
115 $sender->mailer_args([ Host => $smtpmachine ]);
116 $sender->send($message);