-
Notifications
You must be signed in to change notification settings - Fork 1
/
PRTG-Scheduler.ps1
91 lines (76 loc) · 2.91 KB
/
PRTG-Scheduler.ps1
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
#requires -version 4.0
# ___ ___ _____ ___
#| _ \ _ \_ _/ __|
#| _/ / | || (_ |
#|_| |_|_\ |_| \___|
# Scheduler
# ================================
# This is the Sensor for the PRTG scheduler which will execute the scheduler application
# that applies maintenance windows to PRTG objects, according to their configuration.
# The output is then displayed as JSON so that PRTG can interpret it.
#
# Version History
# ----------------------------
# 06/2017 1.0 initial release
# # # # # # # # # # # # # # # # # # # # # # # # # #
#region
# ___ ___ _ _ ___ ___ ___
# / __/ _ \| \| | __|_ _/ __|
#| (__|(_) | .` | _| | | (_ |
# \___\___/|_|\_|_| |___\___|
# # # # # # # # # # # # # # #
$progressPreference = 'silentlyContinue'
$phpPath = "C:\PHP\"
$PrtgError = @"
<?xml version='1.0' encoding='UTF-8' ?><prtg>
<error>1</error><text>{0}</text>
</prtg>
"@
$jsMenuEntry = ''
#endregion
#region
# ___ _ _ _ _ ___ _____ ___ ___ _ _ ___
#| __| | | | \| |/ __|_ _|_ _/ _ \| \| / __|
#| _|| |_| | .` | (__ | | | | (_) | .` \__ \
#|_| \___/|_|\_|\___| |_| |___\___/|_|\_|___/
# # # # # # # # # # # # # # # # # # # # # # #
#
# Basic
# # # #
Function This-ShowMessage([string]$type,$message){
Write-Host ("[{0}] " -f (Get-Date)) -NoNewline;
switch ($type){
"success" { Write-Host " success " -BackgroundColor Green -ForegroundColor White -NoNewline; }
"information" { Write-Host " information " -BackgroundColor DarkCyan -ForegroundColor White -NoNewline; }
"warning" { Write-Host " warning " -BackgroundColor DarkYellow -ForegroundColor White -NoNewline; }
"error" { Write-Host " error " -BackgroundColor DarkRed -ForegroundColor White -NoNewline; }
default { Write-Host " notes " -BackgroundColor DarkGray -ForegroundColor White -NoNewline; }
}
Write-Host (" {0}{1}" -f $message,$Global:blank)
}
Function This-TestPHP(){
if(Test-Path -Path "$($phpPath)php.exe")
{ return $true; }
else
{ return $false; }
}
Function This-AddMenuEntry(){
$customJS = (Get-Content -Path "C:\Program Files (x86)\PRTG Network Monitor\webroot\javascript\scripts_custom.js")
}
Function This-ExecutePHP($command = ""){
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "$($phpPath)php.exe"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "$($phpPath)app\index.php PRTGScheduler $($command)"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
return $p.StandardOutput.ReadToEnd();
}
#endregion
if(This-TestPHP)
{ This-ExecutePHP -command "setMaintenance" }
else
{ Write-Host ([string]::Format($PrtgError,"PHP.exe not found under $($phpPath). Please make sure it's installed!")); }