下面是从ZabbixAPI读取项目名称的代码:
try {
// connect to Zabbix-API
$api = new ZabbixApi($api_url, $username, $password);
$params = array( 'groupids' => '2 ',
'real_items' =>TRUE,
'monitored_items' =>TRUE,
'search' => array('name' => 'Disk root used p'),
'selectFunctions' => 'extend',
'output' => 'name',
'sortfield' => 'name',
'lastvalue' => 'value'
);
$items = $api->itemGet($params); // get data from api
echo serialize($items);
foreach($items as $item) { // loop through the returned data
echo "<td>".$item."</td>";
}
} catch(Exception $e) {
// Exception in ZabbixApi catched
echo $e->getMessage();
}这样,我就可以得到每个项目的输出:
stdClass Object ( [itemid] => 81351 [name] => Disk root used p ) 但我只需要条目的“名称”,而不需要json对象,因此输出只是一个类似于:itemname1, itemname2....的数组。
发布于 2015-11-03 14:23:32
您可以执行以下操作:
$names = array();
foreach($items as $item) { // loop through the returned data
$names[] = $item->name;
}$names数组将是项名的数组。
https://stackoverflow.com/questions/33501299
复制相似问题