In this final article on how to monitor Bacula from Zabbix, we’ll look at how to configure a template with items and triggers. We’ll create a new template that will contain the items we’ll monitor. Then we’ll add the items, such as files written, rate, job successfully completed etc. Finally, we’ll add a trigger, so we are alerted in case a job fails to complete.
You can grab the template on GitHub, and import it into your Zabbix server without having to manually go through the steps below. Note that you’ll require Zabbix version 4.2 or later to import the template.
Creating a Zabbix Template
In this section, we’ll look at how to create the Bacula template.
First log in to the Zabbix server. At the Dashboard screen, move to Configuration, and select Templates. Then click on Create template.
For Template Name, write Bacula, or if you want, a different name. Then, if you want, you can specify the name you want Zabbix to show instead of the Template name by entering a name in the Visible Name field.
In Groups, click select and then check Templates/Application and confirm the selection by hitting select again in the popup box.
Finally, you can add a description of the template.
Click Add and the template will be created. Back at the Templates page, you can search for your template by entering Bacula in the name field and clicking Apply.
Adding Bacula items
In the Templates page, click on the Bacula Template and then on Items link.
In the Items menu, click create item on the top right corner.
Now we need to configure the details for this item. In this case, we’ll configure the job_id.
For the name, write Bacula Job Id.
The type tells Zabbix how this data is supposed to be retrieved. The default way is Zabbix agent. If selected, the Zabbix server will poll the zabbix agent on the host machine for the information at regular intervals. Since we are sending the information to the Zabbix server, we need to set that value to Zabbix trapper.
Each value has a corresponding key so that Zabbix knows which item to associate the value with. In the Python script we configured the keys to start with bacula followed by the name of the item. We need to set the key value equal to the value in the Python script. For job id, that would be bacula.job_id.
Finally, since the job id is an unsigned number, we do not need to make any changes in the Type of information drop down box.
Make sure that the enabled flag is selected and then click the Add link.
Now we just need to create the remaining 29 items. I’ve listed the items name, key and type of information below.
Accurate bacula.accurate Numeric(unsigned) Backup Level bacula.backup_level Text Catalog bacula.catalog Text CL Compression bacula.cl_compression Numeric(float) Elapsed Time bacula.elapsed_time Numeric(unsigned) Encryption bacula.encryption Numeric(unsigned) End Time bacula.end_time Text FD Bytes Written bacula.fd_bytes_written Numeric(unsigned) FD Erros bacula.fd_errors Numeric(unsigned) FD Files Written bacula.fd_files_written Numeric(unsigned) FD Termination bacula.fd_term Numeric(unsigned) FileSet bacula.file_set Text Job Id bacula.job_id Numeric(unsigned) Job Name bacula.job Text LV Bytes bacula.lvbytes Numeric(unsigned) Pool bacula.pool Text Priority bacula.priority Numeric(unsigned) Rate bacula.rate Numeric(float) Scheduled Time bacula.scheduled_time Text SD Bytes Written bacula.sd_bytes_written Numeric(unsigned) SD Errors bacula.sd_errors Numeric(unsigned) SD Files Written bacula.sd_files_written Numeric(unsigned) SD Terminiation bacula.sd_term Numeric(unsigned) Snapshot bacula.snapshot Numeric(unsigned) Start Time bacula.start_time Text Storage bacula.storage Text SW Compression bacula.sw_compression Numeric(float) Termination bacula.termination Numeric(unsigned) Volume Name bacula.volume_name Text Volume Session ID bacula.volume_session_id Numeric(unsigned) Volume Session Time bacula.volume_session_time Text
Pre-processing incoming data
The Python script may send back a value that indicates that something went wrong parsing the data. Therefore we need to add a preprocessing step on a couple of the items.
If we encounter that value, we need to make sure that we can store it correctly. Additionally, if we need to, we can set up triggers that would not just mark the item value as failed, it would also alert us to the fact that the parsing failed. Though triggers are discussed in the next section, I won’t go into detail on how to setup trigger specifically for parsing failure.
In this case, we’ll add preprocessing for CL, SW Compression and FD, SD Termination items. The two compression values are OS dependent. So if the OS is Linux, CL will have a value and SW would not have a value. If the OS is Windows, SW would have a value and CL would not have a value. The value that is sent is not a numeric value, rather is the text None.
For each of the Compression items, navigating to the Preprocessing tab.
Then, click on Add to generate a new preprocessing step.
if (value == 'None') return 0 else return value
Then click Apply.
If you want to, you can also test that the script is returning the correct value by clicking on the Test link.
If you enter None as a value, seen in the screenshot above, and then click on Test, the result should be 0. Press Cancel, to return back to the Preprocessing screen.
Finally, click update to activate the preprocessing step.
Adding Regular Expression check to SD and FD Termination item.
Navigate to the preporcessing tab inside the SD Termination item.
Click on Add
It should default to Regular expression, but if it doesn’t, select Regular expression from the drop down menu.
Set Parameters to ^1$ and in the next textfield set the value to 1 as shown below.
Check the Custom on fail checkbox on the right and click on Set value to and enter 0 in the textfield.
Any value that is not 1 will return 0, include None and 0.
You can verify that the expression works by clicking on the Test link and testing with different values.
Once done, click Update and repeat the steps for FD Termination.
Configuring job specific triggers
We can add triggers so we are alerted if a value does not match a condition. For example, assume the value of termination returns 0, meaning that the job failed. We can create a trigger that says, if the value of termination is 0, create an alert. Though this is a very simplistic example, Zabbix has the ability to create powerful conditionals, though this is outside the scope of this article.
Inside the Bacula template, click on Triggers.
In name enter Backup Failed.
Select Severity High.
Next to Problem expression click Add.
Inside the popup box select Termination by clicking on Select next to the Item box.
Select last() – Last (most recent) T value in the Function drop down.
In Result set the = value to 0.
Finally, click Insert to save the condition.
Next, we need to specify the recovery expression. Click on Add next to Recovery expression. Enter the same values as above, however this time, set Result equal to 1. Create the Condition by clicking Insert.
This step ensures that if a job fails, then to remove the alert, we need to successfully complete a backup job for that host.
Finally, make sure that the Enabled flag is selected and then click Add.
At the Triggers screen, you should now have a trigger called Backup Failed.
Adding value mappings
Before looking at the end result, I wanted to bring up the ability to add value mapping. Some of the values that are being sent to Zabbix may contain single digits to represent Boolean values for example. Rather than reading 0 or 1, it would be helpful to read Success or Failure.
So, we’ll go ahead and add a Success/Failure value mapping to the Termination value so that we can easily read it from the Zabbix dashboard.
Navigate to Administration and General and then select Value Mapping from the drop drown menu on the right hand side.
Then click on Create value map.
Enter the name Bacula Termination Status.
In Mappings, enter 0 in the Value field, then Failure in the Mapped to field. Click on Add to add the next field.
Now in the new field, enter 1 in the Value field, then Success in the Mapped to field.
Finally, click the Add button.
Now, we can go back to our Bacula template and tell Zabbix to use this map when displaying the termination values.
Navigate to Configuration, Templates and then click on the Bacula template.
Click on Items and then click on Termination.
Locate the show value Show value field and click on the drop down box.
Select the Bacula Termination Status value.
After selecting the Bacula Termination Status, the Item will now list Show Value as Bacula Termination Status.
Finally, click on Update to confirm the changes.
Adding Bacula Template to Hosts
Last part is now to add the Bacula template to any hosts that are being backed up using Bacula. This can be done by navigating to Confiugration, then Hosts and finally editing the host you want the Bacula template associated with.
Navigate to the Templates section, and click on the Select button.
Find and select the Bacula template.
Click on the Add button at the bottom of the Link new templates section.
Finally, confirm the addition of the Bacula template by clicking on the Update button.
The host will now be able to receive information regarding the backup status of the job.
The Python script uses the client name from the Bacula Director when it sends the data to the Zabbix server. Therefore, the host name in Zabbix must match the client name in the Bacula Director configuration file.
The only remaining piece is to configure your Zabbix Dashboard to display the values from the Bacula template. I hope you found this series useful, any thoughts or comments, please let me know in the comment section or drop me an email.