Article 125802 of comp.os.vms:
Path: nntpd.lkg.dec.com!crl.dec.com!crl.dec.com!caen!spool.mu.edu!howland.reston.ans.net!gatech!europa.chnt.gtegsc.com!news.mathworks.com!uunet!in2.uu.net!boulder!tali.hsc.colorado.edu!buckie.ucha!cronus.colorado.edu!DGM
Newsgroups: comp.os.vms
Subject: Re: Need help with F$GETQUI
Message-ID: <1995Jul27.081105.2095@buckie.uhcolorado.edu>
From: dgm@cronus.colorado.edu (Dom Maddalone)
Date: 27 Jul 95 08:11:04 MST
Reply-To: dgm@cronus.colorado.edu
References: <01HT4L3Y61UA8WY01P@DBC.COM>
Organization: University Physicians, Inc., Denver, Colorado
Nntp-Posting-Host: 168.200.153.38
Lines: 286

In article <01HT4L3Y61UA8WY01P@DBC.COM>, Greg Bernard <GBERNARD@EF> writes:

>I need some help with the F$GETQUI lexical.  What I want to do is run a COM file
>that will cycle through all the queues on a system and tell me which ones are
>in an abnormal state.  (Abnormal meaning not IDLE or BUSY, but I am willing to
>settle for not IDLE.)  I do not want to hard code the name of the queues and
>just do a IF F$GETQUI (...) .EQS. "TRUE" because different systems here have
>different queues depending on if they are mail servers, production,
>development, etc...  

    Here is a command procedure used at my last place of employment.  It runs
as a detached process, checking on output queues (print,server, and terminal)
and reporting on stopped, stalled, or paused states.  All queues are reported 
except those listed in an exceptions file. 

    The usual disclaimers apply if used.

$! PRINTER_CHECK
$printer_check$version = "1.32"
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$!
$!	This daemon will watch for stalled printer queues when set up
$!	on a standard serial line.  When the printer stalls, a message will
$!	be sent to the operator every five minutes.  On subsequent stalled
$!	status on one queue, up to 5 messages will be sent.
$!	The daemon will check every five minutes.
$!
$!	
$!
$!	Procedure originally created from an example by Kent C. Brodie.
$!
$!						Dom Maddalone [DGM]
$!Code history:
$! Date:      Version:    Description:
$! 22-MAR-93   1.32  DGM  Modified F$FAO code to correct usage.
$! 27-DEC-92   1.31  DGM  Added code that would update the modification time
$!                        of the exception file at the startup of the procedure.
$! 23-DEC-92   1.3   DGM  Modified detached process was started.  Changed
$!                        format of request messages to look more like
$!                        the VMS format.  Changed exception queue name
$!                        extraction from SEARCH to READs.  Moved excpetion
$!                        file from sys$manager to uh_oper:.  Modified symbols
$!                        from 'queuename'cnt and 'stalled'cnt to
$!                        'queuename'_stalled.  These modofications allow a
$!                        more flexible execution.
$! 08-DEC-92   1.2   DGM  Updated for use by University Hospital.  Added check
$!                        for paused and stopped queues.  Renamed PRINTER_CHECK
$!                        from PRINTER_DAEMON.
$! 06-OCT-92   1.1   DGM  Made sure only five messages were sent to the OPA0:
$! 02-OCT-91   1.0   DGM  Original code completed.
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$!                       
$	status = 1       
$!
$	set symbol /verb /scope=NOglobal
$	on warning then goto _error
$	on control_y then goto _abort
$!
$	wait_increment = "00:05:00"	!Wait increment before checking queues.
$	max_request    = 5		!Max number of consecutive requests.
$	exception_file = "uh_oper:printer_check_exception.dat"
$!
$	if .not. f$privileges("TMPMBX,OPER,SYSPRV") then goto _no_privs
$!
$	if f$mode() .nes. "OTHER"
$	then
$	    write sys$output "Firing off Printer Check v''printer_check$version' . . . "
$	    procedure = f$environment("PROCEDURE")
$	    procedure = procedure - f$parse(procedure,,,"VERSION")
$	    output_file = procedure - f$parse(procedure,,,"TYPE") + ".LOG"
$	    error_file  = output_file !procedure - f$parse(procedure,,,"TYPE") + ".LOG"
$	    run 						-
		/detached 					-
		/error='error_file' 				-
		/input='procedure'                  		-
		/output='output_file' 				-
		/process_name="Printer Check" 			-
		/priority=3 					-
		/privileges=(NOsame, tmpmbx, oper, sysprv) 	-
		sys$system:loginout.exe
$	    goto _end
$	endif
$!
$	__new__     = 1
$	__checked__ = 0
$!
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$! At startup, modify the revision time of the execption file so that the
$! procedure will read it.
$! Using an open and immediate cloes of the file until a better 'touch' can
$! be found.
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$!
$	open/append/share exc_file 'exception_file'
$	close exc_file
$!
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$! Check exception file for modification date.
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$!
$_check_exception_file:
$!
$! Make sure an exception file exists.
$!
$	if f$search(exception_file) .eqs. "" then -
	    request/reply/to=(central,printer) -
	    "''f$fao("%PRINTER_CHECK-E-EXFILMIS, Printer Check Exception file is missing.!/<!AS>",exception_file)'"
$!
$! If exception file has been modified since the last time it was read, then
$! read it again, creating new ignore_queuename symbols.  These new exception
$! symbold will be give a value equal to __new__ to differentiate those
$! exception symbols that no longer are needed, which have a value equal to
$! __checked__.
$!
$	if f$cvtime(f$file_attributes(exception_file,"RDT"),"COMPARISON") -
	    .gts. f$cvtime("-''wait_increment'","COMPARISON")
$	then
$	    request/to=(central,printer) -
		"%PRINTER_CHECK-I-NEWEXC, Processing new exception file."
$	    open/read exc_file 'exception_file' /error=_error
$!
$_exc_read:
$	    read exc_file line /end_of_file=_exc_eof /error=_error
$	    line = f$edit(line,"COLLAPSE,TRIM,UNCOMMENT,UPCASE")
$	    if line .eqs. "" then goto _exc_read
$	    ignore_'line' = __new__
$	    goto _exc_read
$!
$_exc_eof:
$	    close exc_file
$!
$! Collect the queue names eliminating unneeded ignore_queuename symbols.
$!
$	    junk = f$getqui("CANCEL_OPERATION")
$!
$_compare_symbols:
$	    queuename = f$getqui("DISPLAY_QUEUE","QUEUE_NAME","*","SYMBIONT")
$	    if queuename .eqs. "" then goto _end_check_exception_file
$!	
$! See if the current queue should be excepted.  If the symbol ignore_queuename
$! is defined to __new__ then change that value to __checked__, else delete that
$! symbol.
$!	
$	    if f$search(exception_file).nes. ""
$	    then
$	    	if f$type(ignore_'queuename') .nes. ""
$	    	then
		   if ignore_'queuename' .eq. __new__
$		    then
$		    	ignore_'queuename' = __checked__
$		    else
$		    	delete/symbol/local ignore_'queuename'
$		    endif
$	    	endif
$	    endif
$	    goto _compare_symbols
$!
$_end_check_exception_file:
$	endif
$!
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$! Check each queue on the system for a STOPPED, STALLED, or PAUSED state.
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$!
$_start_check_queues:
$	wait 'wait_increment'
$	junk = f$getqui("CANCEL_OPERATION")
$!
$_check_queue:
$	queuename = f$getqui("DISPLAY_QUEUE","QUEUE_NAME","*","SYMBIONT")
$	if queuename .eqs. "" then goto _check_exception_file
$	if f$type(ignore_'queuename') .nes. "" then goto _check_queue
$!
$	msg = "%PRINTER_CHECK-I-QSTATE, Printer queue " + queuename + " is "
$!
$	if f$getqui("DISPLAY_QUEUE","QUEUE_PAUSED","*","SYMBIONT,FREEZE_CONTEXT") 
$	then 
$	    requestmsg = msg + "paused."
$	    if f$type('queuename'_paused) .eqs. "" then -
		'queuename'_paused = 0
$	    'queuename'_paused = 'queuename'_paused + 1
$	    if ('queuename'_paused .lt. max_request) then -
		request/to=(central,printer) "''requestmsg'"
$	    if ('queuename'_paused .eq. max_request) then -
		request/to=(central,printer) "''f$fao("!AS !/(Last message until queue restarted)",requestmsg)"
$	else
$	     'queuename'_paused = 0
$	endif
$!
$	if f$getqui("DISPLAY_QUEUE","QUEUE_STALLED","*","SYMBIONT,FREEZE_CONTEXT") 
$	then 
$	    requestmsg = msg + "stalled."
$	    if f$type('queuename'_stalled) .eqs. "" then -
		'queuename'_stalled = 0
$	    'queuename'_stalled = 'queuename'_stalled + 1
$	    if ('queuename'_stalled .lt. max_request) then -
		request/to=(central,printer) "''requestmsg'"
$	    if ('queuename'_stalled .eq. max_request) then -
		request/to=(central,printer) "''f$fao("!AS !/(Last message until queue restarted)",requestmsg)"
$	else
$	     'queuename'_stalled = 0
$	endif
$!
$	if f$getqui("DISPLAY_QUEUE","QUEUE_STOPPED","*","SYMBIONT,FREEZE_CONTEXT") 
$	then 
$	    requestmsg = msg + "stopped."
$	    if f$type('queuename'_stopped) .eqs. "" then -
		'queuename'_stopped = 0
$	    'queuename'_stopped = 'queuename'_stopped + 1
$	    if ('queuename'_stopped .lt. max_request) then -
		request/to=(central,printer) "''requestmsg'"
$	    if ('queuename'_stopped .eq. max_request) then -
		request/to=(central,printer) "''f$fao("!AS !/(Last message until queue restarted)",requestmsg)"
$	else
$	     'queuename'_stopped = 0
$	endif
$!
$	goto _check_queue
$!
$!
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$! Abort
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$!
$_abort:
$	write sys$output " User aborted procedure."
$	goto _end
$!
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$! Error
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$!
$_error:
$	status = $status
$	msg = f$fao("%PRINTER_CHECK-F-UNEXERR, Unexpected error occurred in !AS !/Error> !AS",f$environment(""PROCEDURE""),f$message(status))
$	if f$mode() .eqs. "INTERACTIVE"
$	then
$	    write sys$output "''msg'"
$	else
$	    request/to=(central,printer) "''msg'"
$	endif
$	goto _end
$!
$_no_privs:
$	write sys$output "%PRINTER_CHECK-F-INSPRIV, Insufficient privileges"
$	goto _end
$!
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$! End
$!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$!
$_end:
$	close/nolog exc_file
$	exit 'status'


!	PRINTER_CHECK_EXCEPTION.DAT
!
!	The file contains a list of device queues which will be ignored by
!	the detached process Printer Check.  That process will search this
!	file for a queue name.  If that queue name is found, it will be
!	ignored, and no STALLED or STOPPED operator messages will be generated
!       for that queue.
!
!	This file must be named UH_OPER:PRINTER_CHECK_EXCEPTION.DAT
!
!  VMS Version  Edit Date  Edit  Init  Description
!  -----------  ---------  ----  ----  ---------------------------------------
!  V5.5-1       10-FEB-93  003   DGW   IS_NOFLAG added (same physical printer
!                                      as IS_LS1).
!  V5.5-1        7-JAN-93  002   DGW   LSWD1 is same as IS_LS1; additing it
!                                      to the exclusion list prevents 
!                                      operators from getting two STALLED
!                                      messages.  [Dan Wing.]
!  V5.5-1       08-DEC-92  0001  DGM   Creation
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

NO_PRINT            ! this one is always STOPPED.
LSWD1               ! same as IS_LS1
IS_NOFLAG           ! same as IS_LS1



  Dom Maddalone, dgm@upi.uhcolorado.edu
  System Administrator/Supervisor, University Physicians, Inc., Denver


