Aug 11, 2011

check_windows_processes.pl - Nagios Plugin to monitor multiple Windows processes

Recently I was required to monitor multiple SQL Server processes on a Windows box. Nagios comes bundled with a very cool utility called check_snmp_process which is the ultimate choice for such requests. Unfortunately, it could monitor only one process at a time, so monitoring five processes would mean five different service check definitions, five different checks at five different intervals. Sounds too much of work, isn't it? Inspired by check_snmp_storage, another ultra-cool utility by the same author, I decided to write my own plugin to monitor multiple Windows processes in one run and came up with check_windows_processes.pl

This Perl plugin requires Net::SNMP library to query monitored Windows host. It is also capable of generating shiny PNP graphs.

Plug-in Parameters

  -H      Hostname or IP address of the monitored host
  -C      SNMP Community
  -P      Comma separated list of Windows processes to check
  -l      Long output, includes process names and instance count
  -f      Include performance data to generate graphs
  -h      Display the help and exit

Examples

Basic single process monitoring

$ check_windows_processes -H mssql.example.com -C public -P sqlservr.exe
Processes OK

Basic multiple process monitoring

$ check_windows_processes -H mssql.example.com -C public -P sqlservr.exe,sqlagent.exe,sqlbrowser.exe,sqlwriter.exe
Processes OK

with long output (-l)

$ check_windows_processes -H mssql.example.com -C public -P sqlservr.exe,sqlagent.exe,sqlbrowser.exe,sqlwriter.exe -l
OK: Processes sqlbrowser.exe(1), sqlservr.exe(2), sqlwriter.exe(1), sqlagent.exe(1) are running

with performance data (-f)

$ check_windows_processes -H mssql.example.com -C public -P sqlservr.exe,sqlagent.exe,sqlbrowser.exe,sqlwriter.exe -f
Processes OK | sqlbrowser.exe=1;;0;; sqlservr.exe=2;;0;; sqlwriter.exe=1;;0;; sqlagent.exe=1;;0;;

with performance data and long output (-lf)

$ check_windows_processes -H mssql.example.com -C public -P sqlservr.exe,sqlagent.exe,sqlbrowser.exe,sqlwriter.exe -lf
OK: Processes sqlbrowser.exe(1), sqlservr.exe(2), sqlwriter.exe(1), sqlagent.exe(1) are running | sqlbrowser.exe=1;;0;; sqlservr.exe=2;;0;; sqlwriter.exe=1;;0;; sqlagent.exe=1;;0;;

a process is down

$ check_windows_processes -H mssql.example.com -C public -P sqlservr.exe,sqlagent.exe,w3wp.exe -f
CRITICAL: Process w3wp.exe not running | w3wp.exe=0;;0;; sqlservr.exe=2;;0;; sqlagent.exe=1;;0;;

multiple processes are down

$ check_windows_processes -H mssql.example.com -C public -P sqlservr.exe,w3wp.exe,dns.exe -f
CRITICAL: Processes dns.exe, w3wp.exe not running | w3wp.exe=0;;0;; sqlservr.exe=2;;0;; dns.exe=0;;0;;

Configuration

If you have defined your own configuration standard then you may want to skip the following, otherwise this is how I have configured the plugin to monitor multiple Microsoft SQL Server processes.

I am assuming that you have Nagios installed under /usr/local/nagios directory.

Copy the plugin in /usr/local/nagios/libexec

Edit /usr/local/nagios/nagios/etc/commands.cfg and append the following

define command {
command_name check-windows-processes
command_line $USER1$/check_windows_processes.pl -f -H $HOSTADDRESS$ -C $ARG1$ -P $ARG2$
}

Create a new service template in /usr/local/nagios/etc/servicetemplates.cfg

define service {
name                   xi_windows_processes
service_description    MS SQL Server Processes Monitoring
use                    generic-service
check_period           24x7
notification_options   w,r,c
max_check_attempts     3
check_interval         15
retry_interval         1
notification_interval  60
contacts               windowsadmins,it-managers,servicedesk
register               0
}
NOTE: Make sure you have the correct SNMP community, which is set to public in the above template under check_command directive. Edit the service file for the host you want to monitor the processes. For example /usr/local/nagios/etc/services/mssql.example.com.cfg

define service {
host_name             mssql.example.com
service_description   MSSQL Processes
use                   xi_windows_processes
check_command         check-windows-processes!public!sqlagent.exe,sqlservr.exe,sqlwriter.exe
register              1
}

Download

https://github.com/foo-co-in/check_windows_processes.pl

0 comments:

Post a Comment

Tu comentario será moderado la primera vez que lo hagas al igual que si incluyes enlaces. A partir de ahi no ser necesario si usas los mismos datos y mantienes la cordura. No se publicarán insultos, difamaciones o faltas de respeto hacia los lectores y comentaristas de este blog.