Google Talk

Notificaciones en Tiempo Real
sudoers Barcelona 20111004 Javier Arturo Rodríguez <javier@rodriguez.org.mx>

xkcd.com (cc) Randall Munroe

xkcd.com (cc) Randall Munroe

xkcd.com (cc) Randall Munroe

xkcd.com (cc) Randall Munroe

Flickr (cc) liewcf

Flickr (cc) Albert!

Flickr (cc) Kamil Porembiński

¿Por Qué?

Menos cambios de contexto

Canal Dedicado

API Abierto

http://code.google.com/apis/talk/

Basado en Estándares

Múltiples Clientes

http://en.wikipedia.org/wiki/Comparison_of_instant_messaging_clients

Mismo Canal, Múltiples Medios

• Cliente IM • Móvil • Web

• Cliente IM • Móvil • Web

• Cliente IM • Móvil • Web

• Cliente IM • Móvil • Web

• Cliente IM • Móvil • Web

Gran Infraestructura

Google Maps / Pingdom Blog

Flickr (cc) Charleston’s TheDigitel

Archivo Histórico

Flickr (cc) hamadryades

gTalk Práctico

http://www.gridpp.ac.uk/wiki/Nagios_jabber_notification

notify_via_jabber

notify_via_gtalk

notify_via_gtalk

if ($len ne 2) { die "Usage...\n $0 [jabberid] [message]\n"; } my @field=split(/,/,$ARGV[0]); #------------------------------------

notify_via_gtalk
# Google Talk & Jabber parameters : my my my my my $hostname = 'talk.google.com'; $port = 5222; $componentname = 'gmail.com'; $connectiontype = 'tcpip'; $tls = 1; #-----------------------------------my $Connection = new Net::XMPP::Client(); # Connect to talk.google.com my $status = $Connection->Connect( hostname => $hostname, port => $port, componentname => $componentname, connectiontype => $connectiontype, tls => $tls); if (!(defined($status))) { print "ERROR: XMPP connection failed.\n"; print " ($!)\n"; exit(0); } # Change hostname my $sid = $Connection->{SESSION}->{id}; $Connection->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname; # Authenticate my @result = $Connection->AuthSend( username => $username, password => $password, resource => $resource); if ($result[0] ne "ok") { print "ERROR: Authorization failed: $result[0] - $result[1]\n"; exit(0); } # Send messages foreach ( @field ) { $Connection->MessageSend( to => "$_\@$componentname", resource => $resource, subject => "Notification", type => "chat", body => $ARGV[1]); }

Parche para <STDIN>

Parche para <STDIN>
$ diff notify_via_jabber notify_via_gtalk 7a8 > # small patch for STDIN input by Javier Arturo Rodriguez <codehead@gmail.com> 23,24c24,25 < if ($len ne 2) { < die "Usage...\n $0 [jabberid] [message]\n"; --> if ($len lt 1) { > die "Usage...\n $0 jabberid [message]\n"; 74c75 < body => $ARGV[1]); --> body => $ARGV[1]||join(' ',<STDIN>));

Línea de comando

Línea de comando
$ /usr/local/bin/notify_via_gtalk gtalkuser ‘Hello, gTalk world!’

Línea de comando
$ /usr/local/bin/notify_via_gtalk gtalkuser ‘Hello, gTalk world!’

Shell scripts

Shell scripts
$ rsync src/ remote:dst/ \ && /usr/local/bin/notify_via_gtalk gtalkuser “Backup completed” \ || /usr/local/bin/notify_via_gtalk gtalkuser “ERROR”

Shell scripts
$ rsync src/ remote:dst/ \ && /usr/local/bin/notify_via_gtalk gtalkuser “Backup completed” \ || /usr/local/bin/notify_via_gtalk gtalkuser “ERROR”

Nagios commands.cfg

Nagios commands.cfg
# 'host-notify-by-gtalk' command definition define command{ command_name host-notify-by-gtalk command_line /usr/local/bin/notify_via_gtalk $CONTACTPAGER$ "Host '$HOSTALIAS$' is $HOSTSTATE$ - Info: $HOSTOUTPUT$" } # 'notify-by-gtalk' command definition define command{ command_name notify-by-gtalk command_line /usr/local/bin/notify_via_gtalk $CONTACTPAGER$ "$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$" }

Nagios commands.cfg
# 'host-notify-by-gtalk' command definition define command{ command_name host-notify-by-gtalk command_line /usr/local/bin/notify_via_gtalk $CONTACTPAGER$ "Host '$HOSTALIAS$' is $HOSTSTATE$ - Info: $HOSTOUTPUT$" } # 'notify-by-gtalk' command definition define command{ command_name notify-by-gtalk command_line /usr/local/bin/notify_via_gtalk $CONTACTPAGER$ "$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$" }

mail2gtalk

#!/usr/bin/perl use strict; use Email::StripMIME; use Email::Simple; use Data::Dumper;

mail2gtalk

my $NOTIFY = "/usr/local/bin/notify_via_gtalk"; local $/ = undef; my $to = shift @ARGV; $to=~s,[^a-z0-9],,igs; my $in = <STDIN>; my $email = Email::Simple->new(Email::StripMIME::strip_mime( $in )); my $from = $email->header("From"); my $subject = $email->header("Subject"); if($from=~m,<(.*?)>,) { " $from = $1; } my $body = $from. ': ' . $subject . '. ' . $email->body(); $body=~s,[\n\r], ,igs; $body=~s,\s+, ,igs; # Uncomment next line to limit length, e.g. for SMS # $body=substr($body,0,160); if(-x $NOTIFY) { " open(PIPE,"|$NOTIFY $to")||die($!); " print PIPE $body; " close(PIPE)||die($!); } else { " die("Can't find $NOTIFY"); }

sudo: /etc/aliases

sudo: /etc/aliases
santa: |/usr/local/bin/mail2gtalk gtalkuser

sudo: /etc/sudoers

sudo: /etc/sudoers
Defaults mail_no_perms Defaults mail_badpass Defaults mailto="root,santa@local.domain"

sudo: /etc/sudoers
Defaults mail_no_perms Defaults mail_badpass Defaults mailto="root,santa@local.domain"

Javier Arturo Rodríguez <javier@rodriguez.org.mx>

Sign up to vote on this title
UsefulNot useful