/// <summary> /// Creates a URI for the specified hostname and database using authentication. Optionally uses the default retention policy (DEFAULT) and time precision (s). /// </summary> /// <param name="scheme">The URI scheme type, ie. http, https, net.udp</param> /// <param name="host">The hostname or IP address of the InfluxDB server.</param> /// <param name="port">The port number of the InfluxDB server. Set to zero to use the default of <see cref="InfluxConfig.Default.PortHttp"/>. This value is required for the UDP protocol.</param> /// <param name="database">The name of the database to write records to.</param> /// <param name="username">The username to use to authenticate to the InfluxDB server. Leave blank to skip authentication.</param> /// <param name="password">The password to use to authenticate to the InfluxDB server. Leave blank to skip authentication.</param> /// <param name="retentionPolicy">The retention policy to use. Leave blank to use the server default of "DEFAULT".</param> /// <param name="precision">The timestamp precision specifier used in the line protocol writes. Leave blank to use the default of <see cref="InfluxConfig.Default.Precision"/>.</param> /// <returns>A new InfluxDB URI using the specified parameters.</returns> public static Uri FormatInfluxUri(String scheme, String host, UInt16?port, String database, String username, String password, String retentionPolicy = null, InfluxPrecision?precision = null) { scheme = scheme ?? InfluxUtils.SchemeHttp; if ((port ?? 0) == 0 && (scheme == SchemeHttp || scheme == SchemeHttps)) { port = InfluxConfig.Default.PortHttp; } InfluxPrecision prec = precision ?? InfluxConfig.Default.Precision; String uriString = $@"{scheme}://{host}:{port}/write?db={database}"; if (!String.IsNullOrWhiteSpace(username)) { uriString += $@"&u={username}"; } if (!String.IsNullOrWhiteSpace(password)) { uriString += $@"&p={password}"; } if (!String.IsNullOrWhiteSpace(retentionPolicy)) { uriString += $@"&rp={retentionPolicy}"; } if (prec != InfluxPrecision.Nanoseconds) { uriString += $@"&precision={prec.ToShortName()}"; // only need to specify precision if it's not nanoseconds (the InfluxDB default) } return(new Uri(uriString)); //return new Uri($@"{scheme}://{host}:{port}/write?db={database}&u={username}&p={password}&rp={retentionPolicy}&precision={prec.ToShortName()}"); }
/// <summary> /// Creates an HTTP JSON URI for InfluxDB using the values specified in the <see cref="InfluxConfig"/> object. /// </summary> /// <param name="config">The configuration object to get the relevant fields to build the HTTP URI from.</param> /// <returns>A new InfluxDB JSON URI using the configuration specified in the <paramref name="config"/> parameter.</returns> protected Uri FormatInfluxUri(InfluxConfig config) { InfluxPrecision prec = config.Precision ?? InfluxConfig.Default.Precision; return(new Uri($@"http://{config.Hostname}:{config.Port}/db/{config.Database}/series?u={config.Username}&p={config.Password}&time_precision={prec.ToShortName()}")); }