Linux cups notifications

I had problems with some printers, sometimes, the print server just stops the queue and I only know when the user complains he can’t print ! This can cause several problems and so, I need to know when a printer stops. CUPS can warning you about that so you can do something about it.

Cups is able to send email notifications when some event occurs .

I’m using CUPS 1.3.7 with CentOS 5.10 x86


For configuring cups notifications, we need two files: mailto.conf and subscriptions.conf . Both should be available in /etc/cups . If not, we need to create them.  First, let’s create mailto.conf so cups know where to send the notifications.

mailto.conf

From the manual for mailto.conf (man mailto.conf) :

Here, will configure the mail server (SMTPServer directive or Sendmail directive), From, subject and so on..

Fire up your favorite editor (mine’s VIM) and edit the file (creating it if it does not exists):

Save and quit

NOTE: We haven’t configured a recipient – that’s configured within the subscriptions.conf file. Nevertheless, we can configure a CC recipient (with the Cc <email> directive) – all the notifications will also be mailed to this recipient

NOTE2: I haven’t managed to get it to work with SMTPServer – it just wont send email – it connects to my mail server – Zimbra – but i don’t get any email . The Sendmail directive works fine though !

Now, let’s configure the subscriptions

subscriptions.conf

Again, fire up your favorite editor

Add the following lines (bare minimum options for sending emails when a printer stops)

Those lines above are the minimum for a working configuration.

The syntax of the subscription directive is:

Explanation:

  • NNN – The subscription ID (from 1 to ….)
  • Events – the occurred events that we will make cups to notify us
  • Owner – The owner of this subscription
  • Recipient – Who will be notified. In this case, by email
  • LeaseDuration – The number of seconds this subscription is valid. 0 value is forever
  • Interval – The time interval for notifications in seconds.
  • ExpirationTime – The expiration time of the subscription as a UNIX value (epoch time). 0 value is “never expire”

You can add more directives. For example, if you omit the PrinterName directive, the subscription is valid for all printer queues.

There are many events you can be monitoring, such as job-completed, job-stopped, printer-added, etc… You can check them all in here.

And here’s an example of an email sent by CUPS:

Cups Notification
Cups Notification

Remember, man subscriptions.conf and man mailto.conf are your friends.

Happy printing !

Note: This is only for notifications. If you wan’t to do something about it, like restart the print queue automatically, you need some scripting.  In this site, there’s a solution (by René Pfeiffer) you can implement that will check periodically (added to cron or some similar program or fashion) for stopped print queues and restart them .

NOTE: Taking into account part of the code, i’ve created a script that will check for stopped printers, enabled them and send an email (only if any was stopped) with the list of printers enabled

Now, add it to cron and run it from time to time – mine is running every 30m

There could be some delay (at least 30m) from when you get a notification from cups that the printer is stopped and until it gets restarted by the script

Some references

https://www.cups.org/documentation.php/doc-1.7/ref-mailto-conf.html?VERSION=1.7&Q=

http://www.cups.org/documentation.php/doc-1.7/ref-subscriptions-conf.html?VERSION=1.7&Q=

http://permalink.gmane.org/gmane.comp.printing.cups.general/20375

http://linuxgazette.net/147/misc/lg/2_cent_tip__automatically_reenabling_cups_printer_queues.html

Leave a Reply

Your email address will not be published. Required fields are marked *