コード例 #1
0
ファイル: API.cs プロジェクト: henrikx/cachet-monitor
        public Dictionary <string, dynamic> GetComponents()
        {
            string   URL     = Configuration.GetConfiguration().BaseURL + "components/";
            string   API     = Configuration.GetConfiguration().APIKey;
            HTTPBase apiBase = new HTTPBase();
            var      options = new JsonSerializerOptions();

            options.Converters.Add(new ObjectToInferredTypesConverter());
            Dictionary <string, dynamic> response = JsonSerializer.Deserialize <Dictionary <string, dynamic> >(apiBase.getRequestString(URL, API), options);

            return(response);
        }
コード例 #2
0
ファイル: API.cs プロジェクト: henrikx/cachet-monitor
        public Dictionary <string, dynamic> UpdateComponentStatus(int id, int status)
        {
            string URL  = Configuration.GetConfiguration().BaseURL + "components/" + id.ToString();
            string API  = Configuration.GetConfiguration().APIKey;
            string JSON = JsonSerializer.Serialize <Dictionary <string, dynamic> >(new Dictionary <string, dynamic> {
                { "status", status }
            }, new JsonSerializerOptions()
            {
                IgnoreNullValues = true
            });

            LastActionRequest = JSON;
            HTTPBase apiBase = new HTTPBase();
            var      options = new JsonSerializerOptions();

            options.Converters.Add(new ObjectToInferredTypesConverter());
            Dictionary <string, dynamic> response = JsonSerializer.Deserialize <Dictionary <string, dynamic> >(apiBase.putRequestString(URL, API, JSON), options);

            return(response);
        }
コード例 #3
0
ファイル: API.cs プロジェクト: henrikx/cachet-monitor
        public Dictionary <string, dynamic> UpdateIncident(int id, string title = null, string message = null, int?status = null, int?visible = null, int?componentid = null, int?componentstatus = null, bool?stickied = null)
        {
            string URL  = Configuration.GetConfiguration().BaseURL + "incidents/" + id.ToString();
            string API  = Configuration.GetConfiguration().APIKey;
            string JSON = JsonSerializer.Serialize <Dictionary <string, dynamic> >(new Dictionary <string, dynamic> {
                { "name", title }, { "message", message }, { "status", status }, { "visible", visible }, { "component_id", componentid }, { "component_status", componentstatus }, { "stickied", stickied }
            }, new JsonSerializerOptions()
            {
                IgnoreNullValues = true
            });

            LastActionRequest = JSON;
            HTTPBase apiBase = new HTTPBase();
            var      options = new JsonSerializerOptions();

            options.Converters.Add(new ObjectToInferredTypesConverter());
            Dictionary <string, dynamic> response = JsonSerializer.Deserialize <Dictionary <string, dynamic> >(apiBase.putRequestString(URL, API, JSON), options);

            return(response);
        }
コード例 #4
0
        public bool CheckHTTP(string URL, int statuscodeMin = 200, int statuscodeMax = 399)
        {
            bool     alive    = true;
            HTTPBase httpBase = new HTTPBase();

            try
            {
                HttpWebResponse response = httpBase.getRequest(URL, verifySSL: VerifySSL);
                if ((int)response.StatusCode >= statuscodeMin && (int)response.StatusCode <= statuscodeMax)
                {
                    alive = true;
                }
                else
                {
                    alive = false;
                }
            } catch (WebException ex)
            {
                alive = false;
                var response = ex.Response as HttpWebResponse;
                if (response != null && (int)response.StatusCode >= statuscodeMin && (int)response.StatusCode <= statuscodeMax)
                {
                    alive = true;
                }
                else
                {
                    Console.WriteLine($"Host {URL} failed with message {ex.Message}");
                }
            }
            catch (OperationCanceledException ex)
            {
                Console.WriteLine($"Host {URL} failed with message {ex.Message}");
                alive = false;
            }
            previousRunResult = alive;
            return(alive);
        }