miércoles, 24 de marzo de 2010

viernes, 19 de marzo de 2010

RedIRIS - Diseño del Servicio de Correo Electrónico con calidad

http://www.rediris.es/mail/
Creo que esta web merece ser citada como punto de referencia a la hora de diseñar las políticas del servidor de correo electrónico/antispam. Uno de los artículos que me ha sido más útil es "RACEv2. Servicio de certificación de calidad del Servicio de Correo Electrónico." Donde se describen los criterios de calidad que todo buen antispam debe tener y donde se recogen muchas recomendaciones y consejos útiles.

Ellos mismos lo resumen como:


El documento RACEv2 tiene como objetivo exponer las mejores recomendaciones para diseñar, configurar y gestionar un Servicio de Correo Electrónico desde el punto de vista de la excelencia en la calidad del servicio ofrecido tanto a los usuarios locales de una organización, como al resto de entidades con las que se intercambia tráfico SMTP. Estas recomendaciones se estructuran en criterios de calidad, clasificados según su ámbito de aplicación y asignados a diferentes niveles, que permitirán medir la calidad del Servicio de Correo Electrónico de una organización, y promover la mejora del mismo.

miércoles, 17 de marzo de 2010

Monitorizar Postfix con Cacti

Una gráfica simple de los correos que hay en la cola.








En el servidor de correo hacemos el siguiente script, por ejemplo en /usr/local/bin/mailq.sh

#!/bin/bash

# check postfix mail for snmpd

mailq=$(mailq | grep 'Request')

if [ $? -eq 1 ]; then
echo '0'
exit 0
fi

mail_sum=$(echo $mailq | awk '{print $5}')
echo $mail_sum
En este mismo server añadimos en el snmpd.conf

extend mailq /usr/local/bin/mailq.sh

Importar los siguientes xml al cacti:
http://forums.cacti.net//files/cacti_graph_template_postfix_queue.xml
http://forums.cacti.net//files/cacti_data_template_postfix_queue.xml

Una vez esten instalados los templates, hay que modificar el OID del data source por: NET-SNMP-EXTEND-MIB::nsExtendOutLine."mailq".1

Hay de más completos como http://forums.cacti.net/about16480.html cuando lo tenga instalado lo pondré.


Monitorizar Xen con Nagios - Dominios Zombies





Para monitorizar que ninguna vm se quede en estado zombie


#!/bin/bash


HIHA_ZOMBIE=`sudo /usr/sbin/xentop -bi1 | awk '{ print $1 }' | grep -wc "Zombie-"`
NOMBRE_TOTAL=`sudo /usr/sbin/xentop -bi1 | awk '{ print $1 }' | grep -wv "NAME" | wc -l `

if [ $HIHA_ZOMBIE -ne 0 ] ; then
CRU=`sudo /usr/sbin/xentop -bi1 | awk '{ print $1 }' | grep "Zombie-"`
PLA=`echo -n $CRU`
TEXTRET="Error. Domain Zombie: $PLA "
RETORN=2
else
TEXTRET="OK. Totes les maquines ($NOMBRE_TOTAL) correctes."
RETORN=0
fi

echo $TEXTRET
exit $RETORN



Monitorizar Xen con Nagios - Memoria Virtual Machines





Otro script del mismo estilo para alertar en caso que la memoria de una maquina virtual llegue a warning/critical.

#!/bin/bash

#" parametres entrada nivell de warning i de critical
if [ $# -ne 2 ] ; then
echo "Error es requereixen 2 parametres, el percentatge de warning i de critical"
exit 2
fi

PECRIT=$2
PEWARN=$1
RETORN=0
TEXTRETORN=""
TEMPFILE=`mktemp`

llistat=`sudo /usr/sbin/xentop -bi1 | awk '{ print $1}' | grep -wv "NAME" | grep -v "Domain-0" `
nombre_dominis=`sudo /usr/sbin/xm list | grep -wv "Name" | wc -l`

sudo /usr/sbin/xentop -bi3 >$TEMPFILE
for ite in $llistat ; do
nivell_cpu=`grep "$ite" $TEMPFILE| awk '{ print $6 }' | tail -1| cut -d'.' -f1`

if [ $nivell_cpu -ge $PECRIT ] ; then
RETORN=2
TEXTRETORN="$TEXTRETORN Crit($ite),"
elif [ $nivell_cpu -ge $PEWARN ] ; then
if [ $RETORN -ne 2 ] ; then
RETORN=1
fi
TEXTRETORN="$TEXTRETORN Warn($ite),"
fi
done
if [ $RETORN -eq 0 ] ; then
TEXTRETORN="OK. Totes maquines ($nombre_dominis) per sota limits memoria."
fi
if [ $RETORN -eq 1 ] ; then
TEXTRETORN="WARNING. $TEXTRETORN"
fi
if [ $RETORN -eq 2 ] ; then
TEXTRETORN="ERROR. $TEXTRETORN"
fi

rm -f $TEMPFILE
echo $TEXTRETORN
exit $RETORN


martes, 16 de marzo de 2010

Monitorizar Xen con Nagios - CPUs





Un pequeño script que comprueba que las cpus de las maquinas virtuales no exceden del warning y critical.

#!/bin/bash

#" parametres entrada nivell de warning i de critical
if [ $# -ne 2 ] ; then
echo "Error es requereixen 2 parametres, el percentatge de warning i de critical"
exit 2
fi

PECRIT=$2
PEWARN=$1
RETORN=0
TEXTRETORN=""
TEMPFILE=`mktemp`

nombre_dominis=`sudo /usr/sbin/xm list | grep -wv "Name" | wc -l`
llistat=`sudo /usr/sbin/xentop -bi1 | awk '{ print $1}' | grep -wv "NAME"`

sudo /usr/sbin/xentop -bi2 >$TEMPFILE
for ite in $llistat ; do
nivell_cpu=`grep "$ite" $TEMPFILE | awk '{ print $4 }' | tail -1 | cut -d'.' -f1`

if [ $nivell_cpu -ge $PECRIT ] ; then
RETORN=2
TEXTRETORN="$TEXTRETORN Crit($ite),"
elif [ $nivell_cpu -ge $PEWARN ] ; then
if [ $RETORN -ne 2 ] ; then
RETORN=1
fi
TEXTRETORN="$TEXTRETORN Warn($ite),"
fi
done
if [ $RETORN -eq 0 ] ; then
TEXTRETORN="OK. Totes maquines ($nombre_dominis) per sota limits CPU."
fi
if [ $RETORN -eq 1 ] ; then
TEXTRETORN="WARNING. $TEXTRETORN"
fi
if [ $RETORN -eq 2 ] ; then
TEXTRETORN="ERROR. $TEXTRETORN"
fi

rm -f $TEMPFILE
echo $TEXTRETORN
exit $RETORN

La salida si todo esta Ok seria:
OK. Totes maquines (5) per sota limits CPU.

Luego hay que añadir el comando para hacer sudo en el usuario nagios para los comandos xentop y xm list

nagios ALL=(ALL) NOPASSWD:/usr/sbin/xm list
nagios ALL=(ALL) NOPASSWD:/usr/sbin/xentop

VirtualBox- Arranque de VM automatico

Con este sencillo bat podemos arrancar las maquinas virtuales cuando inicia el sistema. La forma más sencilla es ponerlo en el menu inicio y asi siempre que entremos en nuestra sesión se abriran automaticamente.
C:\Archivos de programa\Sun\VirtualBox
C:\Archivos de Programa\Oracle\VirtualBox
VBoxManage startvm "server-web"
VBoxManage startvm "server-mail"
VBoxManage startvm "server-nagios"
Este mismo comando tambien nos sirve para GNU/linux.
También hay más parametros como:
  • VBoxManage showvminfo nos mostrara toda la info sobre una vm
  • VBoxManage modifyvm “Windows XP” -memory “512MB” Modifica las propiedades de la vm
  • VBoxManage controlvm server-nagios acpipowerbutton Apaga la vm
  • VBoxManage controlvm server-nagios savestate Guarda su estado

Y si alguna vm es un Windows la podemos apagar así:
net rpc SHUTDOWN -t 0 -C "Apagado desde el servidor VBox" -f -I xxx.xxx.xxx.xxx -U Administrador%password



martes, 9 de marzo de 2010

MailWatch - Filtros Reports I

Aquí unos filtros útiles

Filtro Los 7 últimos días:

Date is greater than or equal to
'!CURRENT_DATE() - INTERVAL 7 DAY '













Filtro Hoy!
Date is equal to '!CURRENT_DATE()'



Mailscanner - Max Spam Check Size

Como en la naturaleza, la guerra entre el spam y los antispam, evolucionan. Cada mecanismo de ataque genera uno de defensa y viceversa... al grano. El otro dia vi que MailScanner viene con una config por defecto para analizar todos los correo que no sean superiores a 200k...

# Spammers do not have the power to send out huge messages to everyone as
# it costs them too much (more smaller messages makes more profit than less
# very large messages). So if a message is bigger than a certain size, it
# is highly unlikely to be spam. Limiting this saves a lot of time checking
# huge messages.
# Disable this option by setting it to a huge value.
# This is measured in bytes.
# This can also be the filename of a ruleset.
Max Spam Check Size = 200k

Esta justificación, en mi opinión totalmente valida, pero es muy sutil. El otro dia vi como se colaba un correo de 207k sin mostrar ninguna puntuación en mailscanner, simplemente decia "too large" :(. Para solventarlo aumentar ese valor.


Donde poner las RBL

Este tema creo que crea cierta controversia en general supongo que cada admin las pone donde considera más adecuadas en cada caso, en el MTA, en el MailScanner o en Spamassassin. He encontrado esta doku donde explican un poco que trae poner las rbls en un sitio o en otro. http://wiki.mailscanner.info/doku.php?id=documentation:anti_spam:rbls:all:recommendations

[documentation:anti_spam:rbls:all:recommendations]]

Dice lo siguiente.

At the MTA level

As soon as the originating mail server is listed in the chosen RBLS, the mail is rejected. This means that you will never see this mail. The risk of false positives are high, unless you check your logs very carefully. Many organizations use spamhaus in their MTA.

At MailScanner level

When the originating mail server is listed in the chosen RBLS, it is identified as spam by MailScanner and the action is customizeable. The risk of false positives are also high, but you can, for example, just tag the messages and still deliver, unless it is listed in more than x lists.

At SpamAssassin level

When the originating mail server is listed in the chosen RBLS (there are many of them activated in the default setup), it only increases the score by a determined amount, depending on the effectiveness of the list. This method is usually the most accurate. However, note that from the MTA level to SpamAssassin level, the ressource usage is increasing, so the processing time used with SpamAssassin-based RBLS check.

To summarize

When using RBL checks at MTA level, you save a lot of resources, but you must very carefully select the RBL you use. When using RBL checks at MailScanner level, you have more control on what happens to the messages identified as spam by RBL checks. Here again you must carefully choose the lists, but since you have more control over what happens to the messages, it is less critical than at MTA-level. The counterpart is more ressources needed for the treatment of messages. Finally, SpamAssassin usually gives the more accurate and up-to-date treatment, but consumes the most resources.

miércoles, 3 de marzo de 2010

Monitorizar Xen con Nagios






Script check_xenvm

#!/bin/sh
#
# COPYRIGHT : (c) 2006 SUSE Linux GmbH. All rights reserved.
#
# AUTHOR : Axel Schmidt
#
# BELONGS TO : NLPOS/SLEPOS/Xen Nagios Integration
#
# DESCRIPTION : Runs "xm list" and returns the available xen vms
#
# $Revision: 1.0 $
#
# Permission to use, copy, modify, distribute, and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation.

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHOR OR SUSE BE LIABLE FOR ANY CLAIM, DAMAGES
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

PARM1=$1
WARN=$2
PARM2=$3
CRIT=$4


if [ "$PARM2" != "-c" -o "$CRIT" == "" ]; then
echo "Usage: $0 -w -c "
# Nagios exit code 3 = status UNKNOWN = orange

if [ "$PARM1" != "-h" ]; then
exit 3
else
echo ""
echo " -w = Minimum Number of Xen VMs to activate a warning message."
echo " -c = Number of Xen VMs to activate a critical message."
echo " -h = This help message."
exit 3
fi
fi


RUNNING=$(sudo /usr/sbin/xm list | awk '!/[DN]/ {print $1 }')
NBVMS=$(echo $RUNNING | wc -w)
HNAME=$(hostname)

#echo "Xen Running =" $RUNNING

if [ "$NBVMS" -le "$CRIT" ]; then
echo "Critical Xen VMs Usage - Total NB: $NBVMS - detected VMs: $RUNNING"
# Nagios exit code 2 = status CRITICAL = red
exit 2
else if [ "$NBVMS" -le "$WARN" ]; then
echo "Warning Xen VMs Usage - Total NB: $NBVMS - detected VMs: $RUNNING"
# Nagios exit code 1 = status WARNING = yellow
exit 1
else
echo "OK: Xen Hypervisor \"$HNAME\" is running Xen VMs: $RUNNING"
# Nagios exit code 0 = status OK = green
exit 0
fi
fi
Comando

# added for Xen VM Monitoring

define command{
command_name check_xen_vm
command_line $USER1$/check_xenvm -w $ARG1$ -c $ARG2$
}

Servicio

define service{
use generic-service
host_name localhost
service_description Xen Virtual Machine Monitor
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 60
notification_period 24x7
check_command check_xen_vm!2!0
}
/etc/sudoers

  • Login as root
  • Execute: visudo1
  • Add the following line:
    nagios ALL=(ALL) NOPASSWD:/usr/sbin/xm list
  • Save changes and exit visudo