This repository was archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_autoit.ps1
More file actions
92 lines (84 loc) · 2.92 KB
/
check_autoit.ps1
File metadata and controls
92 lines (84 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<#
.DESCRIPTION
This plugin will execute an AutoIT script and
return the runtime for the executed action. With
this End2End monitoring will be alot easier integrated
into Icinga environments
.PARAMETER Executable
This is the path to the AutoIT executable
.PARAMETER ConfigFile
If your AutoIT script comes with a configuration
file you can specify it with this parameter
.PARAMETER WarningValue
The warning threshold for the script runtime
.PARAMETER CriticalValue
The critical threshold for the script runtime
.PARAMETER Arguments
Array of possible additional arguments required
for the AutoIT script to run properly
.EXAMPLE
C:\PS>
check_autoit.ps1 -Executable 'wikisearch.exe' `
-ConfigFile 'wikisearch.ini' `
-WarningValue 4 `
-CriticalValue 8 `
-Arguments 'nrpe', 'nsclient'
.NOTES
Author: Christian Stein
Date: October 25, 2016
Company: NETWAYS GmbH
#>
# Define our input parameters at first
param(
[string]$Executable,
[string]$ConfigFile,
[int]$WarningValue,
[int]$CriticalValue,
[array]$Arguments
)
# Ensure an executable has been defined in first place
if (-Not $Executable) {
Write-Host 'Please specify a valid AutoIT executable file.' -ForegroundColor red;
exit 3;
}
if (-Not (Test-Path $Executable)) {
Write-Host 'Unable to locate ' $Executable -ForegroundColor red;
exit 2;
}
<#
Build our process info for executing the AutoIT script
We require to wait until the script was executed
#>
$AutoIIProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
$AutoIIProcessInfo.FileName = $Executable
$AutoIIProcessInfo.RedirectStandardError = $true
$AutoIIProcessInfo.RedirectStandardOutput = $true
$AutoIIProcessInfo.UseShellExecute = $false
$AutoIIProcessInfo.Arguments = "$ConfigFile $Arguments"
$AutoIIProcess = New-Object System.Diagnostics.Process
$AutoIIProcess.StartInfo = $AutoIIProcessInfo
$AutoIIProcess.Start() | Out-Null
$AutoIIProcess.WaitForExit()
# Define variables to store our output data
$AutoITRunTime = $AutoIIProcess.ExitCode
$OutputMessage = '';
$ExitCode = 0;
# Now compare our result with the provided thresholds
if ($AutoITRunTime -eq 0) {
Write-Host = 'Unknown! Returncode was ' + $AutoITRunTime + '';
exit 3;
} elseif ($AutoITRunTime -le $WarningValue) {
$OutputMessage = 'OK!';
$ExitCode = 0;
} elseif ($AutoITRunTime -le $CriticalValue) {
$OutputMessage = 'Warning!';
$ExitCode = 1;
} elseif ($AutoITRunTime -gt $CriticalValue) {
$OutputMessage = 'Critical!'
$ExitCode = 2;
}
# Add some additional informations to our output message
$OutputMessage = $OutputMessage + ' AutoIt-Script was running in ' + $AutoITRunTime + ' sec. |Time=' + $AutoITRunTime + ';' + $WarningValue + ';' + $CriticalValue + '';
# Print the message to the console and exit the script
Write-Host $OutputMessage;
exit $ExitCode;