\chapter{Messages Resource} \label{blb:MessagesChapter} \index[general]{Resource!Messages} \index[general]{Messages Resource} The Messages resource defines how messages are to be handled and destinations to which they should be sent. Even though each daemon has a full message handler, within the File daemon and the Storage daemon, you will normally choose to send all the appropriate messages back to the Director. This permits all the messages associated with a single Job to be combined in the Director and sent as a single email message to the user, or logged together in a single file. Each message that \bacula{} generates (i.e. that each daemon generates) has an associated type such as INFO, WARNING, ERROR, FATAL, etc. Using the message resource, you can specify which message types you wish to see and where they should be sent. In addition, a message may be sent to multiple destinations. For example, you may want all error messages both logged as well as sent to you in an email. By defining multiple messages resources, you can have different message handling for each type of Job (e.g. Full backups versus Incremental backups). In general, messages are attached to a Job and are included in the Job report. There are some rare cases, where this is not possible, e.g. when no job is running, or if a communications error occurs between a daemon and the director. In those cases, the message may remain in the system, and should be flushed at the end of the next Job. However, since such messages are not attached to a Job, any that are mailed will be sent to \btool{/usr/lib/sendmail}. On some systems, such as FreeBSD, if your sendmail is in a different place, you may want to link it to the the above location. The records contained in a Messages resource consist of a \textbf{destination} specification followed by a list of \textbf{message-types} in the format: \begin{bdescription} \item [destination = message-type1, message-type2, message-type3, \ldots{} ] \index[dir]{destination} \end{bdescription} or for those destinations that need and address specification (e.g. email): \begin{bdescription} \item [destination = address = message-type1, message-type2, message-type3, \ldots{} ] \index[dir]{destination} Where \textbf{destination} is one of a predefined set of keywords that define where the message is to be sent (\textbf{stdout}, \textbf{file}, \ldots{}), \textbf{message-type} is one of a predefined set of keywords that define the type of message generated by \textbf{\bacula{}} (\textbf{ERROR}, \textbf{WARNING}, \textbf{FATAL}, \ldots{}), and \textbf{address} varies according to the \textbf{destination} keyword, but is typically an email address or a filename. \end{bdescription} The following are the list of the possible record definitions that can be used in a message resource. \begin{bdescription} \item [Messages] \index[dir]{Messages} Start of the Messages records. \bwebdoc{:Messages:Name} \item [Name = \bbracket{name}] \index[dir]{Name} The name of the Messages resource. The name you specify here will be used to tie this Messages resource to a Job and/or to the daemon. \bwebdoc{:Messages:MailCommand} \label{blb:mailcommand} \item [MailCommand = \bbracket{command}] \index[dir]{MailCommand} In the absence of this resource, \bacula{} will send all mail using the following command: \btool{mail -s "\bacula{} Message" \bbracket{recipients}} In many cases, depending on your machine, this command may not work. However, by using the \textbf{MailCommand}, you can specify exactly how to send the mail. During the processing of the \textbf{command} part, normally specified as a quoted string, the following substitutions will be used: \begin{bVerbatim} %% = % %b = Job Bytes %c = Client's name %C = If the job is a Cloned job (Only on director side) %d = Daemon's name (Such as host-dir or host-fd) %D = Director's name (Also valid on file daemon) %e = Job Exit Status %E = Non-fatal Job Errors %f = Job FileSet (Only on director side) %F = Job Files %h = Client address %i = JobId %I = Migration/Copy JobId (Only in Copy/Migrate Jobs) %j = Unique Job id %l = Job Level %n = Job name %o = Job Priority %p = Pool name (Only on director side) %P = Current PID process %r = Recipients %R = Read Bytes %s = Since time %S = Previous Job name (Only on file daemon side) %t = Job type (Backup, ...) %v = Volume name (Only on director side) %w = Storage name (Only on director side) %x = Spooling enabled? ("yes" or "no") \end{bVerbatim} Please note: any \textbf{MailCommand} directive must be specified in the \textbf{Messages} resource \textbf{before} the desired \textbf{Mail}, \textbf{MailOnSuccess}, or \textbf{MailOnError} directive. In fact, each of those directives may be preceded by a different \textbf{MailCommand}. The following is an example. Note, the whole command should appear on a single line in the configuration file rather than split as is done here for presentation: \textbf{mailcommand = "/opt/bacula/bin/bsmtp -h mail.example.com -f \textbackslash{}"\textbackslash{}(Bacula\textbackslash{}) \%r \textbackslash{}" -s \textbackslash{}"Bacula: \%t \%e of \%c \%l\textbackslash{}" \%r\textbackslash{}"} The \btool{bsmtp} program is provided as part of \textbf{\bacula{}}. For additional details, please see the \bxlink{bsmtp -- Customizing Your Email Messages}{blb:bsmtp}{utility}{section} of the \butilityman{}. Please test any \textbf{mailcommand} that you use to ensure that your bsmtp gateway accepts the addressing form that you use. Certain programs such as \btool{Exim} can be very selective as to what forms are permitted particularly in the from part. Be careful, most of the samples use \textbf{\%r} in the sender part of the \textbf{mailcommand}. This is a convenient way to setup the sender and the recipient at once. When you configure multiple recipients (separated by a comma) you must replace the \textbf{\%r} in the sender part with only one valid email address. \bwebdoc{:Messages:OperatorCommand} \item [OperatorCommand = \bbracket{command}] \index[fd]{OperatorCommand} This resource specification is similar to the \textbf{MailCommand} except that it is used for Operator messages. The substitutions performed for the \textbf{MailCommand} are also done for this command. Normally, you will set this command to the same value as specified for the \textbf{MailCommand}. The \textbf{OperatorCommand} directive must appear in the \textbf{Messages} resource before the \textbf{Operator} directive. \bwebdoc{:Messages:End} \item [\bbracket{destination} = \bbracket{message-type1}, \bbracket{message-type2}, \ldots{}] \index[fd]{\bbracket{destination}} Where \textbf{destination} may be one of the following: \begin{bdescription} \item [stdout] \index[fd]{stdout} Send the message to standard output. \item [stderr] \index[fd]{stderr} Send the message to standard error. \item [console] \index[console]{console} Send the message to the console (\bacula{} Console). These messages are held until the console program connects to the Director. \end{bdescription} \item \textbf{\bbracket{destination} = \bbracket{address} = \bbracket{message-type1}, \bbracket{message-type2}, \ldots{}} \index[console]{\bbracket{destination}} Where \textbf{address} depends on the \textbf{destination}. The \textbf{destination} may be one of the following: \begin{bdescription} \bwebdoc{:Messages:Director} \item [director] \index[dir]{director} \index[general]{director} Send the message to the Director whose name is given in the \textbf{address} field. Note, in the current implementation, the Director Name is ignored, and the message is sent to the Director that started the Job. \bwebdoc{:Messages:File} \item [file] \index[dir]{file} \index[general]{file} Send the message to the filename given in the \textbf{address} field. If the file already exists, it will be overwritten. \bwebdoc{:Messages:Append} \item [append] \index[dir]{append} \index[general]{append} Append the message to the filename given in the \textbf{address} field. If the file already exists, it will be appended to. If the file does not exist, it will be created. \bwebdoc{:Messages:Syslog} \item [syslog] \index[general]{syslog} Send the message to the system log (syslog) using the facility specified in the \textbf{address} field. Note, for the moment, the \textbf{address} field is ignored and the message is always sent to the LOG\_DAEMON facility with level LOG\_ERR. See \btool{man 3 syslog} for more details. Example: \begin{bVerbatim} syslog = all, !skipped \end{bVerbatim} Although the \textbf{syslog} destination is not used in the default \bacula{} config files, in certain cases where \bacula{} encounters errors in trying to deliver a message, as a last resort, it will send it to the system \textbf{syslog} to prevent loss of the message, so you might occassionally check the \textbf{syslog} for \bacula{} output (normally \bfilename{var/log/syslog}). \bwebdoc{:Messages:Mail} \item [mail] \index[general]{mail} Send the message to the email addresses that are given as a comma separated list in the \textbf{address} field. Mail messages are grouped together during a job and then sent as a single email message when the job terminates. The advantage of this destination is that you are notified about every Job that runs. However, if you backup five or ten machines every night, the volume of email messages can be important. Some users use filter programs such as \bfilename{procmail} to automatically file this email based on the Job termination code (see \textbf{mailcommand}). \bwebdoc{:Messages:MailOnError} \item [mail on error] \index[general]{mail on error} Send the message to the email addresses that are given as a comma separated list in the \textbf{address} field if the Job terminates with an error condition. MailOnError messages are grouped together during a job and then sent as a single email message when the job terminates. This destination differs from the \textbf{mail} destination in that if the Job terminates normally, the message is totally discarded (for this destination). If the Job terminates in error, it is emailed. By using other destinations such as \textbf{append} you can ensure that even if the Job terminates normally, the output information is saved. \bwebdoc{:Messages:MailOnSuccess} \item [mail on success] \index[general]{mail on success} Send the message to the email addresses that are given as a comma separated list in the \textbf{address} field if the Job terminates normally (no error condition). MailOnSuccess messages are grouped together during a job and then sent as a single email message when the job terminates. This destination differs from the \textbf{mail} destination in that if the Job terminates abnormally, the message is totally discarded (for this destination). If the Job terminates normally, it is emailed. \bwebdoc{:Messages:Operator} \item [operator] \index[general]{operator} Send the message to the email addresses that are specified as a comma separated list in the \textbf{address} field. This is similar to \textbf{mail} above, except that each message is sent as received. Thus there is one email per message. This is most useful for \textbf{mount} messages (see below). \bwebdoc{:Messages:Console} \item [console] \index[general]{console} Send the message to the \bacula{} console. \bwebdoc{:Messages:Catalog} \item [catalog] \index[general]{catalog} Send the message to the Catalog database. The message will be written to the table named \textbf{Log} and a timestamp field will also be added. This permits Job Reports and other messages to be recorded in the Catalog so that they can be accessed by reporting software. \bacula{} will prune the Log records associated with a Job when the Job records are pruned. Otherwise, \bacula{} never uses these records internally, so this destination is only used for special purpose programs (e.g. \textbf{Bweb}). \bwebdoc{:Messages:End} \item [stdout] \index[general]{stdout} Send the message to the standard output (normally not used). \item [stderr] \index[general]{stderr} Send the message to the standard error output (normally not used). \end{bdescription} For any destination, the \textbf{message-type} field is a comma separated list of the following types or classes of messages: \begin{bdescription} \item [events] \index[general]{events} Event messages. ex: Daemon startup/shutdown, Console login/logout, commands... This class of message is not included in the \texttt{all} message type. Specific events can be specified in the form \texttt{events.string}. Each destination directive can support up to 10 sub events. \item [info] \index[general]{info} General information messages. \item [warning] \index[general]{warning} Warning messages. Generally this is some unusual condition but not expected to be serious. \item [error] \index[general]{error} Non-fatal error messages. The job continues running. Any error message should be investigated as it means that something went wrong. \item [fatal] \index[general]{fatal} Fatal error messages. Fatal errors cause the job to terminate. \item [terminate] \index[general]{terminate} Message generated when the daemon shuts down. \item [notsaved] \index[fd]{notsaved} \index[general]{notsaved} Files not saved because of some error. Usually because the file cannot be accessed (i.e. it does not exist or is not mounted). \item [skipped] \index[fd]{skipped} \index[general]{skipped} Files that were skipped because of a user supplied option such as an incremental backup or a file that matches an exclusion pattern. This is not considered an error condition such as the files listed for the \textbf{notsaved} type because the configuration file explicitly requests these types of files to be skipped. For example, any unchanged file during an incremental backup, or any subdirectory if the no recursion option is specified. \item [mount] \index[dir]{mount} \index[general]{mount} Volume mount or intervention requests from the Storage daemon. These requests require a specific operator intervention for the job to continue. \item [restored] \index[fd]{restored} \index[general]{restored} The \textbf{ls} style listing generated for each file restored is sent to this message class. \item [saved] \index[fd]{saved} \index[general]{saved} The \textbf{ls} style listing generated for each file saved is sent to this message class. \item [all] \index[general]{all} All message types except debug, events and saved. \item [security] \index[general]{security} Security info/warning messages principally from unauthorized connection attempts. \item [alert] \index[general]{alert} Alert messages. These are messages generated by tape alerts. \item [volmgmt] \index[general]{volmgmt} Volume management messages. Currently there are no volume mangement messages generated. \end{bdescription} \end{bdescription} The following is an example of a valid Messages resource definition, where all messages except files explicitly skipped or daemon termination messages are sent by email to \bref{mailto:enforcement@sec.com}{enforcement@sec.com}. In addition all mount messages are sent to the operator (i.e. emailed to \bref{mailto:enforcement@sec.com}{enforcement@sec.com}). Finally all messages other than explicitly skipped files and files saved are sent to the console: \begin{bVerbatim} Messages { Name = Standard mail = enforcement@sec.com = all, !skipped, !terminate operator = enforcement@sec.com = mount console = all, !skipped, !saved catalog = all } \end{bVerbatim} With the exception of the email address (changed to avoid junk mail from robot's), an example Director's Messages resource is as follows. Note, the \textbf{mailcommand} and \textbf{operatorcommand} are on a single line -- they had to be split for this manual: \begin{bVerbatim} Messages { Name = Standard mailcommand = "bacula/bin/bsmtp -h mail.example.com \ -f \"\(Bacula\) %r\" -s \"Bacula: %t %e of %c %l\" %r" operatorcommand = "bacula/bin/bsmtp -h mail.example.com \ -f \"\(Bacula\) %r\" -s \"Bacula: Intervention needed \ for %j\" %r" MailOnError = security@example.com = all, !skipped, \ !terminate append = "bacula/working/log" = all, !skipped, !terminate operator = security@example.com = mount console = all, !skipped, !saved } \end{bVerbatim} \label{MessagesEvent} The following is an example of a valid Messages resource definition where Bacula will keep track of the user activity. It is often called ``Auditing''. \begin{bVerbatim} Messages { Name = Standard console = all, !skipped, !saved append = bacula/working/bacula.log = all catalog = all, events append = bacula/working/audit.log = events, !events.bweb } \end{bVerbatim}