#!/bin/env ruby # # (C)2007 Henri Shustak # Lucid Information Systems # http://www.lucidsystems.org # Licensed under the GNU GPLv3 or later # # # Performs checks on each of the printers on the local system. # # # This script is a component of PrintingWorks. # Detailed information regarding PrintingWorks # is availible from the offical website : # http://www.lucidsystems.org/printingworks # # Tested with the following operating systems # Mac OS 10.4.11 & 10.5.2 Admin Station to Be Notified # Debian 3.1 Print Server # # Version 1.0 # REQUIRMENTS # RubyGrowl # CUPs # Ruby ################################## # Varibles ################################## # How many jobs will a queue be able to build up to before we report an issue $max_number_jobs_on_queue_before_error=7 # Which addresses on the Network will we be notified of the problem $report_to_hosts=["10.57.128.29","10.57.129.28"] ################################## # Functions ################################## # Returns the number of jobs currenlty active on a printer def number_of_jobs(printer) command = %x{ lpstat -o #{printer} | wc -l | awk '{print $1}'} return command.to_i end # Growls back that the number of jobs which are currenlty queued for this printer. def report_max_number_of_jobs_exceeded(printer) reporting_from=`hostname` $report_to_hosts.each{ |host| #puts host # Report Using Growl %x{ echo -e "Queue Name : #{printer}\nQueued Jobs : #{number_of_jobs(printer)}" | growl -H #{host} --priority 2 -sticky true -t "#{reporting_from}" } #%x{ echo -e "Queue Name : #{printer}\nQueued Jobs : #{number_of_jobs(printer)}" | growl -H #{host} --priority 2 -t "#{reporting_from}" } } end # Checks all the printers for various problems def check_the_printers() # Build the local printer list printer_list=`lpstat -p | grep -e "^printer" | awk '{print $2}' | grep -v "@"` # Open File For Writing fout = File.open("/tmp/num_printer_jobs.txt", "w") # Checks the printers printer_list.each { |p| # Remove the new line characters from the printer name printer=p.gsub(/\n/, "") #puts "#{printer} #{number_of_jobs(printer)}" fout.puts "#{printer} #{number_of_jobs(printer)}" if (number_of_jobs(printer)) >= $max_number_jobs_on_queue_before_error # This printer is exceeding the maximum number of jobs report_max_number_of_jobs_exceeded(printer) end } fout.close end ################################## # Logic ################################## check_the_printers()