miércoles, 14 de agosto de 2013

asterisk voicemail multiple email addresses

Teniendo instalado postfix en el mismo servidor que está asterisk hay que modificar el fichero main.cf

virtual_alias_domains = pbxfulano.es
virtual_alias_maps = hash:/etc/postfix/virtual


Se crea el fichero /etc/postfix/virtual
lista@pbxfulano.es        pepe@fulano.es, pepa@fulano.es, juan@fulano.es, david@gmail.com

como email para enviar el mensaje del voicebox de asterisk se utiliza lista@pbxfulano.es, de esta forma este mensaje se reenvía a través de postfix a las demás direcciones


Para cargar la configuración
postmap /etc/postfix/virtual
service postfix reload

y para probar que funciona...

echo "prueba" | mail -s "prueba" lista@pbxfulano.es





jueves, 18 de julio de 2013

Configurar router edgemax lite con coovachilli hotspot

Pasos seguidos:

  1. Actualizar a la última versión de firmware
  2. Meter los repositorios de Debian
  3. Descargar hasrel
    1. Instalar  librería que tiene la dependencia de hasrel
  4. Descargar deb de coova-chilli 1.3.0 para mips
  5. Editar fichero de configuración de chilli
  6. Activar DNS cache en el router
  7. Activar NAT masquerading



1- En el siguiente enlace se puede descargar la última versión hasta el momento del firmware de ubiquiti
 
 Para actualizar el firmware, hay que acceder al router por ssh o desde el CLI.
 
$add system image fichero_de_imagen.tar
 
Mas info en este enlace:  actualizar firmware
 
2- Una vez actualizado el firmware, hay que meter los repositorios de Debian en el router
Se pueden seguir las instrucciones en el siguiente link: debian repos
 
Comandos a seguir:
 
configure
set system package repository squeeze components 'main contrib non-free'
set system package repository squeeze distribution squeeze
set system package repository squeeze url http://http.us.debian.org/debian

set system package repository squeeze-security components main
set system package repository squeeze-security distribution squeeze/updates
set system package repository squeeze-security url http://security.debian.org
commit
save
exit

para actualizar el arbol una vez metidos los repositorios:
sudo apt-get update
 
3- Antes de instalar coovachilli, este necesita una dependencia "hasrel", que se puede 
descargar de los repositorios de debian
aquí dejo un enlace  haserl_0.9.29-3_mips.deb
 
una vez descargado se instala con 
# dpkg -i haserl_0.9.29-3_mips.deb
 
este dará fallo.. ya que necesita la siguiente dependencia que se puede bajar directamente
del repositorio  "liblua5.1-0".
Con el siguiente comando se puede instalar la dependencia sin problema
 
#apt-get install liblua5.1-0 

4 - Decargar el paquete de coovachilli 
 foro
 
 coova-chilli_1.3.0_mips.deb
    


 coova-chilli_1.3.0_mips.deb
 
para instalarlo
#dpkg -i coova....
 
5- Edición del fichero /etc/chilli/default
 
HS_WANIF=eth1            # El eth1 esta por dhcp conectado a un router
HS_LANIF=eth2            # En eth2 conectarían los usuarios del portal cautivo 
HS_NETWORK=10.11.0.0       # HotSpot Network (must include HS_UAMLISTEN)
HS_NETMASK=255.255.255.0   # HotSpot Network Netmask
HS_UAMLISTEN=10.11.0.1     # HotSpot IP Address (on subscriber network)
HS_UAMPORT=3990            # HotSpot UAM Port (on subscriber network)
HS_UAMUIPORT=4990          # HotSpot UAM "UI" Port (on subscriber network, for embedded portal)
HS_DNS1=10.11.0.1    # he puesto esta DNS para hacer la cache
HS_DNS2=8.8.8.8
HS_NASID=nas01
HS_RADIUS=97.14X.XXX.XX
HS_RADIUS2=97.14X.XXX.XX
HS_UAMALLOW=www.coova.org
HS_RADSECRET=8U8W2CPTvVcD    # esta es mi clave de radius
HS_UAMSECRET=change-me     # Set to be your UAM secret
HS_UAMALIASNAME=chilli
HS_UAMSERVER=$HS_UAMLISTEN
HS_UAMFORMAT=http://\$HS_UAMLISTEN:\$HS_UAMUIPORT/www/login.chi
HS_UAMHOMEPAGE=http://\$HS_UAMLISTEN:\$HS_UAMPORT/www/coova.html
HS_MODE=hotspot
HS_TYPE=chillispot
HS_WWWDIR=/etc/chilli/www
HS_WWWBIN=/etc/chilli/wwwsh
HS_PROVIDER=Coova
HS_PROVIDER_LINK=http://www.coova.org/
HS_LOC_NAME="My HotSpot"           # WISPr Location Name and used in por
 
también hay que editar /etc/default/chilli para poner  start_chilli=1
  
root@ubnt:/home/ubnt# cat /etc/default/chilli 
START_CHILLI=1
CONFFILE="/etc/chilli.conf"
HS_USER="chilli"

6- Hacer que el rotuer tenga cache dns
he puesto que escucha en el eth2 para que los clientes de coovachilli sean los que tengan
acceso al cache de dns 
 
 
 
7- Activar masquerading NAT
 
 
 
 
Buenos pues con todo esto, ya debería ser una guía suficiente para empezar a probar 
el edgeos router con coovachilli 
 
 
 
8- Editar wwwsh, por algun motivo no funciona bien el fichero que viene por defecto

#!/bin/sh
# (c) 2007 David Bird; Released under GPL.
# This simple script dispatches the <file>.chi embedded CGI scripts.
# If <file>.chi exists, and we have haserl, then we run "haserl file.chi"
# Otherwise, we look for <file>.chi.sh files to run as shell scripts.

file=$(basename $1)
dir=$(dirname $1)
haserl=$(which haserl 2>/dev/null)
cd $dir

# should be make a bit safer!

if [ -z "$haserl" ]; then
    if [ -e "$file.sh" ]; then
        sh $file.sh
    else
        echo "<p>You need to install haserl to serve pages with this wwwsh script!</p>"
        echo "<p>see <a href='http://haserl.sourceforge.net/'>http://haserl.sourceforge.net/</a></p>"
    fi
    exit
fi

    $haserl $file
 
 

viernes, 14 de junio de 2013

jueves, 13 de junio de 2013

Crear alertas de email a partir de un pattern en un fichero de log

Descargar los paquetes
 
apt-get install libmailtools-perl libunix-syslog-perl libfile-tail-perl libproc-daemon-perl 

Agregar los módulos a CPAN

for m in Mail::Mailer Proc::Daemon Unix::Syslog File::Tail; 
do 
   perl -MCPAN -e "install $m";
done 

Descargar el script de aquí   http://unixlore.net/downloads/logmon.pl.txt


#!/usr/bin/perl -wT
#
# Parses given logfile, looking for specified pattern, sends alert or
# logs message.
#
# Copyright (c) 2012 Doug Maxwell <doug@unixlore.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# Sample syslog error we want to alert on and usage:
#
# Jul 17 08:02:49 kaylee mysqld[1532]: 110717  8:02:49 [ERROR] /usr/sbin/mysqld: Table './mysql/user' is marked as crashed and should be repaired
#
# logmon.pl -p 'mysqld.+?table.+?crashed' -m you@example.com -u nobody -g adm -f /var/log/syslog -i 120
#
# Needs Mail::Mailer, Proc::Daemon, Unix::Syslog and File::Tail
# installed - the others are core modules.
#
# On Debian/Ubuntu:
# apt-get install libmailtools-perl libunix-syslog-perl libfile-tail-perl libproc-daemon-perl
#
# On Fedora
# yum install perl-MailTools perl-Unix-Syslog perl-File-Tail perl-Proc-Daemon
#
# CPAN:
#
# for m in Mail::Mailer Proc::Daemon Unix::Syslog File::Tail; do perl -MCPAN -e "install $m"; done
#
use strict;
use File::Tail;
use Mail::Mailer;
use Proc::Daemon;
use Unix::Syslog qw(:subs);
use Unix::Syslog qw(:macros);
use Getopt::Std;
use Sys::Hostname;
use POSIX qw(setuid setgid);
use English;

our ($opt_m,$opt_f,$opt_p,$opt_u,$opt_g,$opt_i,$opt_h,$opt_d,$opt_v);
getopts('hdvm:f:p:u:g:i:');

usage() && exit if ( $opt_h || !$opt_p);

sub usage {
    print "\n$0 synopsis: Daemon that periodically checks logfile for a pattern and send alerts\n";
    print "Pattern is always required. If no other options are given, defaults to syslog alerts and monitors /var/log/messages for given pattern.\n";
    print "Usage: $0  -p pattern [-m alerts\@example.com] [-f logfile] [-u run as user] [-g run as group] [-i max interval] [-v] [-d] [-h]\n";
    print "-m: Email destination for alerts\n-f: logfile to monitor\n-p: Pattern to match against lines in logfile (Perl regexp, match is case-insensitive)\n-u: Run with permissions of user\n-g: Run with permissions of group\n-i: Max time to sleep between checks\n-d: Debug output to STDERR, do not daemonize\n-v: Verbose logging (use with caution or you may have endless alerts)\n-h: This help text\n\n";
}

my $DEBUG = 1 if ( $opt_d );

if ( !$DEBUG ) {
    # Fork and detach
    log_alert("Forking and detaching from controlling terminal...");
    Proc::Daemon::Init;
}

# Drop privileges if needed.
if ( $opt_g && $UID == 0 ) {
    setgid( scalar getgrnam $opt_g ) or log_alert($!);
    log_alert("Now running with permissions of group $opt_g") if ( $GID );
}

if ( $opt_u && $UID == 0 ) {
    setuid( scalar getpwnam $opt_u ) or log_alert($!);
    log_alert("Now running with permissions of user $opt_u") if ( $UID );
}

# Clean up our environment for taint mode
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
$ENV{PATH} = "/bin:/usr/bin";

# Source of email alerts
my $from = 'root@example.com';

# The logfile we are monitoring. Make sure we can read it and that it
# exists.
my $logfile = "/var/log/messages";

if ( $opt_f ) {
    if ( ! -r $opt_f ) {
        log_alert("Logfile $opt_f does not exist or is not readable");
        die;
    } else {
        $logfile = $opt_f;
    }
}

# Pre-compile the regexp we are using
my $pattern = qr/$opt_p/io;

# Mail recipient for alerts
my $recipient = $opt_m if ( $opt_m );

# Max time to wait between checks. File::Tail uses an adaptive
# algorithm to vary the time between file checks, depending on the
# amount of data being written to the file. This is the maximum
# allowed interval.
my $maxinterval = 60;
$maxinterval = $opt_i if ( $opt_i );

my $file = File::Tail->new(name=>$logfile, maxinterval=> $opt_i, adjustafter=>3) or ( log_alert($!) && die );

( $opt_v ) ? log_alert("Running and monitoring $logfile for $pattern") : log_alert("Running and monitoring $logfile");

# Loop as long as we keep getting lines from the file
while (defined(my $line = $file->read)) {
    if ( $line =~ /$pattern/ ) {
        chomp($line);
        if ( $opt_m ) {
            send_mail_alert($from,$recipient,$line);
        } else {
            ( $opt_v ) ? log_alert("Matched $pattern against '$line' in $logfile") : log_alert("$logfile matched!");
        }
    }
}

# Send an email alert using sendmail on the localhost
sub send_mail_alert {
  my ($from,$recipient,$body) = @_;
  my $hostname = hostname();
  my $subject = "Alert from $0 on $hostname while monitoring $logfile for $pattern";
  my $mailer = Mail::Mailer->new("sendmail");
  $mailer->open({ From    => $from,
    To      => $recipient,
    Subject => $subject,
  })
    or log_alert($!);
  print $mailer $body or log_alert($!);
  $mailer->close( );
  log_alert("Sent email alert to $recipient");
  return;
}

# Log a message to this system's syslog. If debugging is enabled, we
# are not a daemon and we just print to STDERR.
sub log_alert {
  my $text = shift;

  if ( $DEBUG ) {
      print STDERR "$0: $text\n";
      return;
  }

  openlog ("$0", LOG_PERROR|LOG_CONS , LOG_LOCAL7);
  syslog (LOG_INFO, "$text\n");
  closelog();
  return;
}
 
 
 Chequear que la sintaxis es correcta con el comando: 
perl -cwT ./logmon.pl

Copiar el fichero en sbin con sus permisos con el siguiente comando



install -m 755 logmon.pl /usr/local/bin/ 

Para ejecutar el comando se puede hacer con:

logmon.pl -p 'pattern buscada' -m pepe@gmail.com -u nobody -g adm -f /var/log/kern.log -i 120

para ejecutarlo en modo debur -dv  (debug + verbose)

para matar el demonio pkill logmon


Fuente: http://www.unixlore.net/articles/monitoring-alerting-patterns-linux-logfiles.html