Running a disk space script
Posted: Tue Dec 13, 2022 10:11 am
I have this script created by another person, no longer with the company, it is a powershell that deletes a placeholder file on a windows server. We used to run Orion which would trigger the script when disk space reached a limit. I want to run this script on NagiosXI now.
$myDays = -30
$myNum = 0
$myCount = 0
$myPath = "\\$Server\$myDrive$\Placeholders"
Write-Host "$Server - $myDrive - $myPath"
$currDate = Get-Date
$myDate = $currDate.AddDays($myDays)
$cleanDate = $myDate.ToString("MM/dd/yyyy")
$mailDate = $currDate.toString("MM/dd/yyyy")#
$myFiles = Get-ChildItem -Path $myPath
Write-Host $myFiles.Count
If ($myFiles.Count -gt 10) {
$myNum = 10
}
Else {
$myNum = ($myFiles.Count - 1)
}
ForEach ($File in $myFiles) {
If ($File.Name -like '*deleteme*' -and $myCount -lt $myNum) {
remove-item -path $File.FullName -force
$myCount++
}
}
$myFiles = Get-ChildItem -Path $myPath
I don't know jack about powershell, but the above is the action portion. How do I set up Nagios to trigger this with the correct drive info?
$myDays = -30
$myNum = 0
$myCount = 0
$myPath = "\\$Server\$myDrive$\Placeholders"
Write-Host "$Server - $myDrive - $myPath"
$currDate = Get-Date
$myDate = $currDate.AddDays($myDays)
$cleanDate = $myDate.ToString("MM/dd/yyyy")
$mailDate = $currDate.toString("MM/dd/yyyy")#
$myFiles = Get-ChildItem -Path $myPath
Write-Host $myFiles.Count
If ($myFiles.Count -gt 10) {
$myNum = 10
}
Else {
$myNum = ($myFiles.Count - 1)
}
ForEach ($File in $myFiles) {
If ($File.Name -like '*deleteme*' -and $myCount -lt $myNum) {
remove-item -path $File.FullName -force
$myCount++
}
}
$myFiles = Get-ChildItem -Path $myPath
I don't know jack about powershell, but the above is the action portion. How do I set up Nagios to trigger this with the correct drive info?