Page 1 of 2
File Monitoring - Linux mount point
Posted: Wed Sep 02, 2020 4:05 am
by RebeccaIlene
Hi Team,
We have some linux mount points that are mapped as windows shares using DFS namespaces.
We want to monitor this path to check if a file *.dat exists in the path everyday at 6 AM.
If the file does not exist it should throw a critical error.
We have this monitoring setup for windows shares where the monitoring is set to check on a drive on the server but haven't been able to set this up for a linux mount point.
Can you please suggest how we can proceed with monitoring this?
Re: File Monitoring - Linux mount point
Posted: Wed Sep 02, 2020 5:01 pm
by jdunitz
You could put together a little plugin script to run via nrpe:
Code: Select all
[root@jpd-cent-nrpe-one libexec]# cat check_datfile
#!/bin/sh
cd $1
ls *.dat > /dev/null
if [ $? -eq 0 ]; then
echo "OK: dat file found as expected"
exit 0
else
echo "CRIT: dat file not found in $1"
exit 2
fi
[root@jpd-cent-nrpe-one libexec]#
and it works like so:
Code: Select all
[root@jpd-cent-nrpe-one libexec]# ./check_nrpe -H 192.168.1.10 -c 'DAT Check' -a /tmp/data
OK: dat file found as expected
[root@jpd-cent-nrpe-one libexec]# rm /tmp/data/sdf.dat
rm: remove regular empty file `/tmp/data/sdf.dat'? y
[root@jpd-cent-nrpe-one libexec]# ./check_nrpe -H 192.168.1.10 -c 'DAT Check' -a /tmp/data
CRIT: dat file not found in /tmp/data
The part about having it only do its thing at 6am is a bit tricky; Nagios kind of thinks of things as running constantly, rather than just once or at a specific time.
However, you could have the script check the hour itself when it runs:
Code: Select all
#!/bin/sh
date +%H | grep -q 06 || echo "OK: not 6am"
date +%H | grep -q 06 || exit 0
cd $1
ls *.dat > /dev/null
if [ $? -eq 0 ]; then
echo "OK: dat file found as expected"
exit 0
else
echo "CRIT: dat file not found in $1"
exit 2
fi
This is super-hacky and more or less just a proof of concept that you can improve upon.
But you can give it a try and see if it works. As it is, it will find any file that has a .dat at the end of the filename, in the directory you pass as an argument. If you need it to calculate a specific date or something, like that case you had a few months ago, that would be a bit more code.
Oh, and I have this command defined on the client-side nrpe.cfg:
Code: Select all
command[DAT Check]=/usr/local/nagios/libexec/check_datfile $ARG1$
--Jeffrey
Re: File Monitoring - Linux mount point
Posted: Thu Sep 03, 2020 12:01 am
by RebeccaIlene
Thanks for the suggestion.
However, the linux host is not managed by us. It's managed by the vendor and we can't install NRPE on the host.
Is there another way to monitor this?
Re: File Monitoring - Linux mount point
Posted: Thu Sep 03, 2020 10:39 am
by jdunitz
What ways into the machine do you have? SSH? Another agent like NCPA?
--Jeffrey
Re: File Monitoring - Linux mount point
Posted: Thu Sep 10, 2020 2:36 am
by RebeccaIlene
Hi Jeffrey,
We will raise a case with the vendor to check if it's possible to install the Nagios client.
Will update the ticket once we get an update from them.
Re: File Monitoring - Linux mount point
Posted: Fri Sep 11, 2020 9:17 am
by jdunitz
Hi Rebecca,
Do you need any help from our end on this one, or are you still in the process of getting something going with your vendor?
Let us know if we can help.
Thanks!
--Jeffrey
Re: File Monitoring - Linux mount point
Posted: Wed Sep 16, 2020 5:03 am
by RebeccaIlene
The vendor provided us with a custom plugin for Nagios to monitor the devices but we are still unsure how we can monitor shares using this.
Can you please help us?
Here the link provided by the vendor.
https://www.cohesity.com/blog/backup-an ... th-nagios/
Re: File Monitoring - Linux mount point
Posted: Thu Sep 17, 2020 3:35 pm
by lmiltchev
We don't provide support for custom plugins, however you could follow the instructions, shown here:
https://github.com/cohesity/cohesity-nagios-plugin
If you have any further questions, I would recommend that you contact your vendor.
Once you make sure your custom plugin works from the command line, you could add a new command and a service by following the document below:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Re: File Monitoring - Linux mount point
Posted: Mon Sep 21, 2020 10:34 pm
by RebeccaIlene
Thanks for the suggestion.
However, we are looking to monitor file shares to see if a *.dat file comes in at 6AM.
These custom plugins are for monitoring other services.
We had a call with the vendor and they said that SSH can't be enabled and the Nagios client can't be installed either.
Can you please suggest another way to monitor this?
The suggestion provided by the vendor is to provide access to a service account on the share and then run a powershell script that uses the credentials of the service account to check if the file exists.
Can you please suggest if we have a custom powershell script for such monitoring?
Re: File Monitoring - Linux mount point
Posted: Tue Sep 22, 2020 9:29 am
by lmiltchev
Writing custom scripts is out of scope of Nagios support, however here's a simple PS script that can get you started:
Code: Select all
# PowerShell Checks If a *.dat File Exists
$WantFile = "D:\TEMP\*.dat"
$ok = 0
$warning = 1
$FileExists = Test-Path $WantFile
if ($FileExists -eq $True) {
Write-Host "WARNING: File with extension *.dat exists"
exit $warning
} else {
Write-Host "OK: No file at this location"
exit $ok
}
Here's an example of the output, when testing the script in the PS terminal:
There was no file with an extension *.dat in the D:\TEMP directory
Code: Select all
PS C:\Program Files\NSClient++\scripts> .\check_dat_file.ps1
OK: No file at this location
I added test.dat file to D:\TEMP directoty
Code: Select all
PS C:\Program Files\NSClient++\scripts> .\check_dat_file.ps1
WARNING: File with extension *.dat exists
You can modify the script by setting the path to the directory, where the .dat files should/should not show up at 6 am. You can change when to get "ok" or "warning", etc. You can run your check at around 6:00 am every day, and get the results back.
Again, this is out of scope, and it is on you to set this up. I hope these notes can help you out and get you started. Thanks!