Page 1 of 1

Check for any file in windows directory and alert

Posted: Tue Nov 05, 2019 9:57 am
by brucej543
Running Nagios XI 5.6.5. Need to check a directory on a windows server (example: C:\\Temp\ProblemFTP) and if any files are found, send alert.
Is there a good example for how to set this up using NCPA?

Re: Check for any file in windows directory and alert

Posted: Tue Nov 05, 2019 3:39 pm
by lmiltchev
I don't think you can check for files with NCPA, at least not yet. Having said that, you could use some kind of custom script, which you can call via check_ncpa.py. For example, you could use a powershell script like this one:

check_count.ps1

Code: Select all

param(
	[string] $path
)

$count=(Get-ChildItem -Path "$path" | Measure-Object).Count

$ok = 0
$warning = 1

if ($count -gt 0){
write-host "Warning - $count files exists"
exit $warning
}
else{
write-host "OK - $count files exists"
exit $ok
}
Place the script in the NCPA plugins directory, and call it via check_ncpa.py.

Note: When you run the "check_ncpa.py" plugin, you need to pass one argument (the path to your directory).

Example:

Code: Select all

[root@main-nagios-xi libexec]# ./check_ncpa.py -H x.x.x.x -t 'mytoken' -M 'plugins/check_count.ps1' -q 'args=C:\Temp\ProblemFTP'
OK - 0 files exists

[root@main-nagios-xi libexec]# ./check_ncpa.py -H x.x.x.x -t 'mytoken' -M 'plugins/check_count.ps1' -q 'args=C:\Temp\ProblemFTP'
Warning - 1 files exists

Re: Check for any file in windows directory and alert

Posted: Wed Nov 13, 2019 9:23 am
by brucej543
Thanks, This can be closed

Re: Check for any file in windows directory and alert

Posted: Wed Nov 13, 2019 9:35 am
by lmiltchev
I am glad I could help!