<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:lucida console,sans-serif;font-size:10pt">Hola,<br><br>No te tomes esto a mal, pero si lo que pretendes es que alguien te haga el trabajo por la cara, te has equivocado de lista... <br><br>Aqui te podemos ayudar a resolver cuestiones concretas sobre como hacer algo con Perl, o incluso sobre cuestiones de mas alto nivel sobre como atacar un problema, o a dise~nar una solucion.<br><br>Pero para eso, empieza por ...<br><br>1) dar una descripcion resumida del problema, algo que se entienda en un tiempo razonable, 5 minutos maximo diria yo<br>2) describe las soluciones que tu has pensado que podrias aplicar con sus mas y sus menos <br>3) ense~nanos lo que hayas hecho hasta el momento y que no te haya funcionado<br><br>... y a ser posible en castellano, ya que esta es la lista de los PerlMongers de Madrid y no todo el mundo tiene porque entender
 ingles.<br><br>Y si lo que en realidad quieres es contratar a alguien para que te haga el trabajo, entonces haber empezado por ahi... no tendras tu nada que ver con este anuncio http://jobs.perl.org/job/10220 en la lista de Perl Jobs, no? porque por 50 euros iba a estar jodida la cosa!!!<br><br>- Salva<br><div style="font-family: lucida console,sans-serif; font-size: 10pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Host Host &lt;greathost@gmail.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> madrid-pm@pm.org<br><b><span style="font-weight: bold;">Sent:</span></b> Wednesday, February 18, 2009 4:59:36 PM<br><b><span style="font-weight: bold;">Subject:</span></b> [Madrid-pm] Ayuda con script<br></font><br>
Hola chicos, alguno podria echarme una mano?<br><br><br>This project is a checking (healthcheck) of the flow of SQL sentences, from one node to a main one.<br>The structure are developed as follows:<br><br>1 Main node plus 3 client nodes who reports events by sql (mysql) to the main node, the process who<br>
sends the events are written in java so i dont have any mechanism to check if it fails/frozen this application,<br>so i need to make a workaround to check if process are sending this sqls and check the log files.<br><br>So i need the following:<br>
<br>Flow:<br>1. INSERT of a given event in sql format to introduce in the sql flow in the 3 Slave Nodes to Master node every <br><br>5 minutes.<br><br>2. Checking by an sql instruction who arrived fine (in time) if not arrives, something goes wrong.<br>
This happens by a micro-cut of the communications, or something the technical product are still checking.<br>So the solution is to check if this events arrives, if all its fine, i dont do anything, if fails,<br>ill call into the system to a script who kills the process and start again the node process.<br>
a) Ill stop the slave node, b) ill stop the master node till the log file says that are stoped (i read this <br><br>word), then c) ill start-up the master node (read again the log to see its completelly up &amp;running) and<br>
d) i run every slave node ni order, first 1, 2nd 2..and 3rd 3.<br>And i read on every node his log file to chech that are up&amp;running (i read im ready on the log file for ex.)<br><br>Sometimes when i read the log files on Slave Nodes i have the following text:<br>
"Connection lost with the Central Server"<br>This happens some times by no reasson, so i need to correct it calling <a target="_blank" href="http://kill-my-process.sh">kill-my-process.sh</a> to kill it <br><br>completelly, waiting to read into the log "Please connect your client to the web server on port: 7070"<br>
Before sending the kill signal to the process, some times it re-establish by itself, so i have to "sleep 60"<br>checking if i have in log files: "Connection re-established with the Central Server" then ill dont do anything, <br>
<br>only keep sending the SQL events every 5minutes.<br><br>3. When i have fully restarted the app it writes down a log where you can read his status, this is the<br>phrase:"Please connect your client to the web server on port: 9090" i need to write an auxiliar file<br>
where in every moment writes me the status of the nodes, (master and slaves) to read it before act,<br>this status are the following: if i read on the log file in the lastest (usually 2/3 phrases):<br>"Please connect your client to the web server on port: 7070" --&gt; STATUS:UP&amp;RUNNING<br>
"Server Successfully Shut Down" --&gt; STATUS:DOWN<br>"Server modules started with problems" --&gt; STATUS:PROBLEMS<br><br>I need to drop the last status line from the original log file to an auxiliar file which latest status<br>
of the process (in main node and in slave nodes too)<br><br>When im up&amp;running i'll dont do anything<br>When im down i'll check to the others nodes to stop before start up the main node again.<br>When im reading problems, i restart again the process to start up all nodes again, (stop main node,<br>
stop slave nodes, start up main node, start up slave node1, slave node 2, slave node 3) wait in the bucle..<br><br><br>The idea of the flow is that from every slave node it sends a witness (testigo: a sql sentence) to the main<br>
node to check if it arrives correctly, for example every 5 minutes, the main node receives this witness<br>and prints in log "node 1 are ok" and do anything, the same from node 2 &amp; 3.<br><br>If im having problems receiving this witness its supposed that im having problems with Node x, then i need to<br>
re-start the nodes in an order: 1st: master node, 2nd slave node1, 3rd slave node2, 4th slave node3.<br>When are are down (i read from auxiliary log file his status) i can re-start in order, 1s node1, then node2, <br><br>
stop and check if node 2 are up and then node3.<br>To send the kill command, i need i must send a remote system call, i dont care if its by RSH::Net or<br>system_call($command) to call a file called <a target="_blank" href="http://kill_node_process.sh">kill_node_process.sh</a> &lt;- this script kills the node and start up<br>
again, all i need is to wait it restarts again and read the log file that tells me all is fine.<br>And of course, i'll check the node sql events again to check that are syncronizing again the node.<br><br>Suddendly i can read on the master node log the following:<br>
"Connection lost with the Client Server" then i must send the kill process to node slave 1, 2 and 3.<br>And then i wait if events arrives fine.<br><br><br><br><br>Table in MYSQL from a Node server<br><br><br>desc Event;<br>
<br>----+-----+---------+-------+<br>| Field&nbsp;&nbsp;&nbsp;&nbsp; | Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Null | Key | Default | Extra |<br>+-----------+--------------+------+-----+---------+-------+<br>| ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | int(11)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | PRI | 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
| TEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | text&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| CATEGORY&nbsp; | varchar(100) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| DDOMAIN&nbsp;&nbsp; | varchar(100) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| NETWORK&nbsp;&nbsp; | varchar(100) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
| NODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | varchar(100) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| ENTITY&nbsp;&nbsp;&nbsp; | varchar(150) |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | MUL |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| SEVERITY&nbsp; | int(11)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| TTIME&nbsp;&nbsp;&nbsp;&nbsp; | bigint(20)&nbsp;&nbsp; | YES&nbsp; | MUL | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
| SOURCE&nbsp;&nbsp;&nbsp; | varchar(100) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| HELPURL&nbsp;&nbsp; | varchar(100) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| WEBNMS&nbsp;&nbsp;&nbsp; | varchar(100) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>| GROUPNAME | varchar(100) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
| OWNERNAME | varchar(25)&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | PRI |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>+-----------+--------------+------+-----+---------+-------+<br>14 rows in set (0.01 sec)<br><br><br>How i can make the INSERT in the table?<br>As you can see i need to read the LAST ID 1st and the add 1 ($ID+1)<br>
<br>select id from Event order by ttime desc limit 1;<br><br>This select it gives me the ID to add later the sql statement:<br>I make the time (TTIME) this style: 1234343883752,<br>I think its with time() * 1000 to make the time on the insert, but im not sure (and i dont care) but i want it <br>
<br>to check lately, check the SQL that arrived in less than 5 min (300seg), and rest from the localtime this way:<br><br>$node1_time=1234343883752 (SELECT TTIME from table...);<br>$local_time=time()*1000;<br>$finish_time=$node1_time - $local_time = $difference<br>
if $difference &gt; 300 do sign_kill_signal_to_node1 ....<br>&nbsp;&nbsp; ... <br><br>&nbsp;&nbsp;&nbsp;&nbsp; ....<br><br><br><br><br>This is a real SELECT from the table Event:<br><br>&nbsp;&nbsp;&nbsp;&nbsp; | 10.33.109.189.barajas_dms_1&nbsp; | 1234465208249 |<br>|&nbsp; 55558 | Process Memory usage threshold exceeded Of Instance --&gt;oracle.4134 Value: 339320 Data: <br>
<br>ProcessMemoryUsage : 10.33.109.189.barajas_dms_1 : 25.5.1.1.2 Threshold Type: maxMajor Threshold : 204800Major <br><br>Rearm Value: 204799 <br><br><br>What i really mind is the following values:<br><br>ID: (generated with select sql given before)<br>
<br>select id from Event order by TTIME desc limit 1;&nbsp; (remember: INSERT $ID+1)<br>+-------+<br>| id&nbsp;&nbsp;&nbsp; |<br>+-------+<br>| 70857 |<br>+-------+<br><br>NODE:<br>bar_dms_1 for node slave1<br>leg_dms_2 for node slave2<br>cas_dms_3for node slave3.<br>
<br>TTIME, generated by $time=time()*1000; (or maybe 999 to fit into the numbers i get from the select) to then <br><br>rest to the localtime and if &gt; 300 this means im waiting for more than 5min the waitness, so i send the kill<br>
process remotelly.<br><br>TEXT: I need the following text: "Alert: Filesystem: /cosa : 100 % used"<br><br><br><br><br><br><br><br>----------Script that adds the SQL to a temporary file: (FAILING)--------------------------------<br>
<br>#!/usr/bin/perl<br><br>use DBI;<br><br><br># Main Server DB connection data<br>$db="CentralDB";<br>$host="localhost";<br>$puerto="3306";<br>$usuario="root";<br>$password="";<br>
<br># Prepare database query<br>$DatosConexion="DBI:mysql:database=$db;$host:$puerto";<br>$dbh=DBI-&gt;connect($DatosConexion,$usuario,$password);<br><br># QUERY<br><br>$sth=$dbh-&gt;prepare(q{ SELECT ID,TTIME,NODE,TEXT from Event where<br>
&nbsp;lower(text) like '%cosa%' Order By TTIME desc limit 1 });<br><br>$sth-&gt;execute(&nbsp; );<br><br>### Open the output file<br>open FILE, "&gt;results.txt" or die "Can't open results.lis: $!";<br>
<br>### Dump the formatted results to the file<br>$rows = $sth-&gt;dump_results(1,\*FILE );&nbsp;&nbsp; &lt;------------This fails...to put me in the auxiliary file (status)<br><br>### Close the output file<br>close FILE or die "Error closing result file: $!\n";<br>
<br>---------------------------------------------------------------------------------------------------------------<br><br>--------<br><br>OUTPUT:<br>MAIN_NODE# perl <a target="_blank" href="http://printmefiles.pl">printmefiles.pl</a><br>'1...', '1...', '1...', 'A...'<br>
1 rows<br><br>---------------------------------------------------------------------------------------------------------------<br><br>
</div></div></div></body></html>