Running a disk space script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Post Reply
sctheide
Posts: 10
Joined: Fri May 14, 2021 10:22 am

Running a disk space script

Post by sctheide »

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?
sctheide
Posts: 10
Joined: Fri May 14, 2021 10:22 am

Re: Running a disk space script

Post by sctheide »

Here is an alert that I wish to trigger the above script.

Service: Drive G: Disk Usage
Host: data-server-4.domain.com
Address: 192.168.1.194
State: WARNING
Info:
WARNING - [Triggered by _Used%96] - G: Total=1,899.997GB, Used=1,858.301GB (97.8%), Free=41.696GB (2.2%)
Date/Time: 2022-12-13 09:00:22
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Running a disk space script

Post by gormank »

First, you want to update the script so it prints a single line of test as output, and returns one of the valid status values for nagios.Then you can define the script ina command and call it as a plugin.
Post Reply