Changeset 1762


Ignore:
Timestamp:
2000-12-07T18:18:21+13:00 (23 years ago)
Author:
sjboddie
Message:

Added support for the new LogEvents, EmailEvents, EmailUserEvents and
MailServer configuration options (though they haven't actually been
implemented yet).

Location:
trunk/gsdl
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/build

    r1753 r1762  
    44# windows (build.bat is in bin\windows)
    55
     6# Note that this script has grown over time and now has many options for
     7# use when called from within the collector. If it appears to
     8# over-complicate things a little, that's why.
     9
    610package build;
    711
     12use lib qq($ENV{'GSDLHOME'}/perllib/cpan);
    813use FileHandle;
    914use File::Copy;
     15use Mail::Sendmail;
     16
    1017
    1118BEGIN {
     
    8592if (-e &util::filename_cat ($cdir, $collection, ".kill")) {
    8693    &util::rm (&util::filename_cat ($cdir, $collection, ".kill"));
     94}
     95
     96# get maintainer email address from main.cfg
     97my $maintainer = "NULL";
     98my $main_cfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
     99my $cfgdata = &cfgread::read_cfg_file ($main_cfg, "maintainer");
     100if (defined $cfgdata->{'maintainer'} && $cfgdata->{'maintainer'} =~ /\w/) {
     101    $maintainer = $cfgdata->{'maintainer'};
     102}
     103# if maintainer is "NULL" email_events should be disabled
     104if ($maintainer =~ /^NULL$/i) {
     105    $email_events = "";
    87106}
    88107
     
    120139    print STDERR "                           archives.org\n";
    121140    print STDERR "   -out                    Filename or handle to print output status to.\n";
    122     print STDERR "                           The default is STDERR\n\n";
     141    print STDERR "                           The default is STDERR\n";
     142    print STDERR "   -log_events             Log important events (collection built successfully etc.)\n";
     143    print STDERR "                           to event_log_file\n";
     144    print STDERR "   -event_log_file file    File to append important events to (defaults to\n";
     145    print STDERR "                           " . &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "events.txt") . "\n";
     146    print STDERR "   -email_events addr      Comma separated list of email addresses to mail details\n";
     147    print STDERR "                           of important collection building events\n";
     148    print STDERR "   -mail_server server     The outgoing (SMTP) mail server to be used by email_events.\n";
     149    print STDERR "                           email_events will be disabled if mail_server isn't set\n";
     150    print STDERR "   -event_header file      File containing a header to go on any event messages. If not\n";
     151    print STDERR "                           specified build will create a generic header\n\n";
    123152}
    124153
     
    250279    } else {
    251280        # no import or archives
    252         print $out "build: ERROR: The $collection collection has no import or archives data.\n";
     281        my $msg = "build: ERROR: The $collection collection has no import or archives data.\n";
     282        print $out $msg;
     283        &log_event ($msg);
    253284        &final_out (1) if $use_out;
    254285        die "\n";
     
    265296        my $olddir = &util::filename_cat ($collectdir, $collection);
    266297        if (-d $newdir) {
    267         print $out "build: Could not install collection as $newdir\n";
    268         print $out "       already exists. Collection will remain at\n";
    269         print $out "       $olddir\n";
     298        my $msg = "build: Could not install collection as $newdir\n" .
     299            "       already exists. Collection will remain at\n$olddir\n";
     300
     301        print $out $msg;
     302        &log_event ($msg);
    270303        &final_out (4) if $use_out;
    271304        die "\n";
    272305        }
    273306        if (!&File::Copy::move ($olddir, $newdir)) {
    274         print $out "build: Failed to install collection to $newdir\n";
    275         print $out "       Collection will remain at $olddir\n";
     307        my $msg = "build: Failed to install collection to $newdir\n" .
     308            "       Collection will remain at $olddir\n";
     309        print $out $msg;
     310        &log_event ($msg);
    276311        &final_out (5) if $use_out;
    277312        die "\n";
     
    280315    }
    281316
     317    &log_event ("The $collection collection was built successfully\n");
    282318    &final_out (0) if $use_out;
    283319}
     
    303339    }
    304340    } else {
     341    my $msg = "build: ERROR: import.pl failed\n";
     342    print $out "\n$msg";
     343    &log_event ($msg);
    305344    &final_out (2) if $use_out;
    306     print $out "\nimport.pl failed\n";
    307345    die "\n";
    308346    }
     
    329367    }
    330368    } else {
     369    my $msg = "build: ERROR: buildcol.pl failed\n";
     370    print $out "\n$msg";
     371    &log_event ($msg);
    331372    &final_out (3) if $use_out;
    332     print $out "\nbuildcol.pl failed\n";
    333373    die "\n";
    334374    }
     
    387427    }
    388428}
     429
     430sub log_event {
     431    my ($msg) = @_;
     432
     433    return unless ($log_events || $email_events);
     434
     435    # get the event header
     436    my $eheader = "";
     437    if ($event_header ne "" && open (HEADER, $event_header)) {
     438    undef $/;
     439    $eheader = HEADER;
     440    $/ = "\n";
     441    close HEADER;
     442    } else {
     443    $eheader = "[Build Event]\n";
     444    $eheader .= "Date: " . scalar localtime() . "\n";
     445    $eheader .= "Collection: $collection\n";
     446    }
     447   
     448    if ($log_events) {
     449    my $fail = 0;
     450    # append the event to the event log file
     451    if ($event_log_file eq "" || !open (LOG, ">>$event_log_file")) {
     452        # log file defaults to $GSDLHOME/etc/events.txt
     453        $event_log_file = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "events.txt");
     454        if (!open (LOG, ">>$event_log_file")) {
     455        print $out "build: ERROR: Couldn't open event log file $event_log_file\n";
     456        $fail = 1;
     457        }
     458    }
     459    if (!$fail) {
     460        print LOG $eheader;
     461        print LOG $msg;
     462        close LOG;
     463    }
     464    }
     465   
     466    if ($email_events) {
     467    # if mail_server isn't set email_events does nothing
     468    if ($mail_server eq "") {
     469        print $out "build: WARNING: mail_server was not set - email_events option was ignored\n";
     470        return;
     471    }
     472   
     473    my %mail = ('SMTP' => $mail_server,
     474            'To' => $email_events,
     475            'From' => $maintainer,
     476            'Subject' => 'Greenstone Build Event'
     477            );
     478    $mail{'Message'} = $eheader . $msg;
     479   
     480    if (!sendmail %mail) {
     481        print $out "build: ERROR sending mail to $email_events\n";
     482        print $out "'$Mail::Sendmail::error'\n";
     483    }
     484    }
     485}
     486
    389487
    390488sub parse_args {
     
    402500             'dontinstall', \$dontinstall,
    403501             'save_archives', \$save_archives,
    404              'out/.*/STDERR', \$out)) {
     502             'out/.*/STDERR', \$out,
     503             'log_events', \$log_events,
     504             'event_log_file/.*/', \$event_log_file,
     505             'email_events/.*/', \$email_events,
     506             'mail_server/.*/', \$mail_server,
     507             'event_header/.*/', \$event_header)) {
    405508   
    406509    &print_usage();
  • trunk/gsdl/src/recpt/receptionist.cpp

    r1305 r1762  
    5656  usecookies = false;
    5757  logcgiargs = false;
     58
     59  maintainer.clear();
     60  MailServer.clear();
     61  LogEvents = Disabled;
     62  EmailEvents = Disabled;
     63  EmailUserEvents = false;
    5864
    5965  // these default page parameters can always be overriden
     
    206212    else if (key == "usecookies") configinfo.usecookies = (cfgline[0] == "true");
    207213    else if (key == "logcgiargs") configinfo.logcgiargs = (cfgline[0] == "true");
     214    else if (key == "maintainer") configinfo.maintainer = cfgline[0];
     215    else if (key == "MailServer") configinfo.MailServer = cfgline[0];
     216    else if (key == "LogEvents") {
     217      if (cfgline[0] == "CollectorEvents") configinfo.LogEvents = CollectorEvents;
     218      else if (cfgline[0] == "AllEvents") configinfo.LogEvents = AllEvents;
     219    }
     220    else if (key == "EmailEvents") {
     221      if (cfgline[0] == "CollectorEvents") configinfo.EmailEvents = CollectorEvents;
     222      else if (cfgline[0] == "AllEvents") configinfo.EmailEvents = AllEvents;
     223    }
     224    else if (key == "EmailUserEvents") configinfo.EmailUserEvents = (cfgline[0] == "true");
    208225    else if (key == "pageparam") {
    209226      if (cfgline.size() >= 2) configinfo.pageparams[cfgline[0]] = cfgline[1];
     
    399416  }
    400417
     418  // if maintainer email address is something dodgy (for now I'll define
     419  // dodgy as being anything that doesn't contain '@') disable EmailEvents
     420  // and EmailUserEvents
     421  text_t::const_iterator maintainer_end = configinfo.maintainer.end ();
     422  text_t::const_iterator maintainer_here = findchar (configinfo.maintainer.begin(),
     423                             maintainer_end, '@');
     424  if (maintainer_here == maintainer_end) {
     425    configinfo.EmailEvents = Disabled;
     426    configinfo.EmailUserEvents = Disabled;
     427  } else {
     428    // if MailServer isn't set it should default to mail.maintainer-domain
     429    if (configinfo.MailServer.empty()) {
     430      configinfo.MailServer = "mail." + substr (maintainer_here, maintainer_end);
     431    }
     432  }
     433
    401434  // init the actions
    402435  actionptrmap::iterator actionhere = actions.begin ();
  • trunk/gsdl/src/recpt/receptionist.h

    r1285 r1762  
    6262typedef map<text_t, collectioninfo_t, lttext_t> colinfo_tmap;
    6363
     64enum events_t {Disabled, CollectorEvents, AllEvents};
    6465
    6566struct recptconf {
     
    7778  bool logcgiargs;  // true if we want to log cgi arguments
    7879
     80  text_t maintainer; // email address of maintainer
     81  text_t MailServer; // SMTP mail server to use when sending event messages by email
     82                     // defaults to mail.maintainer-domain
     83  events_t LogEvents;
     84  events_t EmailEvents;
     85  bool EmailUserEvents;
     86
    7987  text_tmap pageparams;
    8088  text_t macroprecedence;
Note: See TracChangeset for help on using the changeset viewer.