Windows Print Server Monitoring
list Michael S. Fisher
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
list Galen Johnson
How about throw it up on Xymonton (xymonton.trantor.org)?
▸
From: user-ab09d151b26b@xymon.invalid [mailto:user-ab09d151b26b@xymon.invalid]
Sent: Wednesday, April 08, 2009 7:29 PM
To: user-ae9b8668bcde@xymon.invalid
Subject: [hobbit] Windows Print Server Monitoring
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
list Michael S. Fisher
Isnt that restricted? Can anyboyd post to xymonton? Michael S. Fisher ISD | Active Directory Support user-ab09d151b26b@xymon.invalid +X XXX XXX XXXX
list Michael S. Fisher
I just posted the Windows Printer Monitoring Script on XYMONTON Feel free to give suggestions.
list Malcolm Hunter
▸
I just posted the Windows Printer Monitoring Script on XYMONTON Feel free to give suggestions.
Thanks for posting. I've been working on something similar trying to use the fsmon code model (no small task). I can see why you used tables to make the layout of the web page neater. Unfortunately this means the email alerts are full of HTML and almost illegible. The log is displayed using tags on the Xymon web pages, so you _can_ use normal text separated by tabs. To facilitate this I wrote a Pad() function to make all of the fields the same width in each column. You need to find out the maximum length of each field to make use of this: ' Get max lengths For Each objPrinter in colInstalledPrinters If Len(objPrinter.Name) > iMaxNameLen Then iMaxNameLen = Len(objPrinter.Name) If Len(objPrinter.PortName) > iMaxPortLen Then iMaxPortLen = Len(objPrinter.PortName) If Len(objPrinter.Location) > iMaxLocnLen Then iMaxLocnLen = Len(objPrinter.Location) Next ' Use tabs and padding to format each line strDetailAll = "&red " & Pad(objPrinter.Name, iMaxNameLen) & vbTab & Pad(objPrinter.PortName, iMaxPortLen) & vbTab & Pad(objPrinter.Location, iMaxLocnLen) ' Returns text padded to iLength Function Pad(sText, iLength) Dim iPadBy, sTemp sTemp = sText iPadding = iLength - Len(sText) If iPadding > 0 Then sTemp = sTemp & Space(iPadding) Pad = sTemp End Function -- Technical copy-editor & proofreader KDE Proofreading Team KDE British English Translation Team http://l10n.kde.org/team-infos.php?teamcode=en_GB Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01
list Michael S. Fisher
Good change! The email alert is not so iportant because it spits out the relevant status at the top with NO html code...below obviously it is full of code...