Snippets Collections
    public class Centreon
    {
        private String url = @"";
        private String user = "";
        private String password = "";
        private String token = "";
        public CentreonErrors result;

        public async Task<bool> setToken()
        {
            HttpClient client = new HttpClient();
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(url + "/api/v2/login"));
            requestMessage.Content = new StringContent("{\"security\":{\"credentials\":{\"login\":\"" + user + "\",\"password\":\"" + password + "\"}}}", Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.SendAsync(requestMessage);
            String responseString = await response.Content.ReadAsStringAsync();

            token = responseString.Split(':').Last().Replace("\"", "").Replace("}", ""); //etwas unschön

            return true; //TODO
        }

        public async Task<bool> getErrors()
        {
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("x-auth-token", token);
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri(url + "/api/beta/monitoring/services?limit=100&search={\"service.state\":{\"$gt\":\"0\"}}"));

            HttpResponseMessage response = await client.SendAsync(requestMessage);
            String responseString = await response.Content.ReadAsStringAsync();

            result = Newtonsoft.Json.JsonConvert.DeserializeObject<CentreonErrors>(responseString); //etas unschön

            return true; //TODO
        }
    }

    public class CentreonErrors
    {
        public List<CentreonResult> result = new List<CentreonResult>();
        public CentreonMeta meta = new CentreonMeta();
    }

    public class CentreonResult
    {
        public int id;
        public int check_attempt;
        public String description;
        public String display_name;
        public CentreonHost host;
        public DateTime last_check;
        public String output;
        public int state;
        public int state_type;
        public CentreonStatus status;
    }

    public class CentreonHost
    {
        public int id;
        public String name;
        public String alias;
        public String display_name;
        public int state;
    }

    public class CentreonStatus
    {
        public int code;
        public String name;
        public int severity_code;
    }

    //wird vmtl. nicht benötigt
    public class CentreonMeta
    {
        public int page;
        public int limit;
        public int total;
    }
star

Mon Jun 28 2021 06:30:36 GMT+0000 (UTC)

#c# #asp.net #centreon

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension