I need to remotely periodically check if a Linux file system is mounted read only on lots of servers. The only tools at my disposal in this instance are the usual CLI scripting languages (BASH/Perl/Python), SSH and SNMP.
My thoughts so far are:
- Share SSH key and execute the mount command remotely, grep/awk-ing for the RO flag on the given mountpoint.
- Check via SNMP, although I'm not certain if this information is available or how easy that is.
- Attempt to SCP a file across, or remotely touch a file.
The SNMP method is the nicest/cleanest I can think of, however I'm at a loss on how to do this as CLI SNMP seems like a nightmare, especially if I need to run through a decision process to find an index based on a given mountpoint.
Ideally I'd like to pull this off using only BASH (inc. sed/awk/grep etc) and SNMP but need some guidance on where to begin! snmpd is already instaled and configured for v2 on all the servers in question.
The final use of this script will be as a Nagios command.
Many thanks in advance for any help!
Note We already have cacti/nagios set up monitoring 100s of servers, I forget to mention this when originally posting!
In your
snmpd.conf
check out the exec argument. I use this to remotely poll the usercount of some of my IRC servers, like this:To poll this you snmpwalk .1.3.6.1.4.1.2021.8, and would get something like this:
Check the Extending Agent Functionality part of http://linux.die.net/man/5/snmpd.conf for further details!
Edit 1:
UCD-SNMP-MIB:dskTable contains information about mounted volumes and usage. It is located under OID .1.3.6.1.4.1.2021.9 and documented at:
http://www.oidview.com/mibs/2021/UCD-SNMP-MIB.html
http://www.net-snmp.org/docs/mibs/ucdavis.html#dskTable
But I see now it doesn't contain mountflags, so you can't see read only there. Gah. Back to the script above and how to call it! :P
For most "how do I do X in nagios?", you'll find that someone has already written a plugin that will do all of, or at least some of, what you need.
In this case, you could probably use check_ro_mounts in combination with the 'negate' plugin (part of standard nagios plugins), or just modify it to suit your needs:
http://exchange.nagios.org/directory/Plugins/Uncategorized/Operating-Systems/Linux/check_ro_mounts/details
Another way is to use Perl's, Ruby's Net::SSH or Python's paraminko libraries to remotely login and (no need to setup keys beforehand) then parse the contents of the 'mount' command.
Management and confirmation of mount points and their flags could be handled through Puppet. See How to manage mounted partitions (fstab + mount points) from puppet