Linux cups notifications

Posted on Updated on

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

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:

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

#!/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

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

crontab -e
# check stopped printers
0,30 * * * * /path/to/script/ > /dev/null 2>&1

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

Linux screenFetch

Posted on

screenFetch

screenFetch is a small, but awesome utility that displays the logo of your distro in ASCII ART – with colors, as well some information about your environment. It supports a lot of Linux distributions and there respective logos, most main stream Desktop Managers and a lot of window managers. screenFetch can (and is it’s main purpose) take screenshots with the info on screen ! I think is just awesome and I love ASCII ART !

You can see what options it can take with screenFetch -h

 

 

Arduino e LEGO® Power Functions

Posted on

Originally posted on GroundZero Blog:

No dia 10 de junho participei num workshop sobre eletrônica e informática com um projecto baseado em LEGO® Power Functions e Arduino.

Basicamente o projecto envolvia um comboio LEGO® cujo movimento era controlado pelo Arduino. Os objectivos do projecto eram:

  • O comboio tinha de parar na estação sempre que lá passava.
  • Quando arrancava da estação tinha de se ouvir um apito
  • Logo que saisse da estação, o comboio tinha de ser transferido para a linha interior
  • Quando efetuasse 2 voltas na linha interior era novamente transferido para a linha exterior
Layout Final
Layout Final

Para elaborar o projecto, para além do LEGO®, foi usado:

  • 1 arduino
  • 1 buzzer
  • 2 sensores de obstáculos
  • 1 servo
  • 2 leds IR
Arduino and buzzer
Arduino and buzzer
Servo
Servo
Sensor de obstaculos
Sensor de obstáculos
Led's IR
Led’s IR

Para controlar o comboio na estação foi necessário usar dois led´s devido ao alcance e ângulo destes. Um controla a entrada da estação e o outro…

View original 295 more words

Arduino SG90 Micro Servo

Posted on Updated on

Servo ComponentsStep Motor

I’ve just received my Bluetooth Controlled Robot Car Kit and it has a micro servo that needs testing (and I’ve never worked with one before).

Read the rest of this entry »

L298 Dual H-Bridge Motor driver

Posted on Updated on

l298

The Funduino Tracking Maze also comes with a L298 Dual H-Bridge Motor driver to control the two wheels of the robot.  It’s designed to drive inductive loads, such as relays, solenoids, DC and stepping motors. It can also let us drive two independent DC motors, controlling the speed and direction of each one .
Read the rest of this entry »

Keyes IR Remote Sensor

Posted on Updated on

Keyes IR SensorIR remote

My Bluetooth Remote Control Robot kit also comes with a Keyes Infrared remote sensor and a command .
Read the rest of this entry »

Keyes IR obstacle avoidance sensor

Posted on Updated on

IRObstacleAvoidance1

The Funduino Tracking Maze Robot also comes with 3 IR Obstacle Avoidance Sensors. I couldn’t find any information about it, but i found information about similar ones and give it a try.
Read the rest of this entry »

IR Line tracking sensor

Posted on Updated on

irtracking

The Maze tracking robot also comes with 3 IR  Line Tracking Sensors.  These sensors just follows lines, or the light reflected on a surface. In the picture above are 3 of those.

Read the rest of this entry »

Arduino YL-30 SD Card

Posted on Updated on

I’ve bought two Arduino SD Cards modules from DX.com and didn’t found any info for them – So I decided to try by my self.

Reading a bit about Arduino SD cards i found out that Arduino SD card uses SPI (Serial Peripheral Interface) to communicate with the SD Cards and with Arduino UNO (along with others – except Mega) those PINs are 11, 12 and 13.
Read the rest of this entry »

Arduino Sensor Shield v4.0

Posted on Updated on

sensorShieldv4

The Funduino Tracking Maze Robot comes with a Sensor Shield v4.0. With all the bundled sensors, a shield is necessary to connect them all.
Read the rest of this entry »