<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<tt>Hi Marco,<br>
<br>
you are very welcome and thanks for your reply. It was nice getting
deeper into the code for this use case and I'm assured it will help me
on the development of Icinga IDOUtils either way removing the blocking
behavior and enhance the debugoutput (next to rewriting the db handling
code for other rdbms like Postgres, Oracle, SQLite).<br>
<br>
Kind regards,<br>
Michael<br>
</tt><br>
Frassinelli, Marco wrote the following on 22.09.2009 09:24:
<blockquote
 cite="mid:F67BD758D4C6ED4B9BE7730A3D78A91C025E7E7A@derum202.emea.corp.eds.com"
 type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <meta name="Generator" content="Microsoft Word 12 (filtered medium)">
  <style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
tt
        {mso-style-priority:99;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:70.85pt 2.0cm 2.0cm 2.0cm;}
div.Section1
        {page:Section1;}
-->
  </style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
  <div class="Section1">
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Hi
  </span><span
 style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
 lang="EN-US">Michael<o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
 lang="EN-US"><o:p> </o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
 lang="EN-US">Thank you very much for the explanations. Finally I found
the
problem, it was a Nagios issue, too many reload where interrupting data
flow.<o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
 lang="EN-US">Now everything works very well.<o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
 lang="EN-US">By<o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
 lang="EN-US">Marco</span><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
 lang="EN-US"><o:p></o:p></span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
 lang="EN-US"><o:p> </o:p></span></p>
  <div>
  <div
 style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0cm 0cm;">
  <p class="MsoNormal" style="margin-left: 35.4pt;"><b><span
 style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
 lang="EN-US">From:</span></b><span
 style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
 lang="EN-US"> Michael Friedrich
[<a class="moz-txt-link-freetext" href="mailto:michael.friedrich@univie.ac.at">mailto:michael.friedrich@univie.ac.at</a>] <br>
  <b>Sent:</b> domenica 20 settembre 2009 2.34<br>
  <b>To:</b> Nagios Developers List<br>
  <b>Subject:</b> Re: [Nagios-devel] NDO utils bug/explanation<o:p></o:p></span></p>
  </div>
  </div>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><o:p> </o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><tt><span
 style="font-size: 10pt;">Hi,</span></tt><span
 style="font-size: 10pt; font-family: "Courier New";"><br>
  <br>
  <tt>Frassinelli, Marco wrote:</tt></span> <o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><tt><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
 lang="EN-US">Hello</span></tt><o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 70.8pt;"><tt><span
 style="font-size: 10pt;" lang="EN-US">The process of starting ndo2db
and then Nagios makes
sure that there is actual data within the DB. </span></tt><tt><span
 style="font-size: 10pt;">If there is an outdated data within the DB it
needs to
be removed before Nagios even sends new data. So the process of
trimming those
table entries is truly intentional at the beginning (so-called
pre-launch state
where the if condition matches). If ndo2db fails for some reason, those
data
will remain within the database and then removed during the next start.
  </span></tt><o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><tt><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">               
  </span></tt><tt><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
 lang="EN-US">Ok, when the parent ndo2db process starts. But not when
the
child starts.</span></tt><o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><tt><span
 style="font-size: 10pt;">Considering
the fact that the process runs daemonized and forks a child for each
ndomod
client connection, that is truly wrong. See the NDOUtils documentation
page 8:</span></tt><span
 style="font-size: 10pt; font-family: "Courier New";"><br>
  <tt><a moz-do-not-send="true"
 href="http://www.scribd.com/doc/17608352/Nagios-NDOUtils">http://www.scribd.com/doc/17608352/Nagios-NDOUtils</a></tt><br>
  <br>
  <tt>Going deeper into the code in ndo2db.c:main you will recognize
that after
initialization stuff that the standalone daemon condition matches.</tt><br>
  <br>
  <tt>        /* standalone daemon... */</tt><br>
  <tt>        else{</tt><br>
  <br>
  <tt>               
/* create socket and wait for clients to connect */</tt><br>
  <tt>               
if(ndo2db_wait_for_connections()==NDO_ERROR)</tt><br>
  <tt>                       
return 1;</tt><br>
  <tt>               
}</tt><br>
  <br>
  <tt>This function opens the socket wether tcp or unix. Then the
parent forks a
child to handle client data (0 = everythings ok, -1 = error).</tt><br>
  <br>
  <tt>               
/* fork... */</tt><br>
  <tt>               
new_pid=fork();</tt><br>
  <br>
  <tt>               
switch(new_pid){</tt><br>
  <tt>[...]</tt><br>
  <tt>               
case 0:</tt><br>
  <tt>#endif</tt><br>
  <tt>                       
/* child processes data... */</tt><br>
  <tt>                       
ndo2db_handle_client_connection(new_sd);</tt><br>
  <br>
  <tt>                       
/* close socket when we're done */</tt><br>
  <tt>                       
close(new_sd);</tt><br>
  <tt>#ifndef DEBUG_NDO2DB</tt><br>
  <tt>                       
return NDO_OK;</tt><br>
  <tt>                       
break;</tt><br>
  <tt>[...]</tt><br>
  <tt>                       
}</tt><br>
  <br>
  <tt>Parent runs in a while loop and if child has died on the client
connection,
it forks a new one.</tt><br>
  <tt>The child then reads the data from the socket within
ndo2db_handle_client_connection. If there's nothing on the socket, the
client
connection was lost and the while(1) terminates (also on errors),
meaning the
child to terminate too. The child performs the memory cleanup and db
disconnect
and then the process of the parent accepting new client connection and
forking
a child for each client connection starts again. </tt><br>
  <tt>Just look that up in the code, it's quite nice commented. </tt><br>
  <br>
  <tt>               
/* check for completed lines of input */</tt><br>
  <tt>               
ndo2db_check_for_client_input(&idi,&dbuf);</tt><br>
  <br>
  <tt>This function also decides if the actual client needs to be
disconnected.
So there are 3 main options that can lead to the termination of the
child:</tt><br>
  <br>
  <tt>* socket read result fails with -1, eagain/eintr -> <a
 moz-do-not-send="true" href="http://linux.die.net/man/2/read">http://linux.die.net/man/2/read</a></tt><br>
  <tt>* socket read is empty</tt><br>
  <tt>* client input is wrong protocol (idi->disconnect_client)</tt><br>
  <br>
  <tt>If one line has been read from the socket, it comes to
ndo2db_handle_client_input where the data frame is analyzed. If clients
protocol (ndomod) doesn't match ndo2db protocol, client will be
disconnected
and data ignored.</tt><br>
  <br>
  <tt>                       
/* client is using wrong protocol version, bail out here... */</tt><br>
  <tt>                       
if(idi->protocol_version!=NDO_API_PROTOVERSION){</tt><br>
  <tt>                               
syslog(LOG_USER|LOG_INFO,"Error: Client protocol version %d is
incompatible with server version %d.  Disconnecting
client...",idi->protocol_version,NDO_API_PROTOVERSION);</tt><br>
  <tt>                               
idi->disconnect_client=NDO_TRUE;</tt><br>
  <tt>                               
idi->ignore_client_data=NDO_TRUE;</tt><br>
  <tt>                               
return NDO_ERROR;</tt><br>
  <tt>                               
}</tt><br>
  <br>
  <tt>Other data will be read, parsed and saved by type as
idi->buffered_input
... If the data section is complete given by data_type==NDO_API_ENDDATA
then
ndo2db_end_input_data will be called wherein the dbhandling starts e.g.</tt><br>
  <br>
  <tt>        case
NDO2DB_INPUT_DATA_PROGRAMSTATUSDATA:</tt><br>
  <tt>               
result=ndo2db_handle_programstatusdata(idi);</tt><br>
  <tt>               
break;</tt><br>
  <br>
  <tt>values for the dbquery will be read
(dbhandler.c:,ndo2db_handle_programstatusdata) and then the queries are
sent to
db - currently MySQL only, calling ndo2db_db_query</tt><br>
  <br>
  <br>
  <tt>But the real question is - where is ndo2db_handle_processdata
called that
will perform the table trimming if program is starting up? Ok, that's
the same
datahandling.</tt><br>
  <br>
  <tt>        /* realtime Nagios data */</tt><br>
  <tt>        case
NDO2DB_INPUT_DATA_PROCESSDATA:</tt><br>
  <tt>               
result=ndo2db_handle_processdata(idi);</tt><br>
  <tt>               
break;</tt><br>
  <br>
  <tt>Looking at the way we got here it's quite simple to see that only
the child
will call this function. So everytime the child dies and gets forked
again, the
condition of starting up and outdated realtime data matches. And
furthermore,
the trimming of the tables. </tt><br>
  <br>
  <tt>-----------------------</tt><br>
  <tt>Stepping a bit more on the client side with ndomod, the data
comes from </tt><br>
  <br>
  <tt>                       
/* realtime data */</tt><br>
  <tt>                       
case NDO_API_PROCESSDATA:</tt><br>
  <tt>                               
idi->current_input_data=NDO2DB_INPUT_DATA_PROCESSDATA;</tt><br>
  <tt>                               
break;</tt><br>
  <br>
  <tt>which is generated in ndomod.c:ndomod_broker_data</tt><br>
  <br>
  <tt>        /* handle the event */</tt><br>
  <tt>        switch(event_type){</tt><br>
  <br>
  <tt>        case NEBCALLBACK_PROCESS_DATA:</tt><br>
  <br>
  <tt>and written to datasink</tt><br>
  <br>
  <tt>        /* write data to sink */</tt><br>
  <tt>        if(write_to_sink==NDO_TRUE)</tt><br>
  <tt>               
ndomod_write_to_sink(dbuf.buf,NDO_TRUE,NDO_TRUE);</tt><br>
  <br>
  <tt>-----------------------</tt><br>
  <tt>The conditional match for NEBTYPE_PROCESS_PRELAUNCH comes
directly from
Nagios and the defines for the Broker module. This type will be sent to
the
broker after loading all neb modules.</tt><br>
  <br>
  <tt>It seems that your Nagios version does not change this type or it
simply
reloads the broker module every 60 seconds. It could occur that the
nagios
process is restarted for whatever reason, since the do while loop runs
on
sigrestart==TRUE && sigshutdown==FALSE</tt><br>
  <br>
  <tt>But I am not very familiar with that, that's just a guess. The
only thing
is that the ndomod/ndo2db will receive the NEBTYPE_PROCESS_PRELAUNCH
and then
do the work. So the conclusion would be that they're working fine. </tt><br>
  <br>
  <tt>The only thing I could imagine at last is that the data
written/read from
the socket (tcp or unix) is truncated. The defines for the NEBTYPEs
only differ
by one or two bits. That could lead into errors but every 60 seconds is
kind of
weird....</tt><br>
  <br>
  <br>
  </span><o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><tt><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">               
  </span></tt><tt><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
 lang="EN-US">I am referring to the code in visualization software, not
ndo.</span></tt><o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><tt><span
 style="font-size: 10pt;">Then
you should point exactly to it as I am not aware what you meant or
which
codebase you are using. Furthermore you should mention Nagios and
NDOUtils
version, operating system and architecture.</span></tt> <o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"><br>
  <br>
  </span><o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><tt><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"
 lang="EN-US">               
The other strange thing is that ndo2db refork exactly every 60 seconds.
Where
in the code I can find this interval? Why the child ndo2db exits?</span></tt><o:p></o:p></p>
  <p class="MsoNormal" style="margin-left: 35.4pt;"><tt><span
 style="font-size: 10pt;">See
above, it seems that the event broker/ndomod doesn't send any data (or
the
socket is broken) and then a refork is performed. </span></tt><span
 style="font-size: 10pt; font-family: "Courier New";"><br>
  <br>
  <tt>How did you do that trace?</tt><br>
  <br>
  <tt>Kind regards,</tt><br>
  <tt>Michael</tt></span> <o:p></o:p></p>
  </div>
  <pre wrap="">
<hr size="4" width="90%">
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
<a class="moz-txt-link-freetext" href="http://p.sf.net/sfu/devconf">http://p.sf.net/sfu/devconf</a></pre>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Nagios-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Nagios-devel@lists.sourceforge.net">Nagios-devel@lists.sourceforge.net</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/nagios-devel">https://lists.sourceforge.net/lists/listinfo/nagios-devel</a>
  </pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">-- 
DI (FH) Michael Friedrich
<a class="moz-txt-link-abbreviated" href="mailto:michael.friedrich@univie.ac.at">michael.friedrich@univie.ac.at</a>
Tel: +43 1 4277 14359

Vienna University Computer Center
Universitaetsstrasse 7 
A-1010 Vienna, Austria  
</pre>
</body>
</html>