Exemple #1
0
 /**
  * Runs this saved search and returns the resulting search job.
  * 
  * @param array $args   (optional) Additional arguments.
  *                      For details, see the
  *                      <a href="http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#saved.2Fsearches.2F.7Bname.7D.2Fdispatch">
  *                      "POST saved/searches/{name}/dispatch"</a>
  *                      endpoint in the REST API Documentation.
  * @return Splunk_Job
  *                      The created search job.
  */
 public function dispatch($args = array())
 {
     $response = $this->sendPost('/dispatch', $args);
     $xml = new SimpleXMLElement($response->body);
     $sid = Splunk_XmlUtil::getTextContentAtXpath($xml, '/response/sid');
     return $this->service->getJobs()->getReference($sid, $this->getNamespace());
 }
Exemple #2
0
 /** Parses an HTTP response. */
 private static function parseFirstMessageFrom($response)
 {
     if ($response->body == '') {
         return NULL;
     }
     return Splunk_XmlUtil::getTextContentAtXpath(new SimpleXMLElement($response->body), '/response/messages/msg');
 }
Exemple #3
0
 /**
  * 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 {<br/>
  *     **namespace**: (optional) {Splunk_Namespace} The namespace in which
  *                    to create the entity. Defaults to the service's
  *                    namespace.<br/>
  * }<br/>
  *                      For details, see the
  *                      <a href="http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#search.2Fjobs">
  *                      "POST search/jobs"</a>
  *                      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);
 }
Exemple #4
0
 /**
  * Authenticates to the Splunk server.
  */
 public function login()
 {
     $response = $this->http->post($this->url('/services/auth/login'), array('username' => $this->username, 'password' => $this->password));
     $sessionKey = Splunk_XmlUtil::getTextContentAtXpath(new SimpleXMLElement($response->body), '/response/sessionKey');
     $this->token = "Splunk {$sessionKey}";
 }