Zabbix 阅读 Api

Zabbix Reading the Api

我正在使用 PHP 库从 Zabbix Api 获取信息。目前我从 json 数组中得到 "lastvalue":

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'            => 'extend', 
                            'sortfield'         => 'name',
                            'limit'             => '1'

                            );



    $trends = $api->itemGet($params); // get data from api

  $names = array();
    foreach($trends as $trend)  {       // loop through the returned data
      $names[] = $trend->lastvalue;

    }
//print_r($names);

} catch(Exception $e) {

    // Exception in ZabbixApi catched
    echo $e->getMessage();
}

但现在我想获得 "lastvalue" 加上此数组中项目的 "name",例如:"name"+"lastvalue"。如何将它们都放入我的数组 $names[]?

这是我的评论中的答案,希望是您要找的!

$trends = $api->itemGet($params);
$names = array();
foreach($trends as $trendKey => $trendValue)
{
    $names[$trendKey] = $trendValue;
}

#Test the names array
foreach ($names as $nameKey => $nameValue)
{
    print("{$nameKey} = {$nameValue}<br />");
}

Return 值:

groupids = 2
real_items = TRUE
...
sortfield = name
limit = 1