<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Itimag.com &#187; sms</title>
	<atom:link href="http://www.itimag.com/tag/sms/feed" rel="self" type="application/rss+xml" />
	<link>http://www.itimag.com</link>
	<description>Blog de un Ingeniero Informático</description>
	<lastBuildDate>Mon, 12 Apr 2010 22:31:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Alertas SMS Gratis</title>
		<link>http://www.itimag.com/servidores/alertas-sms-gratis.html</link>
		<comments>http://www.itimag.com/servidores/alertas-sms-gratis.html#comments</comments>
		<pubDate>Sat, 03 Oct 2009 23:06:32 +0000</pubDate>
		<dc:creator>Itimag</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Servidores]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[sms]]></category>

		<guid isPermaLink="false">http://www.itimag.com/?p=791</guid>
		<description><![CDATA[Me he enterado por los foros de ovh de un sistema de envío de alertas sms gratis mediante el uso de un servicio de Google: el Google Calendar. Podemos exprimir este recurso utilizando el API de Google Calendar y darle múltiples usos. ¿Se os ocurre alguno?  En los foros de OVH se ha pensado en [...]]]></description>
			<content:encoded><![CDATA[<p>Me he enterado por los foros de ovh de un sistema de envío de alertas sms gratis mediante el uso de un servicio de Google: el Google Calendar.</p>
<p>Podemos exprimir este recurso utilizando el <a href="http://code.google.com/apis/gdata/articles/php_client_lib.html">API de Google Calendar</a> y darle múltiples usos. ¿Se os ocurre alguno?  En los <a href="http://foros.ovh.es">foros de OVH</a> se ha pensado en un sistema de monitorización de servidores.</p>
<p>Un usuario de OVH, Power, <a href="http://foros.ovh.es/showthread.php?t=5184">ha realizado un script php</a> para recibir una alerta por sms en cuanto la carga de alguno de sus servidores supera un &#8220;load average&#8221; determinado. Otro usuario ha pedido adaptar este script para recibir alertas sms cuando alguno de sus servidores pierde la conexión a internet así que esta tarde me he puesto en ello.</p>
<p>El script resultante ha sido el siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
SMS PING 0.1 creado el 3 de Octubre 2009
web http://foros.ovh.es/showthread.php?t=5184
&nbsp;
USO del script:
	1. Introducir tus datos de Google Calendar en la configuración del script.
	2. Introducir el listado de los servidores a monitorizar.
	3. Subir el script al servidor.
	4. Añadir la tarea al cron. El tiempo de ejecución dependerá de la cantidad
 de servidores a monitorizar.
&nbsp;
Nota: En caso de que un servidor no responda, pasa un tiempo hasta averiguar que 
no responde y enviar el sms.
&nbsp;
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Configuración</span>
<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;tu_cuenta@gmail.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Lista de servidores a monitorizar. Introducir un dominio o la IP del servidor.</span>
<span style="color: #000088;">$ips_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ks35xx1:www.google.es&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;ks35xx2:www.yahoo.es&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
<span style="color: #666666; font-style: italic;">// Carga librerías Zend_Gdata</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ZendGdata/library'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_AuthSub'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_ClientLogin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Gdata_Calendar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Conexión con Google Calendar</span>
<span style="color: #000088;">$service</span> <span style="color: #339933;">=</span> Zend_Gdata_Calendar<span style="color: #339933;">::</span><span style="color: #004000;">AUTH_SERVICE_NAME</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// nombre del servicio </span>
<span style="color: #666666; font-style: italic;">//de Google Calendar</span>
<span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> Zend_Gdata_ClientLogin<span style="color: #339933;">::</span><span style="color: #004000;">getHttpClient</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span><span style="color: #000088;">$service</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Función para crear evento en Google Calendar</span>
<span style="color: #000000; font-weight: bold;">function</span> createQuickAddEvent <span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span> <span style="color: #000088;">$quickAddText</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$gdataCal</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_Calendar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$event</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdataCal</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newEventEntry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$event</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdataCal</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newContent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$quickAddText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$event</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">quickAdd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdataCal</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newQuickAdd</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'true'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$newEvent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$gdataCal</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertEvent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> enviasms<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cliente</span><span style="color: #339933;">,</span><span style="color: #000088;">$servidor</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$texto</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Fallo en el servidor &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$servidor</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Hora y minuto con retardo de 2 minutos</span>
    <span style="color: #000088;">$hora</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;H&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$minutos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;i&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Creación del evento en Google Calendar</span>
    createQuickAddEvent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cliente</span><span style="color: #339933;">,</span> <span style="color: #000088;">$texto</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$hora</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$minutos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span><span style="color: #339933;">,</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">=</span><span style="color: #990000;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ips_array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$datos_ip</span><span style="color: #339933;">=</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datos_ip</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;http&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
		<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$datos_ip</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$churl</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$churl</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;El servidor <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$datos_ip</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> esta Offline<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		enviasms<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client</span><span style="color: #339933;">,</span><span style="color: #000088;">$datos_ip</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;El servidor <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$datos_ip</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> esta Online<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>El script requiere de unas librerías llamadas &#8220;Google Data Client Library Files&#8221;, las cuales incluyo en la versión <a href="http://longcook.com/SMS%20PING.zip">descargable del script</a>, preparada para usar. Simplemente debéis introducir activar el servicio de sms hacía vuestro teléfono en la configuración de vuestro google calendar, introducir los datos a éste en el script y añadir los servidores a monitorizar.</p>
<p>¿Cómo funciona el script? Lo que hace es ir comprobando que cada uno de los servidores introducidos respondan a una petición http. En caso de que no responda, se crea un evento en google calendar, el cúal nos enviará un sms a nuestro teléfono.</p>
<p>Se aceptan críticas y sugerencias. Espero que sea de vuestro agrado <img src='http://www.itimag.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.itimag.com/servidores/alertas-sms-gratis.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
