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
How about throw it up on Xymonton (xymonton.trantor.org)?
From: MFisher at hra.com [mailto:MFisher at hra.com] Sent: Wednesday, April 08, 2009 7:29 PM To: hobbit at hswn.dk 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
Isnt that restricted? Can anyboyd post to xymonton?
Michael S. Fisher ISD | Active Directory Support mfisher at hra.com +1 310 781 5663
I just posted the Windows Printer Monitoring Script on XYMONTON
Feel free to give suggestions.
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 <pre></pre> 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
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...
participants (3)
-
Galen.Johnson@sas.com
-
malcolm.hunter@gmx.co.uk
-
MFisher@hra.com