/** * 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()); }
/** 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'); }
private static function parseDict($dictXml) { $dict = array(); foreach ($dictXml->children(Splunk_AtomFeed::NS_S)->key as $keyXml) { $key = Splunk_XmlUtil::getAttributeValue($keyXml, 'name'); $value = Splunk_AtomFeed::parseValueInside($keyXml); $dict[$key] = $value; } return $dict; }
/** * 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); }
/** * @param SimpleXMLElement $xml * @param string $xpathExpr * @return string|NULL */ public static function getTextContentAtXpath($xml, $xpathExpr) { $matchingElements = $xml->xpath($xpathExpr); return count($matchingElements) == 0 ? NULL : Splunk_XmlUtil::getTextContent($matchingElements[0]); }
/** Returns the <entry> element inside the root element. */ protected function extractEntryFromRootXmlElement($xml) { if (!Splunk_XmlUtil::isSingleElement($xml->entry)) { // Extract name from path since we can't extract it from the // entity content here. $pathComponents = explode('/', $this->path); $name = $pathComponents[count($pathComponents) - 1]; throw new Splunk_AmbiguousEntityNameException($name); } return $xml->entry; }
/** * 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}"; }