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

To configure 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 knows where to send the notifications.

MAILTO.CONF

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

The mailto.conf file defines the local mail server and email notification preferences for CUPS.

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):

vi /etc/cups/mailto.conf


#From - If you have ServerAdmin defined in cupsd.conf you can omit this one
From CUPS Server <printserver@domain.conf>
# subject for the email
Subject CUPS notification
# Email server - If you don't have one, you can define Sendmail <path>
SMTPServer mail.domain.com

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

vi /etc/cups/subscriptions.conf

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

<Subscription 1>
Events printer-stopped
Owner cups
Recipient mailto:user@domain.com
LeaseDuration 0
Interval 0
ExpirationTime 0
</Subscription>

Those lines above are the minimum for a working configuration.

The syntax of the subscription directive is:

<Subscription NNN>
  …
  Events job-completed
</Subscription>

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:

#!/bin/bash
# Script to check for disable printers and enable them if configured
# Bruno Santos - bvsantos@ulscb.min-saude.pt
# 2014-07-16
#
#----- email stuff ------
#
#---- Person to get the email -----
email_rcpt=<recipient of the email>

# If send email, check this
send_mail=1

# send mail command - change for your system
sendmail_cmd=`whereis -b mail | awk '{ print $2 }'`

#---- cups enable command ----
# whereis cupsenable
enable_cmd=`whereis -b cupsenable | awk '{ print $2 }'`

#---- NO NEED TO CHANGE BELOW THIS POINT
LOG=/tmp/logprn.log
control=0

#Check for disabled printers - returns the printer name
DISABLE=`lpstat -t | grep -i disabled | awk '{ print $2 }'`

# Log file
echo "List of enabled printers" >> $LOG
echo "" >> $LOG
#In the array, check for the printers name
for PRINT in $DISABLE; do
#we have at least a printer disable
control=1
#Enable the printer
$enable_cmd $PRINT
echo "printer $PRINT has been enabled" >> $LOG
done;

# Only send email if control is not equal 1
if [ $control != 0 ];then
if [ $send_mail -eq 1 ]; then
$sendmail_cmd $email_rcpt -s "Priner Enabled" < $LOG
fi
fi

#remove log
rm $LOG

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