How to get values item from history via API?
Is there such a function? The documentation did not find anything similar.
Is there such a function? The documentation did not find anything similar.
public static function lastvalue($options=array())
{
$sql = 'SELECT i.*, ht.value as value2, ht.clock as clock2 ';
$sql.= ' FROM history_text ht INNER JOIN items i ON ht.itemid=i.itemid ';
$sql.= ' WHERE UPPER(i.key_) = '.zbx_dbstr(strtoupper($options['key']));
$sql.= ' AND i.hostid='.$options['hostid'];
$sql.= ' ORDER BY ht.clock DESC ';
$sql.= ' LIMIT 1';
$res = DBselect($sql);
$result = DBfetch($res);
return $result;
}
$data = ZabbixAPI::fetch_array('item','lastvalue',array(
'hostid' => 12345,
'key' => 'system.uptime'
));
print_r($data);
public static function lastvalue($options=array())
{
$sql = 'SELECT itemid, value_type AS type, lastclock AS clock, FROM_UNIXTIME(lastclock) AS time, lastvalue AS value, prevvalue AS prevvalue, status, error';
$sql.= ' FROM items';
$sql.= ' WHERE UPPER(key_) = '.zbx_dbstr(strtoupper($options['key']));
$sql.= ' AND hostid='.$options['hostid'];
$itq = DBselect($sql);
$item = DBfetch($itq);
$itemid=$item["itemid"];
switch ($item["type"]) {
case 0:
$table="history";
break;
case 1:
$table="history_str";
case 2:
$table="history_log";
break;
case 3:
$table="history_uint";
break;
case 4:
$table="history_text";
break;
}
$item["table"] = $table;
return $item;
}
Comment