We need to monitor a scheduled task created on a server can we do it by PRTG?
Monitor scheduled windows task
Votes:
0
4 Replies
Votes:
0
Daniel,
We cannot monitor the scheduled task itself natively. You might be best by creating a PowerShell script to poll for the data, and have that dump into PRTG via a custom script.
Depending on what the task does, we can monitor for services or processes it invokes.
Benjamin Day
Paessler Support
Votes:
0
Hi,
For me, it was a pleasant surprise https://mycloudrevolution.com/2016/09/15/prtg-advanced-scheduled-task-sensor/
Votes:
0
Here's a shorter PowerShell script I created based on the details in the link above.
# Parameters param ( [parameter(Mandatory=$true,position=0)] [string] $Server, [parameter(Mandatory=$true,position=1)] [string] $TaskName, [parameter(position=3)] [string] $Folder = '\' ) # Main try { # Get task status $Schedule = New-Object -ComObject 'Schedule.Service' $Schedule.connect($Server) $FolderRef = $Schedule.getfolder($Folder) $Task = $FolderRef.GetTasks(1) | Where-Object {$_.name -eq $TaskName} $TaskEnabled = $Task.enabled $TaskLastRunHours = [math]::round($(New-TimeSpan -Start $([datetime]$Task.lastruntime) -End $(Get-Date)).TotalHours,0) $TaskLastResult = $Task.lasttaskresult # Create PRTG response $Message = "The scheduled task `'$TaskName`' last ran $TaskLastRunHours hour(s) ago with a result of $TaskLastResult." $Channels = @() $Channels += [pscustomobject]@{ 'channel'="Task Enabled"; 'value'= [int]($TaskEnabled) } $Channels += [pscustomobject]@{ 'channel'="Hours since last run"; 'value'= $TaskLastRunHours } $Channels += [pscustomobject]@{ 'channel'="Last run result"; 'value'= $TaskLastResult } $Result = [pscustomobject]@{ result = $Channels; text = "$Message" } $PRTGResult = [pscustomobject]@{prtg = $Result} $PRTGResult | ConvertTo-Json -Depth 3 } catch { $Result = [pscustomobject]@{ error = '1'; text = "$HealthCheckURL Error at line $($_.InvocationInfo.ScriptLineNumber): $_ $($_.Exception)" } $PRTGResult = [pscustomobject]@{prtg = $Result} $PRTGResult | ConvertTo-Json }
Votes:
0
Dezdez,
Have you considered submitting this for ScriptWorld?
Submit your script to ScriptWorld
Thanks!
Benjamin Day
Paessler Support
Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.
Add comment