Wednesday, March 28, 2012

Nagios

Howto create custom Nagios Plugins using Python in 3 steps.

http://www.ibm.com/developerworks/aix/library/au-nagios/

http://www.linux-mag.com/id/7706/

The following procedures will create a localhost cpu load check using Python on CentOS.

1)Create the service check that will call your plug-in.

vi /etc/nagios/objects/localhost.cfg and add this code block-
#2012Mar27
#
#Testing
define service{
use local-service
host_name localhost
service_description Python LoadAverage
check_period 24x7
notification_options c,r
notifications_enabled 0
check_command check_mygetloadavg
}


2)Register the plugin with Nagios and give its path.

vi /etc/nagios/objects/commands.cfg and add this code block-
#2012Mar28
#
#Test plugin using a Python script.
define command{
command_name check_mygetloadavg
command_line /usr/lib64/nagios/plugins/check_nagios_host_cpuload.py
}


3)Create the plugin.

vi /usr/lib64/nagios/plugins/check_nagios_host_cpuload.py

#!/usr/bin/env python
#2012Mar23
#
#Python script to check Nagios server cpu load average.
#
#http://www.ibm.com/developerworks/aix/library/au-nagios/
#
#Exit Codes
#exit code 0 = service is working properly.
#exit code 1 = service in a Warning state.
#exit code 2 = service in a Critical state.
#exit code 3 = service in an Unknown state.
#
import os.sys
(d1, d2, d3) = os.getloadavg()
if d1 >= 5.0:
print "GETLOADAVG CRITICAL: Load avg is %.2f" % (d1)
sys.exit(2)
elif d1 >= 2.0;
print "GETLOADAVG WARNING: Load avg is %.2f" % (d1)
sys.exit(1)
else:
print "GETLOADAVG OK: Load avg is %.2f" % (d1)
sys.exit(0)

Set the permissions- -rwxr-xr-x 1 root root 639 Mar 28 20:50 check_nagios_host_cpuload.py

Save all files. Check for errors-
nagios -v /etc/nagios/nagios.cfg
If error free then restart Nagios-
service nagios reload.

Open your Nagios dashboard and the new check will exist and is active.


Monday, March 26, 2012

Scripting

Create a script to monitor a process. There are many ways to accomplish it. I like to keep it simple for maintenance reasons. I create the script and then create a cron job to run it periodically.


Step 1)Create the shell script. Include comments such as date created, brief explanation of what it does, and name of file.
#!/bin/bash
#
#2012Mar26
#
#check.process.sh
#
#This script checks if xyz process is running on localhost.
#If running, then do nothing. If not running, send
#email alert.
`if ! pgrep -f "/usr/bin/xyz"; then /bin/mail -s "Alert! XYZ Process not running!" me@email.com > /home/user/logs/cron.check.txt

Note-Don't forget to give the script executable permissions, chmod 755 check.process.sh




Step 2)Create the cron job, crontab -e
# m h dom mon dow command
#
#Check if xyz process is running-/usr/bin/xyz
15 * * * * /home/user/scripts/check.process.sh


Done.

Thursday, March 8, 2012

Monitoring

I get asked frequently about free website monitoring services. Here are two that I use frequently to monitor small to medium sized websites which I'm involved with. Both offer free standard monitoring checks with an upgrade option if you want reporting, internal monitoring, etc.


http://www.monitor.us
http://www.internetseer.com

Monday, March 5, 2012

vCenter 5.0

I installed VMware's vCenter 5.0 on a couple of servers recently. It was straight forward and relatively painless. Read some articles at http://virtualizationadmin.com/ before you begin. They contain great advice and suggestions. These two saved me alot of time and answered questions I had.

VMware vCenter Design and Installation Options

Getting Starting with the vSphere 5 vCenter Server Appliance