Windows Print Server Monitoring

MFisher at hra.com MFisher at hra.com
Thu Apr 9 01:28:45 CEST 2009



In case anybody is interested, i have completed my rough implementation of
a Windows Print Server Monitoring VBS Script that will create and populate
a column in BB.

It might be able to be written a little cleaner or shorter but hey, im no
VBS expert...

Use freely....

---------------------------

Option Explicit
On Error Resume Next

Dim colour, bbdelay, strDetail, strDetailAll
Dim WindowsShell, objWMIService, colInstalledPrinters, BBConfigExtPath,
objPrinter

'Name of test column in BB
Const BBTestName = "print"

strDetail = ""
strDetailAll = ""
colour = "green"
bbdelay = "+27"

'Complete path to the BB TMP Directory
BBConfigExtPath = "c:\Program Files\BBWin\tmp"

'=============================================================================

Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

'WMI Query
Set colInstalledPrinters = objWMIService.ExecQuery("Select
PortName,Location,Status,DetectedErrorState,Name from Win32_Printer")

'WMI Query Restriction
'If you want to not include things such as Microsoft XPS Writer or Adobe
PDF Printer, put a where clause in the query above
'Example (where Name != 'Microsoft XPS Document Writer')  - != means NOT
EQUAL

For Each objPrinter in colInstalledPrinters
'If objPrinter.Status = "Degraded" Then

If objPrinter.DetectedErrorState = "9" Then
strDetail = "&red" & " " & objPrinter.Name & " is OFFLINE" & vbCrLf &
strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" &
objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" &
vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "6" Then
strDetail = "&red" & " " & objPrinter.Name & " has NO TONER" & vbCrLf &
strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" &
objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" &
vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "4" Then
strDetail = "&red" & " " & objPrinter.Name & " has NO PAPER" & vbCrLf &
strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" &
objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" &
vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "8" Then
strDetail = "&red" & " " & objPrinter.Name & " is JAMMED" & vbCrLf &
strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" &
objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" &
vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "10" Then
strDetail = "&red" & " " & objPrinter.Name & " is Requesting Service" &
vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" &
objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" &
vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "11" Then
strDetail = "&red" & " " & objPrinter.Name & " shows OUTPUT BIN IS FULL" &
vbCrLf & strDetail & vbCrLf
strDetailAll = "<tr><td>&red " & objPrinter.Name & "</td><td>" &
objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" &
vbCrLf & strDetailAll
colour = "red"
ElseIf objPrinter.DetectedErrorState = "0" Then
strDetailAll = "<tr><td>&green " & objPrinter.Name & "</td><td>" &
objPrinter.PortName & "</td><td>" & objPrinter.Location & "</td></tr>" &
vbCrLf & strDetailAll
End If
'End IF
Next

Set colInstalledPrinters = Nothing
Set objWMIService = Nothing

StartDetailBuild()
SetPrintFinalStatus()
GetBBPath()
WriteFile()

Sub StartDetailBuild()
      IF colour = "red" then
      strDetail = "&red Printer Status:" & vbCrLf & vbCrLf & strDetail &
vbCrLf
        ElseIf colour = "green" then
        strDetail = "&green Printer Status: All Printers are Online and
Operational" & vbCrLf & vbCrLf & strDetail & vbCrLf
        End If
End Sub

Sub SetPrintFinalStatus()
      Select Case colour
            Case "red"
                  strDetail = "red" & bbdelay & " " & Date & " " & Time &
vbCrLf & vbCrLf & strDetail & vbCrLf
            Case "yellow"
                  strDetail = "yellow" & bbdelay & " " & Date & " " & Time
& vbCrLf & vbCrLf & strDetail & vbCrLf
            Case "green"
                  strDetail = "green" & bbdelay & " " & Date & " " & Time &
vbCrLf & vbCrLf & strDetail & vbCrLf
      End Select
End Sub

Sub GetBBPath()
      Set WindowsShell = WScript.CreateObject("WScript.Shell")
      If IsObject(WindowsShell) Then Set WindowsShell = Nothing
End Sub

Sub WriteFile()
    Dim oFSO, oFile
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFile = oFSO.OpenTextFile(BBConfigExtPath & "\" & BBTestName , 8 ,
TRUE)
    oFile.Write strDetail
    oFile.Write "<table>" & vbCrLf & strDetailAll & vbCrLf & "</table>"
    oFile.Close
    If IsObject(oFSO) Then Set oFSO = Nothing
End Sub
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20090408/d706d9a9/attachment.html>


More information about the Xymon mailing list