Outils personnels

Check service.sh : Différence entre versions

De wikiGite

Ligne 5 : Ligne 5 :
 
  # FSo 2010
 
  # FSo 2010
 
  # check services that can't be check by monit (ex : no pid file and no network port)
 
  # check services that can't be check by monit (ex : no pid file and no network port)
# v1.0 : creation avec surveillance monit et ossec
 
 
  # First : monit itself !
 
  # First : monit itself !
  /etc/init.d/monit status > /dev/null 2>&1
+
  # Debian :
 +
BIN_MAIL=/usr/sbin/sendmail
 +
SENDER_MAIL=$(hostname -s)
 +
REPORT_EMAIL=support@systea.net
 +
if [ -e /etc/debian_version ]
 +
then
 +
    ps -p $(cat /var/run/monit.pid) > /dev/null 2>&1
 +
else
 +
# CentOS :
 +
    /etc/init.d/monit status > /dev/null 2>&1
 +
fi
 
  if [ $? -ne 0 ]
 
  if [ $? -ne 0 ]
 
  then
 
  then
 
     /etc/init.d/monit restart > /dev/null 2>&1
 
     /etc/init.d/monit restart > /dev/null 2>&1
 +
    logger "Check_services.sh restarting Monit"
 +
    (
 +
    echo "Subject: [Check services] : monit restarted"
 +
    echo ""
 +
    echo "Status of service :"
 +
    monit summary
 +
    ) | $BIN_MAIL -F$SENDER_MAIL $REPORT_EMAIL
 
  fi
 
  fi
+
 
 
  # OSSEC don't have standard pid files
 
  # OSSEC don't have standard pid files
 
  OSSEC_DIR=/opt/ossec
 
  OSSEC_DIR=/opt/ossec
 
  OSSECPROC=0
 
  OSSECPROC=0
  for pidfile in $(ls $OSSEC_DIR/var/run/*.pid)
+
  ls $OSSEC_DIR/var/run/*.pid > /dev/null 2>&1
do
+
if [ $? -eq 0 ]
    ps -p $(cat $pidfile) | grep ossec > /dev/null 2>&1
+
then
    if [ $? -ne 0 ]
+
  for pidfile in $(ls $OSSEC_DIR/var/run/*.pid)
    then
+
  do
      OSSECPROC=1
+
      ps -p $(cat $pidfile) | grep ossec > /dev/null 2>&1
     fi
+
      if [ $? -ne 0 ]
done
+
      then
 +
        OSSECPROC=1
 +
      fi
 +
  done
 +
else
 +
     OSSECPROC=1
 +
fi
 +
 
 
  if [ $OSSECPROC -eq 1 ]
 
  if [ $OSSECPROC -eq 1 ]
 
  then
 
  then
 
     /etc/init.d/ossec restart
 
     /etc/init.d/ossec restart
 +
  logger "Check_services.sh restarting Ossec"
 +
  (
 +
    echo "Subject: [Check services] : ossec restarted"
 +
    echo ""
 +
    echo "Status of processes (must return 6 processes running) :"
 +
    /etc/init.d/ossec status
 +
    ) | $BIN_MAIL -F$SENDER_MAIL $REPORT_EMAIL
 
  fi
 
  fi
  

Version du 6 avril 2011 à 06:45

Script de surveillance des services qui ne peuvent pas l'être avec monit
(pas de fichier pid, et/ou pas de port réseau à surveiller)

#!/bin/bash
# FSo 2010
# check services that can't be check by monit (ex : no pid file and no network port)
# First : monit itself !
# Debian :
BIN_MAIL=/usr/sbin/sendmail
SENDER_MAIL=$(hostname -s)
REPORT_EMAIL=support@systea.net
if [ -e /etc/debian_version ]
then
   ps -p $(cat /var/run/monit.pid) > /dev/null 2>&1
else
# CentOS :
   /etc/init.d/monit status > /dev/null 2>&1
fi
if [ $? -ne 0 ]
then
   /etc/init.d/monit restart > /dev/null 2>&1
   logger "Check_services.sh restarting Monit"
   (
    echo "Subject: [Check services] : monit restarted"
    echo ""
    echo "Status of service :"
    monit summary
    ) | $BIN_MAIL -F$SENDER_MAIL $REPORT_EMAIL
fi
# OSSEC don't have standard pid files
OSSEC_DIR=/opt/ossec
OSSECPROC=0
ls $OSSEC_DIR/var/run/*.pid > /dev/null 2>&1
if [ $? -eq 0 ]
then
  for pidfile in $(ls $OSSEC_DIR/var/run/*.pid)
  do
     ps -p $(cat $pidfile) | grep ossec > /dev/null 2>&1
     if [ $? -ne 0 ]
     then
        OSSECPROC=1
     fi
  done
else
   OSSECPROC=1
fi
if [ $OSSECPROC -eq 1 ]
then
   /etc/init.d/ossec restart
  logger "Check_services.sh restarting Ossec"
  (
   echo "Subject: [Check services] : ossec restarted"
   echo ""
   echo "Status of processes (must return 6 processes running) :"
   /etc/init.d/ossec status
   ) | $BIN_MAIL -F$SENDER_MAIL $REPORT_EMAIL
fi

A intégrer (par un lien) à /etc/cron.hourly ou /etc/cron.quarter-hourly

cd /etc/cron.hourly/
ln -s /opt/systools/check_services.sh check_services