Wednesday, 14 March 2018

Paessler: EXE/Script Advanced Sensor to Monitor Print Job

The following steps allow you to monitor the print job by using the EXE/Script Advanced sensor:
1. Copy powershell.exe on the probe from c:\windows\system32\windowspowershell\* to the EXE/XML directory in c:\program files (x86)\PRTG Network Monitor\Custom Sensors

2. Copy the following script as a .ps1 file in c:\batch on the probe
# prtg-print.ps1
#
#
param (
[string]$server= "<server name>"     #please enter your server name here
)
write-host "Start PRTG Sensor"
write-host "Server:" $Server
$serverlist = $server.split(",")
write-host "Serverlist count:" $Serverlist.count
$result='<?xml version="1.0" encoding="UTF-8" ?>`r`n<prtg>`r`n'

foreach ($server in $serverlist){
write-host "Server: " $server
$queue = (Get-PrintJob -ComputerName $server –PrinterName "MacQ" | where JobStatus -eq 'Paused')
#$value = $queue.count
if ($error) {
# Skip Counters
write-host "Server: $server Unable to read $counter"
$error.clear()
}
else  {
$result+="  <result>`r`n"
$result+="    <channel>ErrorPrintJob("+$server+")</channel>`r`n"
$result+="    <value>"+$value.CounterSamples[0].CookedValue+"</value>`r`n"
$result+="    <unit>Count</unit>`r`n"
$result+="    <mode>Absolute</mode>`r`n"
$result+="  </result>`r`n"
}
}
$result+="<text>ErrorPrintJobs:"+$arg+"</text>`r`n"
$result+="</prtg>"
write-host "End: ExitCode "$error.count
Write-host "Sending Result to output pipeline"
$result
if ($error) {
#write-host "Found Errors"
EXIT 1
}
3. Create an EXE/Script Advanced Sensor in PRTG

4. Select powershell.exe

5. Enter parameters: -noprofile -executionpolicy bypass -file c:\batch\prtg-print.ps1 (or your script)

6. Set security context to Use Windows credentials of parent device

No comments:

Post a Comment