static function execMonitoringJob(Job $job, $opt) { // fetch last state of all hosts $laststates = array(); foreach (Laststate::find_many() as $host) { $laststates[$host->hostname] = $host->as_array(); } // $optsetgroup = array(); $job->last_started = time(); $job->job_status = Job::STATUS_RUNNING; $job->save(); foreach (Ou::where('logging', 1)->find_many() as $ou) { $optsetgroup[$ou->optionset_id][] = $ou->id; } // now exec amtc -I ... on each group of hosts with same optionset foreach ($optsetgroup as $optsetid => $ou_array) { $hosts = array(); foreach ($ou_array as $ou_id) { $hosts = array_merge($hosts, self::getOuHosts($ou_id, true)); } $maxThreads = 180; // This should be a global config option! if (count($hosts) < $maxThreads) { $job->amtc_hosts = implode(',', $hosts); $job->ou_id = $ou_array[0]; // one OU setting fits all here, as it's the same... self::updateHostState(self::execAmtCommand($job, $opt), $opt, $laststates); } else { // more than maxThreads hosts to scan, slice hosts array $hostsCompleted = 0; while ($hostsCompleted < count($hosts)) { $workpack = array_slice($hosts, $hostsCompleted, $maxThreads); $hostsCompleted += count($workpack); $job->amtc_hosts = implode(',', $workpack); $job->ou_id = $ou_array[0]; // one OU setting fits all here, as it's the same... self::updateHostState(self::execAmtCommand($job, $opt), $opt, $laststates); } } } $job->last_done = time(); $job->job_status = Job::STATUS_PENDING; $job->ou_id = NULL; $job->amtc_hosts = NULL; $job->save(); }