Skip to content

Commit

Permalink
Add Check-FileRecency
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Axvig committed Mar 2, 2021
1 parent 4d29c07 commit 2806b55
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
SnmpCredentials.ps1
SnmpV2Credentials.ps1
Check-FileRecency-Settings.ps1
16 changes: 16 additions & 0 deletions FileRecency/Check-FileRecency-SettingsExample.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("UseDeclaredVarsMoreThanAssignments", "SnmpInfo")]
$filesToCheck = @(
@{
NameForChannel = "Server1 DB_dump"
FileSearchString = "\\backups\Server1\DB_dump_*"
MinimumSize = 800MB
MaximumAge = New-TimeSpan -Hours 30
}

@{
NameForChannel = "Server2 DB_dump"
FileSearchString = "\\backups\Server2\DB_dump_*"
MinimumSize = 10GB
MaximumAge = New-TimeSpan -Hours 30
}
)
42 changes: 42 additions & 0 deletions FileRecency/Check-FileRecency.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#Requires -Modules PrtgXml
# Install-Module PrtgXml
# https://www.powershellgallery.com/packages/PrtgXml
# https://github.com/lordmilko/PrtgXml

Param(
[Parameter(Mandatory=$false)]
[string]
$CheckFileRecencySettings = 'Check-FileRecency-Settings.ps1'
)

$path = Join-Path $PSScriptRoot $CheckFileRecencySettings
. $path

Prtg {
foreach ($fileToCheck in $filesToCheck) {
if (Test-Path -Path $fileToCheck.FileSearchString) {
$files = Get-Item -Path $fileToCheck.FileSearchString
$newest = $files | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$age = New-TimeSpan -Start $newest.LastWriteTime

Result {
Channel "$($fileToCheck.NameForChannel) age OK"
Value ([int]($age -lt $fileToCheck.MaximumAge))
Unit 'Custom'
ValueLookup "prtg.standardlookups.boolean.statetrueok"
}

Result {
Channel "$($fileToCheck.NameForChannel) size OK"
Value ([int]($newest.Length -gt $fileToCheck.MinimumSize))
Unit 'Custom'
ValueLookup "prtg.standardlookups.boolean.statetrueok"
}
}
else {
Error 1
Text "No $($fileToCheck.NameForChannel) files found with search string $($fileToCheck.FileSearchString). Aborting further checks."
break
}
}
}

0 comments on commit 2806b55

Please sign in to comment.