Re: Is it possible to get mail notification on Warning

Bill Arlofski via Bacula-users <[email protected]>
Newsgroups gmane.comp.bacula.user
Message-ID <[email protected]>
On 4/1/25 6:58 AM, Mehrdad Ravanbod wrote:
> Hi Guys
> 
> I have managed to gt the mail notifications working on my Bacula
> installation, but I seem to have encountered a problem
> 
> I don't want to get a notification for successful jobs only on jobs that
> fail(get an error) and jobs that do complete but with warnings
> 
> The first one is easy, just using MailOnError keyword, BUT there is no
> keyword command for warnings and MailOnError does not generate an email
> for these jobs
> 
> has anyone managed to do this, i.e get a mail notification for jobs that
> do complete but with warning(with out turning on mail for all jobs)??
> 
> Regards /Mehrdad

Hello Mehrdad,

As you have discovered, there is no such setting/option/feature.

The reason for this is as follows:

In the catalog, a `jobstatus` of "W" was considered very early on in the development of Bacula, and, in some hard-coded 
queries where the goal is to select Good Jobs (Termination: Backup OK), o
r Good jobs with warnings (Termination: Backup OK -- 
with warnings), there is an "AND jobstatus IN ('T', 'W')" clause.

However, the "W" has never been implemented in any code that inserts or modifies the Job table's jobstatus field, so you will 
never find a "W" in this field for any job - unless you manually set it. :)

Here is the "status" table in the bacula catalog database where we can see that a jobstatus of "W: Terminated normally with 
warnings" exists:
----8<----
# sudo -u bacula psql bacula
psql (17.2)
Type "help" for help.

bacula=> select * from status;
jobstatus |           jobstatuslong           | severity
-----------+-----------------------------------+----------
C         | Created, not yet running          |       15
R         | Running                           |       15
B         | Blocked                           |       15
T         | Completed successfully            |       10
E         | Terminated with errors            |       25
e   
      | Non-fatal error                   |       20
f         | Fatal error                       |      100
D         | Verify found differences          |       15
A         | Canceled by user                  |       90
F         | Waiting for Client                |       15
S         | Waiting for Storage daemon        |       15
m         | Waiting for new media             |
M         | Waiting for media mount           |       15
s         | Waiting for storage resource      |       15
j         | Waiting for job resource          |       15
c         | Waiting for client resource       |       15
d         | Waiting on maximum jobs           |       15
t         | Waiting on start time             |       15
p         | Waiting on higher priority jobs   |       15
a         | SD despooling attributes          |       15
i         | Doing batch insert file records   |       15
I         | Incomplete Job                    |       25
l         | Doing data desp
ooling             |       15
L         | Committing data (last despool)    |       15
u         | Cloud upload                      |       15
w         | Cloud download                    |       15
q         | Queued waiting for device         |       15
W         | Terminated normally with warnings |       25     <------ Here
(28 rows)
----8<----

The way for you to accomplish what you are looking for would be with a small script that your `mailcommand` would call 
(instead of calling the bsmtp binary), and in that script is where you would make the decisions on when to send an email or 
not, and where to send it.

A quick idea would be to pass the script the jobid, and other things you would want to use on the email subject line of any 
emails that get sent, as well as the entire log text (which is passed automatically via stdin, I believe...)

Then, the simplest way to make the determination of who and when to send an email without any database queries is to do a 

simple string comparison on the Job's Summary line `Termination:   xxxxxx`

Doing something like this would then take all the responsibility about where and when to send emails away from Bacula, and 
put it in the script based on the decisions it makes.

This would then also remove the need for using `mailonerror` etc in your Messages resources...


Alternatively, if you do not need to send job logs with specific termination statuses to different places, and have someone 
read and deal with every email that Bacula sends, you might want to take a look at the "Bacula Backup Report" Python script 
that I wrote and have released to the open-source community for free.

It is quite customizable, and when run via cron each morning, it sends an HTML email summarizing all of your jobs in the past 
(default) 24 hours.

You can even have cron trigger it multiple times each morning, each time using different settings from the config file so 
that each morning you can have differe
nt reports, based on different criteria, sent to different people/teams. Your boss will 
be happy to always get email reports of all GOOD jobs. :)  But seriously, as a real example, you might have an "all jobs with 
errors or which failed" email report be sent to a team that would need to deal with these issues.

The latest version of the script (baculabackupreport.py) may be found on my Github account here: https://github.com/waa


Good luck,
Bill

-- 
Bill Arlofski
[email protected]

_______________________________________________
Bacula-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bacula-users
signature.asc (application/pgp-signature, 583 B)
-----BEGIN PGP SIGNATURE-----
Version: ProtonMail

wsCpBAEBCABdBYJn8gt9CZBIDTDab9XDQDUUAAAAAAAcABBzYWx0QG5vdGF0
aW9ucy5vcGVucGdwanMub3JnnoWxrV8k1H5wEJ0XYZxRYhYhBMuLnlBaSQiu
SUbb6UgNMNpv1cNAAABSmAf/UrmYRpxk8PEjY+XWQXlTe5QpJeSq4cB4jWZV
+zaKftRtHSRQZgk7yfUrPy7cleJf3/p0BTdZxiOWR2sv+XzZNn0JEI5eCk5k
2g8Xm1xah9jTp1Mahb8mS9wLraBNDMyaTMOsonkXHUIIXxFJ/C8voUqqxL1y
CPFAFf/688oCLTFy5rA9r8BCKUL89TG02iEicr+WGwFsB7k8mueAtNaPZ2wK
8FNdq29lsZnK0u2NjbrU8QCuMCG4px5nBWBfbTbbvzHq7i5UHWQEqzVcE5dH
/raRRffsJLZLCs4+1+8QDYloxaNGG7wScpPIxIuK8GOj+iTcI7LtzOdH4T9a
d2EW8A==
=/6o8
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.