checkName($name);
$this->checkNamespace($namespace);
// Delegate to Job, which already has the special handling to
// fetch an individual Job entity.
return $this->getReference($name, $namespace)->makeReady();
}
/**
* Creates a new search job.
*
* @param string $search The search query for the job to perform.
* @param array $args (optional) Job-specific creation arguments,
* merged with {
* **namespace**: (optional) {Splunk_Namespace} The namespace in which
* to create the entity. Defaults to the service's
* namespace.
* }
* For details, see the
*
* "POST search/jobs"
* endpoint in the REST API Documentation.
* @return Splunk_Job
* @throws Splunk_IOException
*/
public function create($search, $args=array())
{
$args = array_merge(array(
'search' => $search,
), $args);
if (array_key_exists('exec_mode', $args) && ($args['exec_mode'] === 'oneshot'))
throw new InvalidArgumentException(
'Cannot create oneshot jobs with this method. Use createOneshot() instead.');
$namespace = Splunk_Util::getArgument($args, 'namespace', NULL);
$response = $this->sendPost('', $args);
$xml = new SimpleXMLElement($response->body);
$sid = Splunk_XmlUtil::getTextContentAtXpath($xml, '/response/sid');
return $this->getReference($sid, $namespace);
}
/**
* Executes the specified search query and returns results immediately.
*
* @param string $search The search query for the job to perform.
* @param array $args (optional) Job-specific creation arguments,
* merged with {
* **namespace**: (optional) {Splunk_Namespace} The namespace in which
* to create the entity. Defaults to the service's
* namespace.
* }
* For details, see the
*
* "POST search/jobs"
* endpoint in the REST API Documentation.
* @return string The search results, which can be parsed with
* Splunk_ResultsReader.
* @throws Splunk_IOException
*/
public function createOneshot($search, $args=array())
{
$args = array_merge(array(
'search' => $search,
'exec_mode' => 'oneshot',
), $args);
if ($args['exec_mode'] !== 'oneshot')
throw new InvalidArgumentException(
'Cannot override "exec_mode" with value other than "oneshot".');
$response = $this->sendPost('', $args);
return $response->body;
}
}