Hello,
I just start to use Zabbix few weeks ago and I'm really impressed by the product philosophy and possibilities...
I'm an old nagios user and several things I actually use with nagios or cacti are missing.
First one was Network Weather Map (www.network-weathermap.com) integration.
So I made a datasource plugins in order to retrieve item value from zabbix history and use it in network weather map :
The Target syntax is : zabbix:itemid_of_IN_value:temid_of_OUT_value
You need to write down the itemid of each item you want to integrate with. A little bit anoying, but that's working !
Also The plugin use only History_uint table for retreiving data.
/weathermap/lib/datasources/WeatherMapDataSource_zabbix.php
I just start to use Zabbix few weeks ago and I'm really impressed by the product philosophy and possibilities...
I'm an old nagios user and several things I actually use with nagios or cacti are missing.
First one was Network Weather Map (www.network-weathermap.com) integration.
So I made a datasource plugins in order to retrieve item value from zabbix history and use it in network weather map :
The Target syntax is : zabbix:itemid_of_IN_value:temid_of_OUT_value
You need to write down the itemid of each item you want to integrate with. A little bit anoying, but that's working !
Also The plugin use only History_uint table for retreiving data.
/weathermap/lib/datasources/WeatherMapDataSource_zabbix.php
Code:
<?php
// Zabbix Pluggable datasource for PHP Weathermap 0.9
// - read a pair of values from a database, and return it
// Actually the plugin look only in history_uint table
// TARGET zabbix:in:out
class WeatherMapDataSource_zabbix extends WeatherMapDataSource {
function Init(&$map)
{
if(! function_exists("mysql_real_escape_string") ) return FALSE;
if(! function_exists("mysql_connect") ) return FALSE;
return(TRUE);
}
function Recognise($targetstring)
{
if(preg_match("/^zabbix:([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/",$targetstring,$matches))
{
return TRUE;
}
else
{
return FALSE;
}
}
function ReadData($targetstring, &$map, &$item)
{
$data[IN] = NULL;
$data[OUT] = NULL;
$data_time = 0;
if(preg_match("/^zabbix:([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/",$targetstring,$matches))
{
$database_user = $map->get_hint('zabbix_dbuser');
$database_pass = $map->get_hint('zabbix_dbpass');
$database_name = $map->get_hint('zabbix_dbname');
$database_host = $map->get_hint('zabbix_dbhost');
$raw_in = mysql_real_escape_string($matches[1]);
$raw_out= mysql_real_escape_string($matches[2]);
debug ("Found for IN Value : $raw_in \n");
debug ("Found for OUT Value : $raw_out \n");
$SQL_IN = "select value from history_uint where itemid=$raw_in order by clock desc limit 1";
$SQL_OUT = "select value,clock from history_uint where itemid=$raw_out order by clock desc limit 1";
if(mysql_connect($database_host,$database_user,$database_pass))
{
if(mysql_select_db($database_name))
{
$result_IN = mysql_query($SQL_IN);
if (!$result_IN)
{
warn("Zabbix ReadData: Invalid query for IN Value: " . mysql_error()."\n");
}
else
{
$row_IN = mysql_fetch_assoc($result_IN);
$data[IN] = $row_IN['value'];
}
$result_OUT = mysql_query($SQL_OUT);
if (!$result_OUT)
{
warn("Zabbix ReadData: Invalid query for OUT Value: " . mysql_error()."\n");
}
else
{
$row_OUT = mysql_fetch_assoc($result_OUT);
$data[OUT] = $row_OUT['value'];
$data_time = $row_OUT['clock'];
}
}
else
{
warn("Zabbix ReadData: failed to select database ($database_name): ".mysql_error()."\n");
}
}
else
{
warn("Zabbix ReadData: failed to connect to database server: ".mysql_error()."\n");
}
// $data_time = now();
}
debug ("RRD ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[IN]).",$data_time)\n");
return( array($data[IN], $data[OUT], $data_time) );
}
}
?>



Comment