$jobList = array(); foreach ($xml->answer[0]->state[0]->jobs[0] as $jobs) { // JobSchedulerに定義されているJob情報を$jobListに配列として格納 array_push($jobList, $jobs->attributes()->path); } $msg = 'sending start' . "\n"; $msg = $msg . '------------------------------------------------------------' . "\n"; // 全job情報の履歴を取得してzabbix_sender経由でzabbixへ登録する処理の開始 // zabbixへまだ登録していないJob実行履歴のみを取得してzabbixへ登録 for ($i = 0; $i < count($jobList); $i++) { $job = $jobList[$i]; // ZabbixのKeyとして利用できない文字を'.'へReplaceする。 $tobeRepl = array('/', '#'); $keyHeader = str_replace($tobeRepl, '.', $job); // Zabbixにelapseに対応するKeyが登録されていないJobはスキップする。 $items = $api->itemGet(array('output' => 'extend', 'search' => array('key_' => $keyHeader . $KEY_ELAPSE), 'inherited' => 'true', 'sortfield' => 'itemid')); if ($items == NULL) { $msg = $msg . "Job : " . $job . " is skipped.\n"; continue; } // 該当jobの前回取得した最後のidを取得する $items = $api->itemGet(array('output' => 'extend', 'search' => array('key_' => $keyHeader . $KEY_ID), 'inherited' => 'true', 'sortfield' => 'itemid')); // Zabbixにidに対応するKeyが登録されていないJobはスキップする。 if ($items == NULL) { $msg = $msg . "Job : " . $job . " is skipped.\n"; continue; } $lastId = $items[0]->lastvalue; // zabbixへの登録が初回の場合はlastId(前回記録したJobSchedulerでJob毎に割り振られるid)がzabbixから取得出来ない為、 // JobSchedulerの初期値である「1」を設定する if ($lastId < 2) {