From 7991c9e71fab3f04e09a94e4c150c1f049ed235d Mon Sep 17 00:00:00 2001 From: mkoetzing Date: Wed, 4 Nov 2020 13:27:06 +0100 Subject: [PATCH] translation_en some translation, tested on zabbix5 an win2019server as client --- zabbix v5/DiscoverScheduledTasks.ps1 | 90 +++++++ zabbix v5/Readme.md | 60 +++++ zabbix v5/zbx5_export_templates.xml | 346 +++++++++++++++++++++++++++ 3 files changed, 496 insertions(+) create mode 100644 zabbix v5/DiscoverScheduledTasks.ps1 create mode 100644 zabbix v5/Readme.md create mode 100644 zabbix v5/zbx5_export_templates.xml diff --git a/zabbix v5/DiscoverScheduledTasks.ps1 b/zabbix v5/DiscoverScheduledTasks.ps1 new file mode 100644 index 0000000..430c15b --- /dev/null +++ b/zabbix v5/DiscoverScheduledTasks.ps1 @@ -0,0 +1,90 @@ +# Script: DiscoverSchelduledTasks +# Author: Romain Si +# +# This script is intended for use with Zabbix > 3.x +# +# +# Add to Zabbix Agent +# UserParameter=TaskSchedulerMonitoring[*],powershell -NoProfile -ExecutionPolicy Bypass -File "C:\_zabbix\DiscoverScheduledTasks.ps1" "$1" "$2" +# +## Change the $path variable to indicate the Scheduled Tasks subfolder to be processed as "\nameFolder\" or "\nameFolder2\subfolder\" see (Get-ScheduledTask -TaskPath ) + + +$path = "\" + + +Function Convert-ToUnixDate ($PSdate) { + $epoch = [timezone]::CurrentTimeZone.ToLocalTime([datetime]'1/1/1970') + (New-TimeSpan -Start $epoch -End $PSdate).TotalSeconds +} + +$ITEM = [string]$args[0] +$ID = [string]$args[1] + +switch ($ITEM) { + "DiscoverTasks" { +$apptasks = Get-ScheduledTask -TaskPath $path | where {$_.state -like "Ready" -or "Running"} +$apptasksok = $apptasks.TaskName +$idx = 1 +write-host "{" +write-host " `"data`":[`n" +foreach ($currentapptasks in $apptasksok) +{ + if ($idx -lt $apptasksok.count) + { + + $line= "{ `"{#APPTASKS}`" : `"" + $currentapptasks + "`" }," + write-host $line + } + elseif ($idx -ge $apptasksok.count) + { + $line= "{ `"{#APPTASKS}`" : `"" + $currentapptasks + "`" }" + write-host $line + } + $idx++; +} +write-host +write-host " ]" +write-host "}"}} + + +switch ($ITEM) { + "TaskLastResult" { +[string] $name = $ID +$pathtask = Get-ScheduledTask -TaskPath "*" -TaskName "$name" +$pathtask1 = $pathtask.Taskpath +$taskResult = Get-ScheduledTaskInfo -TaskPath "$pathtask1" -TaskName "$name" +Write-Output ($taskResult.LastTaskResult) +}} + +switch ($ITEM) { + "TaskLastRunTime" { +[string] $name = $ID +$pathtask = Get-ScheduledTask -TaskPath "*" -TaskName "$name" +$pathtask1 = $pathtask.Taskpath +$taskResult = Get-ScheduledTaskInfo -TaskPath "$pathtask1" -TaskName "$name" +$taskResult1 = $taskResult.LastRunTime +$date = get-date -date "01/01/1970" +$taskResult2 = (New-TimeSpan -Start $date -end $taskresult1).TotalSeconds +Write-Output ($taskResult2) +}} + +switch ($ITEM) { + "TaskNextRunTime" { +[string] $name = $ID +$pathtask = Get-ScheduledTask -TaskPath "*" -TaskName "$name" +$pathtask1 = $pathtask.Taskpath +$taskResult = Get-ScheduledTaskInfo -TaskPath "$pathtask1" -TaskName "$name" +$taskResult1 = $taskResult.NextRunTime +$date = get-date -date "01/01/1970" +$taskResult2 = (New-TimeSpan -Start $date -end $taskresult1).TotalSeconds +Write-Output ($taskResult2) +}} + +switch ($ITEM) { + "TaskState" { +[string] $name = $ID +$pathtask = Get-ScheduledTask -TaskPath "*" -TaskName "$name" +$pathtask1 = $pathtask.State +Write-Output ($pathtask1) +}} diff --git a/zabbix v5/Readme.md b/zabbix v5/Readme.md new file mode 100644 index 0000000..4d08d4e --- /dev/null +++ b/zabbix v5/Readme.md @@ -0,0 +1,60 @@ +================DiscoverScheduledTasks ================ + +This template use PowerShell Cmdlets to discover and manage Windows Tasks Scheduled. + +Items : Task Last Result (Status for each tasks), Task Last Run Time, Task Next Run time + +Discovery : All tasks Active or Running + +Triggers : [HIGH] => Last Result of tasks FAILED
+Triggers : [HIGH] => State of tasks Disabled + +Install : +Import template, +Install the Zabbix agent on your host, +Copy DiscoverScheduledTasks.ps1 in your zabbix agent directory, +In powershell script change $path variable for subsfolders, +Add the following line to your Zabbix agent configuration file : + + +EnableRemoteCommands=1 +UnsafeUserParameters=1 +UserParameter=TaskSchedulerMonitoring[*],powershell -NoProfile -ExecutionPolicy Bypass -File "C:\_zabbix\DiscoverScheduledTasks.ps1" "$1" "$2" +Timeout=30 + + + +do not forget to restart the zabbix agent!! + + + + + + + + + +####### USER-DEFINED MONITORED PARAMETERS ####### + +### Option: UnsafeUserParameters +# Allow all characters to be passed in arguments to user-defined parameters. +# The following characters are not allowed: +# \ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @ +# Additionally, newline characters are not allowed. +# 0 - do not allow +# 1 - allow +# +# Mandatory: no +# Range: 0-1 +# Default: +# UnsafeUserParameters=0 +UnsafeUserParameters=1 + +### Option: UserParameter +# User-defined parameter to monitor. There can be several user-defined parameters. +# Format: UserParameter=, +# +# Mandatory: no +# Default: +# UserParameter= +UserParameter=TaskSchedulerMonitoring[*],powershell -NoProfile -ExecutionPolicy Bypass -File "C:\_zabbix\DiscoverScheduledTasks.ps1" "$1" "$2" \ No newline at end of file diff --git a/zabbix v5/zbx5_export_templates.xml b/zabbix v5/zbx5_export_templates.xml new file mode 100644 index 0000000..632dc08 --- /dev/null +++ b/zabbix v5/zbx5_export_templates.xml @@ -0,0 +1,346 @@ + + + 3.4 + 2018-01-05T12:48:06Z + + + Templates + + + + + + + + scheduledtask + + + 0 + Success + + + 1 + Bad or unknown function called + + + 2 + File not found + + + 10 + Incorrect environment + + + 267008 + The task is ready to run at the next scheduled time + + + 267009 + The task is running + + + 267011 + The task is not yet complete + + + 267012 + There are no more operations scheduled for this task + + + 267014 + The task is finished + + + 2147750671 + Corrupted credentials + + + 2147750687 + An instance of this task is already running + + + 2147942401 + Fonction incorrecte ou inconnue appelée + + + 2147942402 + Bad or unknown function called + + + 2147942667 + The "start in" directory cannot be found + + + 2147943645 + The service is not available + + + 3228369022 + Unknown software exception + + + + +