<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://forum.ubuntu-fr.org/extern.php?action=feed&amp;tid=1083271&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Forum Ubuntu-fr.org / [Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
		<link>http://forum.ubuntu-fr.org/viewtopic.php?id=1083271</link>
		<description><![CDATA[Les sujets les plus récents dans [Résolu] modifier une chaîne de caractères et convertir en nombre ?.]]></description>
		<lastBuildDate>Mon, 05 Nov 2012 10:01:09 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11396981#p11396981</link>
			<description><![CDATA[<div class="quotebox"><cite>cedric.amouyal a écrit&#160;:</cite><blockquote><div><p>s/^(\d{2})(\d).*$/$1.$2/;<br />excuse je me suis trompé dans ma regex..</p></div></blockquote></div><p>Merci ça marche <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (inserm)]]></author>
			<pubDate>Mon, 05 Nov 2012 10:01:09 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11396981#p11396981</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11313891#p11313891</link>
			<description><![CDATA[<p>s/^(\d{2})(\d).*$/$1.$2/;<br />excuse je me suis trompé dans ma regex..</p>]]></description>
			<author><![CDATA[dummy@example.com (cedric.amouyal)]]></author>
			<pubDate>Mon, 29 Oct 2012 17:35:25 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11313891#p11313891</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11310991#p11310991</link>
			<description><![CDATA[<div class="quotebox"><cite>cedric.amouyal a écrit&#160;:</cite><blockquote><div><p>Si tu veux que les 3 1er caractère ca devrait marcher avec ca aussi<br />$value =~ s/^(\d{2})(\d)/$1.$2/;</p><p>sans le substr...</p></div></blockquote></div><p>J&#039;ai testé ça donne ça : 22.0150250 et moi je veux 22.0 parce que la valeur que je récupéré : 220150250</p><p>Merci</p>]]></description>
			<author><![CDATA[dummy@example.com (inserm)]]></author>
			<pubDate>Mon, 29 Oct 2012 14:43:36 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11310991#p11310991</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11310821#p11310821</link>
			<description><![CDATA[<p>Si tu veux que les 3 1er caractère ca devrait marcher avec ca aussi<br />$value =~ s/^(\d{2})(\d)/$1.$2/;</p><p>sans le substr...</p>]]></description>
			<author><![CDATA[dummy@example.com (cedric.amouyal)]]></author>
			<pubDate>Mon, 29 Oct 2012 14:25:45 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11310821#p11310821</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11310181#p11310181</link>
			<description><![CDATA[<p>Merci<br />J&#039;ai trouvé en rajoutant deux lignes:</p><div class="codebox"><pre><code>	$value = substr($value,0,3);
			$value =~ s/^(\d+)(\d)$/$1.$2/;
			print &quot;$value\n&quot;;</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (inserm)]]></author>
			<pubDate>Mon, 29 Oct 2012 13:24:36 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11310181#p11310181</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11306681#p11306681</link>
			<description><![CDATA[<div class="quotebox"><cite>cedric.amouyal a écrit&#160;:</cite><blockquote><div><p>essaie ca<br />remplace<br /> $value =~ s/([0-9]*).*/$1/;<br />par ca<br /> $value =~ s/(\d+)\d$/$1/;</p></div></blockquote></div><p>J&#039;ai testé avec ce changement toujour le même résultat:</p><div class="codebox"><pre><code># ./check_string -H &lt;my_ipadress&gt;/tme.xml -s &quot;Thermometer&quot; -w 15 -c 25
CRITICAL Thermometer 220150250 | Thermometer=220150250;15;25</code></pre></div><div class="quotebox"><cite>cedric.amouyal a écrit&#160;:</cite><blockquote><div><p>en gros tu enleves le dernier chiffre.<br />ou<br />$value =~ s/^(\d+)(\d)$/$1.$2/;<br />ca fait 220 ==&gt; 22.0</p></div></blockquote></div><p>ça donne : </p><div class="codebox"><pre><code># ./check_string -H &lt;my_ipadress&gt;/tme.xml -s &quot;Thermometer&quot; -w 15 -c 25
CRITICAL Thermometer 22015025.0 | Thermometer=220150250;15;25</code></pre></div><p>Ce que je veux :</p><div class="codebox"><pre><code># ./check_string -H &lt;my_ipadress&gt;/tme.xml -s &quot;Thermometer&quot; -w 15 -c 25
CRITICAL Thermometer 22.0 | Thermometer=220150250;15;25</code></pre></div><p>C&#039;est à dire avoir comme résultat <span style="color: #ff1f3d">22.0</span> pas <span style="color: #eb1d38">22015025.0</span><br />C.f : Cette valeur est dans le fichire tme.xml entre la balise &lt;temperature&gt;220&lt;/temperature&gt; </p><p>Merci</p>]]></description>
			<author><![CDATA[dummy@example.com (inserm)]]></author>
			<pubDate>Mon, 29 Oct 2012 08:45:39 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11306681#p11306681</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11286801#p11286801</link>
			<description><![CDATA[<p>essaie ca<br />remplace<br /> $value =~ s/([0-9]*).*/$1/;<br />par ca<br /> $value =~ s/(\d+)\d$/$1/;</p><p>en gros tu enleves le dernier chiffre.<br />ou<br />$value =~ s/^(\d+)(\d)$/$1.$2/;<br />ca fait 220 ==&gt; 22.0</p>]]></description>
			<author><![CDATA[dummy@example.com (cedric.amouyal)]]></author>
			<pubDate>Sat, 27 Oct 2012 20:09:08 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11286801#p11286801</guid>
		</item>
		<item>
			<title><![CDATA[[Résolu] modifier une chaîne de caractères et convertir en nombre ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11278481#p11278481</link>
			<description><![CDATA[<p>J&#039;ai testé un script qui a l&#039;air de fonctionner pour mon matériel, mais je ne sais pas comment parser une valeur</p><p>En gros le script récupère la temperature capturé par une sonde et sur cette dernière que je fais les test<br />Voilà le script :</p><div class="codebox"><pre class="vscroll"><code>    #!/usr/bin/perl -w
    # nagios: -epn
    use strict;
    use warnings;
    use Switch;
    use lib &quot;/usr/lib/nagios/plugins&quot;;
    use utils qw(%ERRORS $TIMEOUT);
    use Getopt::Long;
    use vars qw/$opt_host $opt_string $opt_sep $opt_verbose $opt_w $opt_c $opt_help/;

    #### Main

    get_options();
    $TIMEOUT=60;
    my $lynx   = &#039;/usr/bin/lynx&#039;;
    my @input;
    my $command=&quot;$lynx -dump http://$opt_host | grep \&quot;$opt_string\&quot;&quot;;



    open(DATA,&quot;$command|&quot;) || die &quot;CRITICAL Could not execute $command&quot;;
    while(&lt;DATA&gt;) {
        chomp;
        push(@input,$_);
    }

    close(DATA);

    my $some_data_found=0;
    my $value;
    my $res=&#039;CRITICAL&#039;;
    my $nresult;
       foreach my $line (@input) {
          if ( $line =~ &quot;$opt_string&quot; ) {
             $some_data_found=1;
             $value = $line;
             $value =~ s/$opt_string//;
             $value =~ s/$opt_sep*//;
          # Extract number from $value
             $value =~ s/([0-9]*).*/$1/;
          }
       }
       
       if ( $value eq &quot;&quot; ) { print &quot;CRITICAL Search string has no value !\n&quot;; exit $ERRORS{&#039;CRITICAL&#039;}; }
       if ( defined($opt_w) ) { if ($value &lt; $opt_w) {$res=&#039;OK&#039;;} else {$res=&#039;WARNING&#039;;} }
       if ( defined($opt_c) &amp;&amp; ($res =~ &#039;WARNING&#039;||!defined($opt_w)) ) { if ($value &gt; $opt_c) {$res=&#039;CRITICAL&#039;;} }

    $nresult  = &quot;$res &quot;;
    $nresult .= &quot;$opt_string $value&quot;;
    $nresult .= &quot; | &quot;;
    $nresult .= &quot;$opt_string=$value&quot;;
    $nresult .= &quot;;$opt_w&quot; if ( defined($opt_w) );
    $nresult .= &quot;;$opt_c&quot; if ( defined($opt_c) );

    print (&quot;$nresult\n&quot;);

    if ( !$some_data_found || $opt_verbose ) {
       print &quot; CRITICAL No corresponding data has been found\nDebugging data: \n&quot; if(!defined($opt_verbose));
       print &quot;$command\n&quot;;
       foreach my $line (@input) {print &quot;$line\n&quot;;}
       exit $ERRORS{&#039;CRITICAL&#039;};
    }
    exit $ERRORS{&quot;$res&quot;};

    #### END MAIN

    sub get_options {
        Getopt::Long::Configure( &#039;bundling&#039; );
          GetOptions(
          &#039;H:s&#039;      =&gt; \$opt_host,      &#039;host&#039;      =&gt; \$opt_host,
          &#039;s:s&#039;           =&gt; \$opt_string,        &#039;string&#039;        =&gt; \$opt_string,
          &#039;k:s&#039;           =&gt; \$opt_sep,           &#039;separator&#039;     =&gt; \$opt_sep,
          &#039;v&#039;      =&gt; \$opt_verbose,   &#039;verbose&#039;   =&gt; \$opt_verbose,
          &#039;w:i&#039;      =&gt; \$opt_w,      &#039;warning&#039;   =&gt; \$opt_w,
          &#039;c:i&#039;      =&gt; \$opt_c,      &#039;critical&#039;   =&gt; \$opt_c,
          &#039;h&#039;      =&gt; \$opt_help,      &#039;help&#039;      =&gt; \$opt_help,
                     );
       if ( defined($opt_help) ) { &amp;print_help; exit $ERRORS{&#039;CRITICAL&#039;}; }
       if ( !defined($opt_string) ) { &amp;print_help; exit $ERRORS{&#039;CRITICAL&#039;}; }
       if ( !defined($opt_sep) ) { $opt_sep=&quot; &quot;; }
      }
    sub print_help {
    print &lt;&lt;EOT;

    Usage: check_pmta_connections -i/-o -w -c -x -d
            -H  --hostn=&lt;ip&#039;s of the server&gt;
          This must be defined
       -s, --string
          The string that must precede the monitored value
          This MUST be defined
       -k, --separator
          If not defined is space
       -v, --verbose
                    print extra debugging information
       -w, --warning  = &lt;warning threshold&gt;
       -c, --critical = &lt;critical threshold&gt;
       -h, --help   This help

    EOT
    }   </code></pre></div><p>quand je lance cette commande :</p><div class="codebox"><pre><code># ./check_string -H &lt;my_ipadress&gt;/tme.xml -s &quot;Thermometer&quot; -w 15 -c 25&lt;/code&gt;
CRITICAL Thermometer 220150250 | Thermometer=220150250;15;25</code></pre></div><p>comment parser la valeur <span style="color: #fa2112">220150250</span> ? en <span style="color: #f72111">22</span> ou 22.0</p><p>voilà mon fichier tme.xml</p><div class="codebox"><pre><code>&lt;thermometer&gt;
&lt;title&gt;Ethernet thermometer TME designed by Papouch s.r.o. - www.papouch.com&lt;/title&gt;
&lt;description&gt;Thermometer&lt;/description&gt;
&lt;temperature&gt;220&lt;/temperature&gt;
&lt;mintemperature&gt;150&lt;/mintemperature&gt;
&lt;maxtemperature&gt;250&lt;/maxtemperature&gt;
&lt;/thermometer&gt;</code></pre></div><p>Ce que je veux comme résultat si quelqu&#039;un peut m&#039;aider :</p><div class="codebox"><pre><code># ./check_string -H &lt;my_ipadress&gt;/tme.xml -s &quot;Thermometer&quot; -w 15 -c 25
OK Thermometer 22 | Thermometer=22;15;25


# ./check_string -H &lt;my_ipadress&gt;/tme.xml -s &quot;Thermometer&quot; -w 15 -c 25
CRITICAL Thermometer 26 | Thermometer=26;15;25


# ./check_string -H &lt;my_ipadress&gt;/tme.xml -s &quot;Thermometer&quot; -w 15 -c 25
WARNING Thermometer 14 | Thermometer=14;15;25</code></pre></div><p>Merci</p><p><em>edit modo : merci de poster dans la bonne section et de choisir des titres explicites à l&#039;avenir.</em></p>]]></description>
			<author><![CDATA[dummy@example.com (inserm)]]></author>
			<pubDate>Sat, 27 Oct 2012 10:00:00 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11278481#p11278481</guid>
		</item>
	</channel>
</rss>
