hello
i am trying to monitor the DEFAULT printer queue on my windows server 2003 but this fails.
i wrote a VB script that counts the printjobs in my queue
if the printjobs count is higher then 5 an alert will come up.
this is what i have but DOES NOT WORK.
can some one help me with this ??
thanks
m
code:
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:"
FUNCTION PerformTest()
Option Explicit
'On Error Resume Next
Dim strComputer
Dim wmiNS
Dim wmiQuery
Dim objWMIService
Dim colItems
Dim objItem
Dim intTotalJobs
Dim intTotalPages
Dim intMaxPrintJob
strComputer = '.'
wmiNS = '\root\cimv2'
wmiQuery = 'Select * from win32_PrintJob'
Set objWMIService = GetObject('winmgmts:\\' _
& strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)
If colItems.count = 0 Then
WScript.Echo('There are no print jobs at this time')
Else
For Each objItem In colItems
intTotalJobs = intTotalJobs + 1
intTotalPages = intTotalPages + objItem.TotalPages
If objItem.TotalPages > intMaxPrintJob Then
intMaxPrintJob = objItem.TotalPages
End If
Next
WScript.Echo 'Total print jobs in queue: ' & intTotalJobs
WScript.Echo 'Total pages in queue: ' & intTotalPages
WScript.Echo 'Largest print job in queue: ' & intMaxPrintJob
End If
PerformTest = statusUnknown+"Empty VBScript" 'change this line to return proper test`s "Status" and "Reply" value to HostMonitor
END FUNCTION
problem monitoring print queue
1) mp1 is right - if you just need to check number of printjobs in the queue, you don't need any script. Use WMI test method
2) When you have some problem then please describe the problem. Simple "Does not work" does not provide any useful information. What exactly does not work? Do you see some errors? What exactly error? What is the status of the test? What is Reply value of the test?
3) It does not work because your script does not provide correct results to HostMonitor.
Please check the manual or visit our web site to find out how your script should pass test results to HostMonitor.
If you are using Active Script test method, please read this section: http://www.ks-soft.net/hostmon.eng/mfra ... htm#script
If you are using Shell Script test method, please read this section:
http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Also there are various script samples come with our software.
If you want to display number of jobs and number of pages in Reply field of the test, your script (for Shell Script test method) may look like
Regards
Alex
2) When you have some problem then please describe the problem. Simple "Does not work" does not provide any useful information. What exactly does not work? Do you see some errors? What exactly error? What is the status of the test? What is Reply value of the test?
3) It does not work because your script does not provide correct results to HostMonitor.
Please check the manual or visit our web site to find out how your script should pass test results to HostMonitor.
If you are using Active Script test method, please read this section: http://www.ks-soft.net/hostmon.eng/mfra ... htm#script
If you are using Shell Script test method, please read this section:
http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Also there are various script samples come with our software.
If you want to display number of jobs and number of pages in Reply field of the test, your script (for Shell Script test method) may look like
Code: Select all
Option Explicit
const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"
Dim strComputer
Dim wmiNS
Dim wmiQuery
Dim objWMIService
Dim colItems
Dim objItem
Dim intTotalJobs
Dim intTotalPages
Dim intMaxPrintJob
dim objArgs
Set objArgs = WScript.Arguments
strComputer = "."
wmiNS = "\root\cimv2"
wmiQuery = "Select * from win32_PrintJob"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)
If colItems.count = 0 Then
WScript.StdOut.Write statusOk & "Print jobs=0"
Else
For Each objItem In colItems
intTotalJobs = intTotalJobs + 1
intTotalPages = intTotalPages + objItem.TotalPages
If objItem.TotalPages > intMaxPrintJob Then
intMaxPrintJob = objItem.TotalPages
End If
Next
If intTotalJobs > Int(objArgs(0)) Then
WScript.StdOut.Write statusBad & "print jobs=" & intTotalJobs & " Total pages=" & intTotalPages & " Largest print job=" & intMaxPrintJob
Else
WScript.StdOut.Write statusOk & "print jobs=" & intTotalJobs & " Total pages=" & intTotalPages & " Largest print job=" & intMaxPrintJob
End If
End If
Alex