-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_files_count.ps1
40 lines (33 loc) · 1002 Bytes
/
check_files_count.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
Param(
[string]$Path,
[int]$warning,
[int]$critical,
[string]$ListFiles
)
$Files=Get-ChildItem $Path -File | Select LastWriteTime,Name
$Files_Count=(Get-ChildItem $Path -File).count
# Logic Check
if ($warning -gt $critical) {
Write-Output "Warning ($warning) can't be higher then critical! ($critical)"
exit 2
}
# Icinga2 Director true is low true but is is needed True
if ($ListFiles = "true") {
$ListFiles = "True"
}
# Here happens the magic
if ($Files_count -lt $warning) {
Write-Output "OK - Files: $Files_Count|result=$Files_count;"
if ($ListFiles -eq 'TRUE') { Write-Output $Files }
exit 0
}
elseif ($Files_count -le $critical) {
Write-Output "Warning - Files: $Files_Count found|result=$Files_count;"
if ($ListFiles -eq 'TRUE') { Write-Output $Files }
exit 1
}
elseif ($Files_count -ge $critical) {
Write-Output "Critical - Files: $Files_Count found|result=$Files_count;"
if ($ListFiles -eq 'TRUE') { Write-Output $Files }
exit 2
}