/// <summary> /// Ensures that the given path is fully qualified, prepending a path /// prefix if necessary. /// </summary> /// <param name="path">The path.</param> /// <param name="splunkNamespace">The Splunk namespace.</param> /// <returns>A fully qualified URL.</returns> /// <remarks> /// The path prefix is constructed using the current owner and app /// context when available. /// </remarks> public string Fullpath(string path, Args splunkNamespace) { // If already fully qualified (i.e. root begins with /), then return // the already qualified path. if (path.StartsWith("/")) { return(path); } // If no namespace at all and no service instance of app and no // sharing, return base service endpoint + path. if (splunkNamespace == null && this.App == null) { return("/services/" + path); } // Base namespace values. string localApp = this.App; string localOwner = this.Owner; string localSharing = string.Empty; // Override with invocation namespace if set. if (splunkNamespace != null) { if (splunkNamespace.ContainsKey("app")) { localApp = (string)splunkNamespace["app"]; } if (splunkNamespace.ContainsKey("owner")) { localOwner = (string)splunkNamespace["owner"]; } if (splunkNamespace.ContainsKey("sharing")) { localSharing = (string)splunkNamespace["sharing"]; } } // Sharing, if set calls for special mapping, override here. // "user" --> {user}/{app} // "app" --> nobody/{app} // "global" --> nobody/{app} // "system" --> nobody/system if (localSharing.Equals("app") || localSharing.Equals("global")) { localOwner = "nobody"; } else if (localSharing.Equals("system")) { localApp = "system"; localOwner = "nobody"; } return(string.Format( "/servicesNS/{0}/{1}/{2}", localOwner == null ? "-" : localOwner, localApp == null ? "-" : localApp, path)); }
/// <summary> /// Creates a search with a UTF-8 pre-encoded search request. /// </summary> /// <remarks> /// A "oneshot" request is invalid. To create a oneshot search, /// use the <see cref="Service.Oneshot(string)"/> method instead. /// </remarks> /// <param name="query">The search query.</param> /// <param name="args">Additional arguments for this job.</param> /// <returns>The job.</returns> public new Job Create(string query, Args args) { if (args != null && args.ContainsKey("exec_mode")) { if (args["exec_mode"].Equals("oneshot")) { throw new Exception( "Oneshot not allowed, use service oneshot search method"); } } args = Args.Create(args).Set("search", query); ResponseMessage response = Service.Post(Path, args); /* assert(response.getStatus() == 201); */ StreamReader streamReader = new StreamReader(response.Content); XmlDocument doc = new XmlDocument(); doc.LoadXml(streamReader.ReadToEnd()); string sid = doc.SelectSingleNode("/response/sid").InnerText; Job job = new Job(Service, "search/jobs/" + sid); job.Refresh(); return(job); }
/// <summary> /// Initializes a new instance of the <see cref="Resource"/> class, /// adding optional arguments for namespace and other endpoint /// arguments. /// </summary> /// <param name="service">The service.</param> /// <param name="path">The path of this resource.</param> /// <param name="args">The variable arguments.</param> public Resource(Service service, string path, Args args) { this.Service = service; /* Pull out namespace items (app, owner, sharing) from the args, and * then use to create the full path. */ Args clonedArgs = new Args(args); Args splunkNamespace = new Args(); if (args.ContainsKey("app")) { splunkNamespace.Set("app", args["app"].ToString()); clonedArgs.Remove("app"); } if (args.ContainsKey("owner")) { splunkNamespace.Set("owner", args["owner"].ToString()); clonedArgs.Remove("owner"); } if (args.ContainsKey("sharing")) { splunkNamespace.Set( "sharing", args["sharing"].ToString()); clonedArgs.Remove("sharing"); } if (!clonedArgs.ContainsKey("count")) { clonedArgs.Set("count", "-1"); } this.RefreshArgs = clonedArgs; this.Path = service.Fullpath( path, splunkNamespace.Count == 0 ? null : splunkNamespace); this.MaybeValid = false; }