-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_icinga2_scripts.ps1
More file actions
56 lines (42 loc) · 1.33 KB
/
update_icinga2_scripts.ps1
File metadata and controls
56 lines (42 loc) · 1.33 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
<#
icinga2scripts
Version 0.2
Description: Update powershell from remote host.
Pavel Satin (c) 2016
pslater.ru@gmail.com
#>
$returnStateOK = 0
$returnStateWarning = 1
$returnStateCritical = 2
$returnStateUnknown = 3
$localDir = "c:\Scripts\icinga2\"
$ScriptHost = "http://78.24.216.120"
$ScriptHostPath = $ScriptHost + "/icinga2scripts/"
Try
{
$HttpContent = Invoke-WebRequest -URI $ScriptHostPath -UseBasicParsing
$ArrLinks = $HttpContent.Links | Foreach {$_.href }
Foreach ($ArrStr in $ArrLinks)
{
if ( $ArrStr.endsWith(".ps1") -OR $ArrStr.endsWith(".exe") -OR $ArrStr.endsWith(".dll"))
{
##Для Apache2
$NewScriptHostPath = $ScriptHostPath + $ArrStr
##Для IIS, он отдает ссылки с вместе с виртуальными каталогами
#$NewScriptHostPath = $ScriptHost + $ArrStr
$localFile = $localDir + $ArrStr
Invoke-WebRequest -URI $NewScriptHostPath -UseBasicParsing -OutFile $localFile
$script_count = $script_count + 1
}
}
$icinga2_status = "Update OK: Downloads " + $script_count + " scripts."
Write-Host $icinga2_status
[System.Environment]::Exit($returnStateOK)
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host $ErrorMessage
[System.Environment]::Exit($returnStateCritical)
}