Anderson Jacson </a>  
Login

Menu

4 visitantes online (1 na seção: Artigos e Dicas)

Usuários: 0
Visitantes: 4

mais...

SmartSection is developed by The SmartFactory (http://www.smartfactory.ca), a division of INBOX Solutions (http://inboxinternational.com)
Linux > Monitorar Ritta CMC com o Nagios
Monitorar Ritta CMC com o Nagios
Publicado por Anderson em 18/8/2010 (1927 leituras)
Monitorar Ritta CMC com o Nagios
 
Para monitorar você vai precisar de três scripts, um meio que geral, outro para temperatura e outro para umidade.
No meu caso eles estão dentro de /usr/lib/nagios/plugins/
 
 
  •  check_temp_cmc.sh

#!/bin/bash
#
# - Check Rittal CMC-TC temperature status from I/O units and from LCP units.
# - CMC-TC needs webinterface enabled
# - Uses curl to fetch html-page from CMC-TC, supports I/O units and Rittal LCP unit
# - Easy to check LCP temperatures and I/O unit's temperature sensor etc.
#
# Version: 1.0.2
# Author: Pekka Panula, pekka.panula@sofor.fi
# Dated: 27.6.2008
# License: GPLv2
# (c) 2008 Pekka Panula / Net Servant Oy
# Requirements: curl, grep, tr, cut (=coreutils), sed


returnStatus=3
pluginError=0
curl_options="--connect-timeout 5 --silent --anyauth"

# - Change username and password -
username=cmc
password=cmc
# - - - - - - - - -

# cmc_variable="3101" # first module, first variable

if [ ! "$1" = "-H" ]; then
pluginError=1
elif [ ! "$3" = "-w" ]; then
pluginError=1
elif [ ! "$5" = "-c" ]; then
pluginError=1
elif [ ! "$7" = "-V" ]; then
pluginError=1
fi

cmc_variable=$8

TEMPERATURE=$(curl ${curl_options} "http://${username}:${password}@$2/cmcget.cgi?${cmc_variable}" | grep "bb12l style=\"color:\#[F0-9][F0-9][0-9][0-9][0-9][0-9]\"" | cut -d\> -f2|cut -dd -f1|sed 's/\W//g')

if [ "$pluginError" -eq "0" ]; then
# echo $TEMPERATURE
case "$TEMPERATURE" in
*[^0-9]*) echo "WARNING - Result not a temperature: $TEMPERATURE"; exit 1 ;;
esac
if [ "$TEMPERATURE" == "" ]; then
echo "WARNING - Cant read temperature"
returnStatus=1
elif [ "$TEMPERATURE" -ge $6 ]; then
echo "CRITICAL - Temperatura $TEMPERATURE C"
returnStatus=2
elif [ "$TEMPERATURE" -ge $4 ]; then
echo "WARNING - Temperatura $TEMPERATURE C"
returnStatus=1
else
echo "OK - Temperatura $TEMPERATURE C"
returnStatus=0
fi
else
echo "Rittal CMC-TC Temperature check for Nagios, v$version (c) 2008 Pekka Panula / Net Servant Oy"
echo "License: GPLv2"
echo "Usage: rittal_temp.sh -H host -w warn -c critical -V variable"
echo " - variable: eg. 3304, 3. module 4. variable, etc"
echo ""
echo "Example: ./rittal_temp.sh -H 192.168.0.2 -w 28 -c 32 -V 3104"
returnStatus=3
fi

exit $returnStatus


 

 

  •  check_cmc.sh

#!/bin/bash
#
# - Check Rittal OK/Alarm status from any module, which uses OK/Alarm status
# - CMC-TC needs webinterface enabled
# - Uses curl to fetch html-page from CMC-TC, supports I/O units and Rittal LCP unit
# - Easy to check eg. smoke detector status, emergency waterpump status and LCP alarm and warning, etc.
#
# Version: 1.0.3
# Author: Pekka Panula, pekka.panula@netservant.fi
# Dated: 9.1.2009
# License: GPLv2
# (c) 2008-2009 Pekka Panula / Net Servant Oy
# Requirements: curl, grep, tr (=coreutils)
# Changelog:
# v1.0.3: Added support for Rittal ISDN-unit. Thanks for Ralf Begemann for a tip.
# v1.0.2: Really fixed bug: grepping failed when status was alarm state.
# v1.0.1: fixed bug, grepping failed when status was not ok. Thanks for Sebastian Krolzig for reporting it.

version="1.0.3"
returnStatus=3
pluginError=0
curl_options="--connect-timeout 5 --silent --anyauth"

# - Change username and password -
username=cmc
password=cmc
# - - - - - - - - - -

# cmc_variable="3103" # = 1. module, 3. variable
# name="Alarm Message"

## TODO: Make better command line handler

if [ ! "$1" = "-H" ]; then
pluginError=1
elif [ ! "$3" = "-V" ]; then
pluginError=1
elif [ ! "$5" = "-N" ]; then
pluginError=1
fi

toUpper() {
echo $1 | tr "[:lower:]" "[:upper:]"
}

cmc_variable=$4
name=$6

if [ "$pluginError" -eq "0" ]; then

STATUS=$(curl ${curl_options} "http://${username}:${password}@$2/cmcget.cgi?${cmc_variable}" | grep "bb12l style=\"color:\#[F0-9][F0-9][0-9][0-9][0-9][0-9]\"")
STATUS=`toUpper "$STATUS"`

if [ "$STATUS" == "" ]; then
echo "WARNING - Cant read $name status"
returnStatus=1
elif [[ "$STATUS" =~ "ALARM" ]]; then
echo "CRITICAL - $name alarm"
returnStatus=2
elif [[ "$STATUS" =~ "LOCKED" ]]; then
echo "OK - $name OK"
returnStatus=0
elif [[ "$STATUS" =~ "OK" ]]; then
echo "OK - $name OK"
returnStatus=0
elif [[ "$STATUS" =~ "O.K." ]]; then
echo "OK - $name OK"
returnStatus=0
else
echo "UNKNOWN - $name Status: $STATUS"
returnStatus=1
fi
else
echo "Rittal CMC-TC support for Nagios, v$version (c) 2008-2009 Pekka Panula / Net Servant Oy"
echo "License: GPLv2"
echo "Usage: rittal_cmc -H host -V variable -N name"
echo " - variable: eg. 3304, 3. module 4. variable, etc"
echo " - name : name of variable, eg. Alarm Message"
echo ""
echo "Example: ./rittal_cmc.sh -H 192.168.0.2 -V 3104 -N \"Warning Message\""
returnStatus=3
fi

exit $returnStatus
 

  •  check_temp_cmc.sh

#!/bin/bash
#
# - Check Rittal CMC-TC temperature status from I/O units and from LCP units.
# - CMC-TC needs webinterface enabled
# - Uses curl to fetch html-page from CMC-TC, supports I/O units and Rittal LCP unit
# - Easy to check LCP temperatures and I/O unit's temperature sensor etc.
#
# Version: 1.0.2
# Author: Pekka Panula, pekka.panula@sofor.fi
# Dated: 27.6.2008
# License: GPLv2
# (c) 2008 Pekka Panula / Net Servant Oy
# Requirements: curl, grep, tr, cut (=coreutils), sed


returnStatus=3
pluginError=0
curl_options="--connect-timeout 5 --silent --anyauth"

# - Change username and password -
username=cmc
password=cmc
# - - - - - - - - -

# cmc_variable="3101" # first module, first variable

if [ ! "$1" = "-H" ]; then
pluginError=1
elif [ ! "$3" = "-w" ]; then
pluginError=1
elif [ ! "$5" = "-c" ]; then
pluginError=1
elif [ ! "$7" = "-V" ]; then
pluginError=1
fi

cmc_variable=$8

TEMPERATURE=$(curl ${curl_options} "http://${username}:${password}@$2/cmcget.cgi?${cmc_variable}" | grep "bb12l style=\"color:\#[F0-9][F0-9][0-9][0-9][0-9][0-9]\"" | cut -d\> -f2|cut -dr -f1|sed 's/\W//g')

if [ "$pluginError" -eq "0" ]; then
# echo $TEMPERATURE
case "$TEMPERATURE" in
*[^0-9]*) echo "WARNING - Result not a temperature: $TEMPERATURE"; exit 1 ;;
esac
if [ "$TEMPERATURE" == "" ]; then
echo "WARNING - Cant read umidade"
returnStatus=1
elif [ "$TEMPERATURE" -lt $6 ]; then
echo "CRITICAL - Umidade $TEMPERATURE %"
returnStatus=2
elif [ "$TEMPERATURE" -lt $4 ]; then
echo "WARNING - Umidade $TEMPERATURE %"
returnStatus=1
else
echo "OK - Umidade $TEMPERATURE %"
returnStatus=0
fi
else
echo "Rittal CMC-TC Temperature check for Nagios, v$version (c) 2008 Pekka Panula / Net Servant Oy"
echo "License: GPLv2"
echo "Usage: rittal_temp.sh -H host -w warn -c critical -V variable"
echo " - variable: eg. 3304, 3. module 4. variable, etc"
echo ""
echo "Example: ./rittal_temp.sh -H 192.168.0.2 -w 28 -c 32 -V 3104"
returnStatus=3
fi

exit $returnStatus
 

 

Feito isto, você deve criar os comandos para o nagios. No meu caso:  /etc/nagios-plugins/config/cmc.cfg

 

 # 'check_cmc' command definition

define command{
command_name check_cmc
command_line /usr/lib/nagios/plugins/check_cmc.sh -H '$HOSTADDRESS$' -V '$ARG1$' -N '$ARG2$'
}



define command{
command_name check_temp_cmc
command_line /usr/lib/nagios/plugins/check_temp_cmc.sh -H '$HOSTADDRESS$' -w '$ARG1$' -c '$ARG2$' -V '$ARG3$'
}



define command{
command_name check_umidade_cmc
command_line /usr/lib/nagios/plugins/check_umidade_cmc.sh -H '$HOSTADDRESS$' -w '$ARG1$' -c '$ARG2$' -V '$ARG3$'
}
 

 Agora é só dar uma olhada nos helps dos *.sh que ele explica como usar os parâmetros.

 

Have fun.

 

Referencia: Nagios Exchange 


Navegue pelos artigos
Artigo prévio Sendmail com SMTP externo e mascarado Alterar memoria Jboss 5 Próximo artigo
Os comentários são de propriedade de seus respectivos autores. Não somos responsáveis pelo seu conteúdo.
Pesquisa