<?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>Emil Wayers &#187; mk livestats</title>
	<atom:link href="http://emil.wayers.com/archives/tag/mk-livestats/feed" rel="self" type="application/rss+xml" />
	<link>http://emil.wayers.com</link>
	<description>SSDD</description>
	<lastBuildDate>Thu, 24 Jun 2010 07:42:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>NagVis with MK Livestats compatible json_decode()</title>
		<link>http://emil.wayers.com/archives/486</link>
		<comments>http://emil.wayers.com/archives/486#comments</comments>
		<pubDate>Wed, 03 Feb 2010 14:31:19 +0000</pubDate>
		<dc:creator>emiL</dc:creator>
				<category><![CDATA[Anything]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[bugfix]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[json_decode]]></category>
		<category><![CDATA[mk livestats]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[nagvis]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://emil.wayers.com/?p=486</guid>
		<description><![CDATA[When installing the latest version of Nagvis (1.4.5) on my a RHEL 5.4 Apache instance (PHP 5.1) I really wanted it to connect to the new and cool MK Livestats backend for Nagios. Too bad the apparently recently added json_decode() function wasn&#8217;t tested for compatibility and it breaks Nagvis. Luckily the round-about-fix isn&#8217;t that complicated [...]]]></description>
			<content:encoded><![CDATA[<p>When installing the latest version of <a href="http://www.nagvis.org" target="_blank">Nagvis</a> (1.4.5) on my a RHEL 5.4 Apache instance (PHP 5.1) I really wanted it to connect to the new and cool <a href="http://www.mathias-kettner.de/checkmk_livestatus.html" target="_blank">MK Livestats</a> backend for <a href="http://www.nagios.org" target="_blank">Nagios</a>. Too bad the apparently <a href="http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=dbfef61b6bf8d5c714ae892fb22794f4b8645db6" target="_blank">recently</a> added <a href="http://php.net/json_decode" target="_blank">json_decode</a>() function wasn&#8217;t tested for compatibility and it breaks Nagvis. Luckily the round-about-fix isn&#8217;t that complicated and just fits in the current design of Nagvis.</p>
<p>To bugfix please edit your &#8220;nagvis/includes/functions/<strong>oldPhpVersionFixes.php</strong>&#8221; file and add (or replace if already present) the code below.</p>
<pre class="brush: php;">
/**
 * JSON Decode to PHP
 * (Needed for PHP &lt; 5.2.0)
 *
 * Function cannot compete with commented JSON inputs, please remove all
 * comments prior to input. Not tested with any other software other then
 * NagVis requirements.
 *
 * @param   String      JSON formatted code
 * @author  Emil Wayers
 * @version 1.0
 */
if(!function_exists('json_decode')){

  function json_decode($json) {

    $json = str_replace(array(&quot;\n&quot;,&quot;\r&quot;), &quot;&quot;, $json);
    $json = preg_replace('/([{,])(s*)([^&quot;]+?)s*:/' , '$1&quot;$3&quot;:', $json);

    $out = '$x=';

    $inside_value=false;

    for ($i=0; $i&lt;strlen($json); $i++) {
      if($json[$i] == '&quot;') {
        $inside_value = !$inside_value;
      }

      if($inside_value) {
        $out .= $json[$i];

      } else {
        switch($json[$i]) {
          case &quot;{&quot;: $out .= &quot; array(&quot;; break;
          case &quot;}&quot;: $out .= &quot;)&quot;;       break;
          case &quot;[&quot;: $out .= &quot; array(&quot;; break;
          case &quot;]&quot;: $out .= &quot;)&quot;;       break;
          case &quot;:&quot;: $out .= &quot;=&gt;&quot;;      break;
          default:
            $out .= $json[$i];
        }
      }
    }

    eval($out . ';');
    return $x;
  }
}
</pre>
<p>I also found a <a href="http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=blob_plain;f=share/server/core/functions/oldPhpVersionFixes.php">very  good hint</a> that this issue will be resolved within the next release&#8230;</p>
<p><b>Update</b>: You can always, pear install pecl/json</p>
]]></content:encoded>
			<wfw:commentRss>http://emil.wayers.com/archives/486/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
