Sysadmin's Shouts!

a blog for sysadmin's rants and raves…


Leave a comment

Nagios Plugin for UNIX released

I have released a nagios plugin written in shell script to check if a filesystem is mounted under a UNIX & Linux OS, and it has been posted today in nagios exchange.

It’s a simple-written script in Unix shell, to make it compatible across a bigger number of operating systems, basically it checks if a file system is mounted with a vanilla “mount” command, and checks to see if the fs type matches the result with a grep. If the filesystem is mounted more than once, it gives a warning message with the number of times the FS is mounted under parentheses.

I have checked that it is compatible under the following UNIX, UNIX-like & Linux platforms:

IBM AIX v7.1, v6.1, v5.2 
RHEL v6.6, v4.8, RHL v9 
Ubuntu v10.04.4 LTS 
SuSe v11 
CentOS v6.6, v6.5 
CygWin v2.5.1, v2.0.4 & BusyBox v1.22.1 
Oracle Solaris x86 v11.3, v10 
SCO OpenServer v6.0.0 
SCO UnixWare v7.1.4+, v7.1.4

The plugin description is the following:

Shell Script for Nagios, checks if the FS passed on $1 is mounted under Mount Type $2. 
If no parameter passed on $2 NFS type is assumed by default. 
This script does not check fstab or /etc/filesystem or other tab entries, 
as it is designed to consume as little CPU time as possible and to be used in different 
OS types. 

It is a simple script, but it detects mounts of practically any type of FS, 
and multiple instances mounted of the same FS. 

Released under GPLv3. Author: Carlos Ijalba - 2016.

Alerts given to Nagios: 

OK - "/exports" mounted under "NFS". 
CRITICAL - "/exports" not mounted under "NFS". 
WARNING - "/exports" is mounted several times! (3) 

------------- 

USE: 
check_mount.sh [ $1 - Filesystem ] | optional: [ $2 - Type (NFS by default)] 

Reports: 
OK - $1 mounted under $2. 
CRITICAL - $1 not mounted under $2. 
WARNING - $1 is mounted several times! (number of times mounted) 

Examples: 
check_mount.sh /developer/logs <-- check NFS mount of /developer/logs 
check_mount.sh /developer cifs <-- check CIFS mount of /developer 
check_mount.sh /ora12c nfs4 <-- check NFSv4 mount of /ora12c 
check_mount.sh /db2 ext3 <-- check EXT3 mount of /db2 
check_mount.sh /CICS jfs2 <-- check JFS2 mount of /CICS 

The script’s code is as follows:

#!/bin/sh
#
 Copyright="(C) 2016 - Carlos Ijalba GPLv3" # <perkolator @ gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################################################################
#
# Program: check_mount.sh
#
# Parameters:
#   $1 - FS to check --MANDATORY--
#   $2 - Mount type [ nfs3 | nfs4 | cifs | jfs2 | procfs | ext3 | ext4... ] --OPTIONAL-- (NFS by default)
#
# Output:
#   3 - Error: No FS passed on parameter $1.
#   2 - CRITICAL: FS not OK, the FS specified is not mounted by $2.
#   1 - WARNING: FS not OK, the FS specified is mounted several times (it might not be a problem).
#   0 - OK: FS OK, the FS specified has an instance mounted under $2 mount type.
#
# Description:
#
# Shell Script for Nagios, checks if the FS passed on $1 is mounted under Mount Type $2. If no parameter passed on $2
# NFS type is assumed by default. This script do not check fstab or /etc/filesystem or other tab entries, as it is
# designed to consume as little CPU time as possible and to be used in different OS types.
#
# It is a simple script, but it detects mounts of practically any type of FS, and multiple instances mounted of the same FS.
#
# Verified compatible with the following OS:
#   IBM AIX v7.1, v6.1, v5.2
#   RHEL v6.6, v4.8, RHL v9
#   Ubuntu v10.04.4 LTS
#   SuSe v11
#   CentOS v6.6, v6.5
#   CygWin v2.5.1, v2.0.4 &amp; BusyBox v1.22.1
#   Oracle Solaris x86 v11.3, v10
#   SCO OpenServer v6.0.0
#   SCO UnixWare v7.1.4+, v7.1.4
#
# Versions Date Programmer, Modification
# ------------ ---------- ----------------------------------------------------
# Version=1.00 # 03/06/2016 Carlos Ijalba, Original version.
  Version=1.01 # 10/06/2016 Carlos Ijalba, GPLv3 open source release.
#
########################################################################################################################
#set -x

# Constants
NAGIOS_ERROR=3
NAGIOS_CRIT=2
NAGIOS_WARN=1
NAGIOS_OK=0

# Usage
if [ $# -lt 1 ]
 then
 cat << EOF
check_mount.sh v$Version - $Copyright

 ERROR - No FS passed under parameter \$1

 USE:
   check_mount.sh [ \$1 - Filesystem ] | optional: [ \$2 - Type (NFS by default)]

 Reports:
   OK - \$1 mounted under \$2.
   CRITICAL - \$1 not mounted under \$2.
   WARNING - \$1 is mounted several times! (number of times mounted)

 Examples:
   check_mount.sh /developer/logs &lt;-- check NFS mount of /developer/logs
   check_mount.sh /developer cifs &lt;-- check CIFS mount of /developer
   check_mount.sh /ora12c nfs4 &lt;-- check NFSv4 mount of /ora12c
   check_mount.sh /db2 ext3 &lt;-- check EXT3 mount of /db2
   check_mount.sh /CICS jfs2 &lt;-- check JFS2 mount of /CICS

EOF
 RC=$NAGIOS_ERROR
 exit $RC
fi
FS=$1

# Main

MOUNT=$2
if [ -z "$MOUNT" ]
 then
   MOUNT="nfs" # if $2 not specified, assume NFS by default
fi

MOUNTED=`mount | grep $MOUNT | grep $FS | wc -l | tr -s " "` # execute the command to check the mount...

if [ $MOUNTED -eq 0 ]; then
   MSG="CRITICAL - $FS not mounted under $MOUNT."
   RC=$NAGIOS_CRIT
 elif [ $MOUNTED -eq 1 ]; then
   MSG="OK - $FS mounted under $MOUNT."
   RC=$NAGIOS_OK
 else
   MSG="WARNING - $FS is mounted several times! ($MOUNTED)"
   RC=$NAGIOS_WARN
fi

echo $MSG
exit $RC

# End

I hope it is of use to somebody, if you have any doubts or problems with it, just give the sysadmin a shout!!!
You can check my plugin at nagios exchange here:

Check if FS is Mounted (check_mount.sh) AIX, NFS, UNIX, Linux, Solaris

 

And for more filesystem plugins from nagios exchange, visit:

https://exchange.nagios.org/directory/Plugins/System-Metrics/File-System

 

 

Advertisements


Leave a comment

HowTo: detect and connect to Oracle / Sun Microsytems ILOMs (Integrated Lights Out Manager)

Prereqs:

· A laptop PC (with windows)
· NetScan from Softperfect (it’s free for personal & professional use)
· An ethernet cable (ie: cat5-6, normal cable -no crossover needed-)

Steps:

1.- If you haven’t done it already, go to Softperfects web and download the latest version of NetScanner.
Why I like this program? well, it’s free, it’s portable (I love portables BTW), it’s one of the best scanners that I have seen, and it’s free (did I say that already?).

2.- Conect your laptop to the “Net Mgmt” ethernet port of your server, and change your laptop’s local IP address to 192.160.1.2, with a gateway of 192.168.1.1.

3.- Open NetScan, let it identify your NICs IP network, and start the scan.

ILOM_detect_01

4.- As soon as you have 2 entries displayed on NetScan, you can save time and pause the scan process.

ILOM_detect_02

5.- Select the last IP shown, and right click, open as Secure HTTP (HTTPS).

ILOM_detect_03

6.- Voilá, You may get a certificate error, ignore that, and you will be able to login;

ILOM_detect_04

a browser windows should have opened with the ILOM login’s page.

ILOM_detect_05
remember that the default user/password to access is root/changeme.

7.- Now you can do what you wanted to do in the ILOM, log off, and go for another server…

ILOM_detect_06

HowTo: Find out Nagios Configuration Files

Leave a comment

It looks simple, and it should be, but as it goes, I have seen installations with different nagios versions & configurations.

In one particularly hairy case, the administrators had been migrating from one version to other, and to be on the safe side, they just installed the new nagios version in a different folder, say nagios3, but because some of the checks migrated to the new version where broken, somebody fixed them by pointing to the scripts and config files from the previous version, instead of fixing or replacing the ones in the new nagios3 folder. (Nice!)

So they ended up with a nagios folder, and nagios3 folder…

The thing is: Nagios works. And by following the rule: “If it ain’t broke, don’t fix it”, nobody has done anything with the nagios install.

What happens when you want to upgrade to a newer nagios version like nagios 4? -well, you will probably have lots of fun…


So I will just describe in some easy steps how to find out the correct config files that the “good nagios set” is using, and what is not being used & it has just been left there from previous installs or configurations.

1.- Locate the nagios binary and it’s good config file.

[root@nagserv ~]# ps -ef | grep nagios

nagios 2026 1 0 18:15 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

2.- Navigate to the path where that config file resides.
cd /usr/local/nagios/bin

3.- Execute a Nagios validation, this step must be done every time that we modify/add something in nagios, as it checks the configuration files integrity.

Note: if we don’t want to validate the integrity, just remember that nagios won’t start if it has errors, and next time the nagios service gets restarted or a new one spawn off, it will just throw back errors, until these get fixed.

./nagios -v /usr/local/nagios/etc/nagios.cfg

Once nagios does the config validation, it will report in all config files used in the actual nagios running state.

Nagios Core 3.3.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 07-25-2011
License: GPL

Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/contactgroups.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/hosts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/dependencies.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/www_xxx.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvaaa.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvbbb.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/servnew.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvdb.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvmsg.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvapp.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvtsm.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvsap1.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvapp2.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/nagservios.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvdb2.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvtraps.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvunk.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/OLD'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvccc.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/servddd.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SRV/srvpre.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/NETWORK'... &lt;-- Empty directory (for nagios)
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/Switch_03.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/Switch_04.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/SAN01.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/SAN02.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/Switch_02.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/Switch_01.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/OLD'... &lt;-- Empty directory (for nagios)
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-1.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-2.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/cmm-1.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-8.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/cmm-2.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-9.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-10.cfg'...
Processing object config directory '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/OLD'... &lt;-- Empty directory (for nagios)
Processing object config file '/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/sp-xxx.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/nagserv/hostgroups.cfg'...
Read object config files okay...
---cut---
4.- From the validation, we can see that most nagios objects are stored in the path /usr/local/nagios/etc/objects
so, we have a look there:
cd /usr/local/nagios/etc/objects
ls -l
total 96

-rw-r--r-- 1 nagios nagios 8362 Oct 1 2013 commands.cfg
-rw-r--r-- 1 nagios nagios 8362 Oct 1 2013 commands.cfg.bak
-rw-rw-r-- 1 nagios nagios 2167 Oct 11 2013 contacts.cfg
-rw-rw-r-- 1 nagios nagios 5441 Aug 6 2013 localhost.cfg
drwxrwxr-x 2 nagios nagios 4096 Nov 12 2013 nagios3
-rw-rw-r--. 1 nagios nagios 3124 Apr 4 2012 printer.cfg

drwxrwxr-x 3 nagios nagios 4096 Sep 9 17:45 nagserv
-rw-rw-r--. 1 nagios nagios 3293 Apr 4 2012 switch.cfg
-rw-rw-r-- 1 nagios nagios 11225 Apr 4 2012 templates.cfg
-rw-rw-r--. 1 nagios nagios 10812 Apr 4 2012 templates.cfg.original
-rw-rw-r-- 1 nagios nagios 4428 Sep 9 18:38 timeperiods.cfg
-rw-rw-r-- 1 nagios nagios 1221 Nov 26 2013 timeperiods.cfg.old.bz2
-rw-rw-r-- 1 nagios nagios 4037 Aug 13 2013 timeperiods.cfg.wip

-rw-rw-r--. 1 nagios nagios 4019 Apr 4 2012 windows.cfg

5.- The files in red are not being used by nagios (specially important is nagios3 directory, which in this case contains lots of config files for alarms, hosts, etc, and it’s not being used anymore).

The directory nagserv, is where all the good config files are stored.

So, if we wanted to do a bit of cleanup, we could safely delete the following folders:

/usr/local/nagios/etc/objects/nagserv/HOSTS/NETWORK
/usr/local/nagios/etc/objects/nagserv/HOSTS/SAN/OLD
/usr/local/nagios/etc/objects/nagserv/HOSTS/SP/OLD
/usr/local/nagios/etc/objects/nagios3

Before that tho, might as well double check that they don’t contain any files, or backup the folders with TSM or whatever backup product you use, and then delete them.
Having folders lying around without a good use, it’s bound to be counterproductive soon or later.

So there you go, we’ve identified the good folders and .cfg files used by nagios; any other file that does not use a .cfg extension, won’t be picked up by nagios (all the files listed here with extensions like: cfg.bak, cfg.original, cfg.old.bz2, cfg.wip, etc, are just backups of the real config files).

This gallery contains 0 photos