JetBackup version 4+ introduced a fancy new alerts system in which you can easily get an overview of your notifications in one central place.
There are 3 types of alerts : Information, Warning & Critical . You can also get email notifications based on these alerts, setting this will be done through the Settings -> Notification page.
By default ‘Warning’ & ‘Critical’ alerts will send emails.
Unacknowledged alerts will continue to send emails until you acknowledge them from the GUI [ Emails are sent once on the daily cron. ]
Using a JetBackup hook to auto acknowledge alerts
Using A JetBackup hook, you can automate the procedure of acknowledging the alerts.
STEP 1 – Create bash hook file
Edit the hook file –
vi /root/acknowledgeAlerts
Paste the following code –
#!/bin/sh for x in $(jetapi backup -F listAlerts | grep "_id" | awk '{print $2}'); do jetapi backup -F acknowledgeAlerts -D '_id[]='$x; done;
Give executable permissions –
chmod +x /root/acknowledgeAlerts
You can execute your hook to test if it’s working –
[root@cpanel01 ~]# /root/acknowledgeAlerts success: 1 message: Alerts Acknowledged Successfully system: version: 3.1.20-1 tier: STABLE drMode: agreement: licenseIssue: data: success: 1 message: Alerts Acknowledged Successfully system: version: 3.1.20-1 tier: STABLE drMode: agreement: licenseIssue: data: success: 1 message: Alerts Acknowledged Successfully
Empty response means no alerts to acknowledge.
STEP 2 – Apply your hook inside JetBackup
Navigate to “Hooks” & Click on “Create new hook” button.
Name your hook, paste your script location under “Hook script” and choose “Daily cron” from the type. As for the position, it could run PRE or POST the daily cron.
Running the hook at PRE daily cron – Will acknowledge the alerts and prevent the daily cron from sending email alerts (as they are already acknowledged once the cron reached there, so nothing to do).
Running the hook POST daily cron – Will acknowledge the alerts after daily cron already sent email alerts about them. There will no more emails about this alert anymore (as they are acknowledged).
We recommend using the POST position, as we want to receive at least one email notification about this alert.
ADVANCED USAGE – ACKNOWLEDGING SPECIFIC ALERTS
We can use some “bash magic” to acknowledge specific alerts. Let’s use the “No Disaster Recovery destination was set” alert as an example.
First, let’s show the alert from our bash using JETAPI –
[root@cpanel-dev-qa ~]# jetapi backup -F listAlerts success: 1 message: system: version: 4.0.6 tier: EDGE drMode: agreement: licenseIssue: data: alerts: 0: _id: 5beca8f23d278dc906648e53 title: No Disaster Recovery destination was set message: Please go to the destinations page and click on the "Shield" icon near the destination you want set as Disaster Recovery destination created: 2018-11-14T23:00:02+00:00 acknowledge: type: warning level: 64 total: 1
We can use the same script as before, only that we will “grep” the specific alert(s) we want to ‘catch’, get their ID and auto acknowledge them.
Catching the ID –
[root@cpanel-dev-qa ~]# jetapi backup -F listAlerts | grep 'No Disaster Recovery destination' -B 1 | grep '_id' | awk {'print $2'} 5beca8f23d278dc906648e53
Creating a loop –
for x in $(jetapi backup -F listAlerts | grep 'No Disaster Recovery destination' -B 1 | grep '_id' | awk {'print $2'}); do jetapi backup -F acknowledgeAlerts -D '_id[]='$x; done;
Testing from command line –
[root@cpanel-dev-qa ~]# for x in $(jetapi backup -F listAlerts | grep 'No Disaster Recovery destination' -B 1 | grep '_id' | awk {'print $2'}); do jetapi backup -F acknowledgeAlerts -D '_id[]='$x; done; success: 1 message: Alerts Acknowledged Successfully system: version: 4.0.6 tier: EDGE drMode: agreement: licenseIssue: data:
To also automate this procedure, go through steps 1 & 2 as before and use the loop code above instead.
“Where there is a bash, there is a way…” 🙂
Thanks, very helpful..