Scheduling reports for e-mail delivery

Zenoss Core includes the reportmail command in $ZENHOME/bin that enables us to send any report, including custom device reports, via e-mail. No graphical interface is available which means that we must work from the command line as the zenoss user.

We need to specify the URL of the report, the username/password for a user, and a from address for the e-mail. Run the command reportmail --help to get a full list of options.

To get the URL of the report, open the report you want to mail from the Zenoss UI and copy the URL from the browser. Using the Uptime Report we created earlier in this chapter, I would use the command:

reportmail -U userName -p password 
-u http://localhost:8080/zport/dmd/reports#reporttree:.zport.dmd.Reports.Custom%20Device%20Reports.Uptime

As you can see, the URL is quite large and causes the above command to wrap over three lines. It's one of those things that doesn't transfer well to print. And even though it's ugly, it's relatively simple. We feed reportmail a username and password. Then we specify in the above command the URL to the report.

The report will be sent to the e-mail address associated with the user account. Use the -a option to change the recipient.

Sending a CSV report

The default report that gets sent from reportmail will be readable and will likely serve its purpose. However, you may want to e-mail the CSV version of the report instead. To get the CSV version of any report, append ?doExport to the report URL.

Scheduling a cron job

If we want to e-mail the report out on a recurring basis, we can schedule it as a cron job. We talked about setting up cron jobs in the Automating backups with zenbackup section of Chapter 8, Settings and Administration. To add the reportmail command, edit the crontab as the zenoss user with the command:

crontab -e

The following screenshot shows my updated crontab:

Scheduling a cron job

Not all of the reportmail command is shown in the screenshot because it's too long.

Just be aware that reportmail requires you to specify the username/password for a Zenoss Core account. If you do report mail in a script, change the ownership on the script so only the zenoss user can read it. You might also want to set up a less privileged account in Zenoss Core account with a role of ZenUser for use with reportmail.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.7.224