Hi All,<br><br>I've just written a check_sendmail plugin shell script for Solaris; I'm wondering if anyone has any thoughts for improving it (be as pedantic as you like), problems with it, etc. Alternatively, if anyone wants to use it themselves.
<br><br>To use the plugin via nrpe<br><br>** you must give the nagios user on the remote host<br>** you must give the nagios user sudo access to run this script as root without password<br><br>Kind Regards,<br>Alex<br><br>
#!/bin/ksh<br># check_sendmail<br># author: alex harvey<br># email: <a href="mailto:alexh19740110@gmail.com">alexh19740110@gmail.com</a><br><br>die=false<br>OS=`uname -r`<br><br># first check status according to SMF if we're in Solaris 10
<br>if [ "$OS" == "5.10" ]; then<br>   svcs -l sendmail >|/tmp/check_sendmail.tmp.1 2>&1<br>   smf_enabled=`cat /tmp/check_sendmail.tmp.1 | awk '{if ($1 == "enabled") print $2}'`<br>
   smf_state=`cat /tmp/check_sendmail.tmp.1 | awk '{if ($1 == "state") print $2}'`<br>   if [ "$smf_enabled" == "false" ]; then<br>      echo WARNING [ Disabled by SMF ]<br>      exit 1<br>   fi
<br><br>   # $smf_enabled must be "true"<br>   if [ "$smf_state" != "online" ]; then<br>      echo WARNING [ SMF reports state $smf_state ]<br>      exit 1<br>   fi<br><br>   # $smf_enabled must be "true" and $smf_state must be "online"
<br>   sendmail_pid_file=/var/run/sendmail.pid<br>   client_pid_file=/var/spool/clientmqueue/sm-client.pid<br>   if [ ! -e $sendmail_pid_file ]; then<br>      messpart1="and $sendmail_pid_file "<br>      die=true
<br>   fi<br>   if [ ! -e $client_pid_file ]; then<br>      messpart1="$messpart1 and $client_pid_file"<br>      die=true<br>   fi<br>   messpart1=`echo $messpart1 | sed -e 's/^and //'`<br>   mess1="$messpart1 not found!"
<br>   [ $die == "true" ] && echo CRITICAL [ $mess1 ] && exit 2<br>fi<br><br># now check that both processes are running<br>sendmail_pid=`cat /var/run/sendmail.pid | head -1`<br>sendmail_cmd=`cat /var/run/sendmail.pid | tail -1`
<br>client_pid=`cat /var/spool/clientmqueue/sm-client.pid | head -1`<br>client_cmd=`cat /var/spool/clientmqueue/sm-client.pid | tail -1`<br>ps -ef | egrep "${sendmail_pid}.*${sendmail_cmd}" >/dev/null 2>&1
<br>RC1=$?<br>ps -ef | egrep "${client_pid}.*${client_cmd}" >/dev/null 2>&1<br>RC2=$?<br>if [ $RC1 -ne 0 ]; then<br>   messpart2="and daemon "<br>   die=true<br>fi<br>if [ $RC2 -ne 0 ]; then<br>
   messpart2="$messpart2 and client"<br>   die=true<br>fi<br>messpart2=`echo $messpart2 | sed -e 's/^and //'`<br>mess2="sendmail $messpart2 is not running!"<br>[ $die == "true" ] && echo CRITICAL [ $mess2 ] && exit 2
<br><br># otherwise exit OK<br>echo OK && exit 0<br><br>