This script reports bad if:
* There are more than 5 jobs waiting
* There is a print job that's over 15 minutes old.
All other times it reports good.
Code: Select all
Option Explicit
const statusAlive = "Host is alive:"
const statusDead = "No answer:"
const statusUnknown = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk = "Ok:"
const statusBad = "Bad:"
const statusBadContents = "Bad contents:"
Const USE_LOCAL_TIME = True
FUNCTION PerformTest()
dim intTotalJobs, intTotalPages, objPrintJob, oResponse
dim objWMIService, colPrintJobs
dim int15minCount, DateTime, dtmActualTime, TimeinQueue
intTotalJobs = 0
intTotalPages = 0
int15minCount = 0
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery ("Select * from Win32_PrintJob")
Set DateTime = CreateObject("WbemScripting.SWbemDateTime")
For Each objPrintJob in colPrintJobs
intTotalJobs = intTotalJobs + 1
intTotalPages = intTotalPages + objPrintJob.TotalPages
'Check age of job
DateTime.Value = objPrintJob.TimeSubmitted
dtmActualTime = DateTime.GetVarDate(USE_LOCAL_TIME)
TimeinQueue = DateDiff("n", dtmActualTime, Now)
If TimeinQueue > 15 Then
int15minCount = int15minCount + 1
''strPrinterName = Split(objPrintJob.Name,",",-1,1)
'strPrinterName(0) = Printer Name
'objPrintJob.JobID = Print Job ID
End If
Next
oResponse = "Total jobs: " & intTotalJobs & " (Pages: " & intTotalPages & ")"
If int15minCount > 0 Then
oResponse = "Waiting >15mins: " & int15minCount & " / " & oResponse
End if
If int15minCount > 0 or intTotalJobs > 5 Then 'If a print job has been waiting >15mins, OR there are 5 jobs waiting then alert
PerformTest = statusBad+oResponse
Else
PerformTest = statusOk+oResponse
End If
End Function