Skip to content

Instantly share code, notes, and snippets.

@alexander-williamson
Created June 14, 2017 16:00
Show Gist options
  • Save alexander-williamson/9255a9dfdb63e87d44a432911f016ea0 to your computer and use it in GitHub Desktop.
Save alexander-williamson/9255a9dfdb63e87d44a432911f016ea0 to your computer and use it in GitHub Desktop.
How to send files to logz.io kibana and have properties accepted as fields
using System;
using System.Net;
using RestSharp;
namespace Alexw.ParkingAvailable
{
public class KibanaClient
{
private readonly IRestClient _client;
private readonly string _token;
public KibanaClient(IRestClient client, string token)
{
_client = client;
_token = token;
}
public void Upload<T>(params T[] objectsToUpload)
{
if(objectsToUpload == null)
throw new ArgumentOutOfRangeException("objectsToUpload");
var relativeUrl = "";
if (!string.IsNullOrEmpty(_token))
{
relativeUrl += relativeUrl.Contains("?") ? "&" : "?";
relativeUrl += "token=" + _token;
}
foreach (var element in objectsToUpload)
{
var request = new RestRequest(relativeUrl);
request.AddJsonBody(element);
var response = _client.Post(request);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new Exception(response.ErrorMessage);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment