So I thought I better add support for adding multiple email addresses.
Each email address that gets imported needs an updated index number to go into the Z_PK column. So the script will now import multiple email addresses and assign a Z_PK index number for each email address.
The script now will read in a CSV file instead of taking stdin for input. You will need to specify the location of the CSV file in the script, or modify as needed.
So after a bit of further testing, it appears that the
alertData.db does not get created automatically at installation of Server.app and requires the Alert tab be selected in Server.app for the db to be created. This presented a problem for me as I am automating the deployment of these macOS server machines and I want to include the alert email settings with zero touch. So some more digging around with the
alertData.db and I was able to find the tables and values needed to create a bare database that enables the caching service to be enabled for alerts. The updated script now will create the
alertData.db if it does not exist, enable email alerts for caching server (no other services are enabled) and then sets the notification recipients email address.
If you wish to enable notifications for extra services such as Mail, you should add a ‘1’ to the
ZPUSHENABLED columns for the relevant service in the script where it inserts these values to the relevant column.
(ZADALERTBUNDLE) contains the following column names and types:
(Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZENABLED INTEGER, ZMAILENABLED INTEGER, ZPUSHENABLED INTEGER, ZBUNDLE VARCHAR, ZNAME VARCHAR)
The columns we are interested in are
ZPUSHENABLED. These columns will accept a data type of:
INTEGER. In actual fact, this is really a boolean with either a 0 (False) or a 1 (True) value assigned.
Here is an example of what having the caching service enabled for mail and push notifications looks like in our
You can also see that the Mail service has mail and push notifications disabled
Z_PK Z_ENT Z_OPT ZENABLED ZMAILENABLED ZPUSHENABLED ZBUNDLE ZNAME ---------- ---------- ---------- ---------- ------------ ------------ ----------------- ----------- 2 2 2 1 1 1 Caching Caching 5 2 2 1 0 0 Mail Mail
Note the two ‘0’s in the
ZPUSHENABLED columns mentioned earlier, setting these to 1 means the service will have push and email alerts enabled for it.
Now we know what controls the enabled/disabled checkboxes in the alerts section of server.app it is trivial to modify this directly in the alertsData.db.
Original post below:
In macOS Server it used to be possible to edit the alert settings with something like :
serveradmin settings info:notifications:certificateExpiration:who = email@example.com
Unfortunately it appears that it is no longer possible to add an email address to the alert settings via the command line.
This presented an issue for me as I automate the deployment of many macOS servers where we want to have an email address entered in the alert settings so that user receives notifications from their server.
After a little bit of digging the location where this information is now saved was found in
Specifically it is stored in a
ZADMAILRECIPIENT in a
So now we know that, all we have to do is work out a way of adding in our desired values to that table.
The quick and dirty of it is something like this:
sqlite /Library/Alerts/alertData.db "INSERT or REPLACE INTO ZADMAILRECIPIENT VALUES('2','4','1','1','firstname.lastname@example.org','en')"
But in my quest to force myself into using python, I wrote a quick python script that takes the email address as the first argument and then writes this into our db, which makes it easy to put into my deployment workflow.
To use it, simply run it like this:
You will need to edit the location of your csv file. Currently this is set in line number 96 of the script.
The script is as below.