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;
    }
public static async void downloadAllFiles() {

    var credentials = new NetworkCredential("USERNAME", "PASSWORD");
    var webDavSession = new WebDavSession(@"https://cp.DOMAIN/remote.php/dav/files/USERNAME/", credentials);
    var items = await webDavSession.ListAsync(@"APK-Test/");

    foreach (var item in items)
    {
        //await webDavSession.DownloadFileAsync(item.Uri, STREAM);

        WebClient myWebClient = new WebClient();
        myWebClient.Credentials = credentials;
        myWebClient.DownloadFile(item.Uri, @"C:\temp" + item.Name);

        Console.WriteLine(item.Name);
    }

}
star

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

#c# #asp.net #centreon
star

Wed Jun 23 2021 05:32:19 GMT+0000 (UTC)

#c# #nextcloud #asp.net #webdav

Save snippets that work with our extensions

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