Exemplo n.º 1
0
        /// <summary>
        /// Retrieve the process monitors
        /// </summary>
        /// <param name="apiKey"></param>
        /// <param name="client"></param>
        /// <param name="showMonitors"></param>
        public void GetExternalMonitors(string apiKey, HttpClient client, List <string> argMonitors)
        {
            using (HttpResponseMessage response = client.Get("api?apikey=" + apiKey + "&output=xml&version=2&action=tests"))
            {
                response.EnsureStatusIsSuccessful();

                String    data = response.Content.ReadAsString();
                XDocument xml  = XDocument.Parse(data);

                // copy the list of monitors from the command line
                List <string> showMonitors = new List <string>(argMonitors);

                // check if the list of monitors to show is 'all' or 'empty'
                if (showMonitors.Count == 0)
                {
                    foreach (MonitorDefinition md in ExternalMonitor.GetMonitorDefinitions())
                    {
                        showMonitors.Add(md.Metric);
                    }
                }


                // filter the monitors from the returned XML
                var allMonitors = from monitorNode in xml.Descendants("test")
                                  select new
                {
                    Id   = monitorNode.Attribute("id").Value,
                    Name = monitorNode.Value
                };

                // create all the monitor objects and copy in the values from the XML results
                foreach (var a in allMonitors)
                {
                    foreach (string m in showMonitors)
                    {
                        if (a.Name.ToLower().Contains(m.ToLower()) || m.ToLower() == "all")
                        {
                            Monitor monitor = new ExternalMonitor(this);
                            monitor.Id   = a.Id;
                            monitor.Name = a.Name;
                            monitor.GetMetrics(apiKey, client);
                            this.AddMonitor(monitor);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieve the process monitors
        /// </summary>
        /// <param name="apiKey"></param>
        /// <param name="client"></param>
        /// <param name="showMonitors"></param>
        public void GetExternalMonitors(string apiKey, HttpClient client, List<string> argMonitors)
        {
            using (HttpResponseMessage response = client.Get("api?apikey=" + apiKey + "&output=xml&version=2&action=tests"))
            {
                response.EnsureStatusIsSuccessful();

                String data = response.Content.ReadAsString();
                XDocument xml = XDocument.Parse(data);

                // copy the list of monitors from the command line
                List<string> showMonitors = new List<string>(argMonitors);

                // check if the list of monitors to show is 'all' or 'empty'
                if (showMonitors.Count == 0)
                {
                    foreach (MonitorDefinition md in ExternalMonitor.GetMonitorDefinitions())
                        showMonitors.Add(md.Metric);
                }

                // filter the monitors from the returned XML
                var allMonitors = from monitorNode in xml.Descendants("test")
                                    select new
                                    {
                                        Id = monitorNode.Attribute("id").Value,
                                        Name = monitorNode.Value
                                    };

                // create all the monitor objects and copy in the values from the XML results
                foreach (var a in allMonitors)
                {
                    foreach (string m in showMonitors)
                    {
                        if (a.Name.ToLower().Contains(m.ToLower()) || m.ToLower() == "all")
                        {
                            Monitor monitor = new ExternalMonitor(this);
                            monitor.Id = a.Id;
                            monitor.Name = a.Name;
                            monitor.GetMetrics(apiKey, client);
                            this.AddMonitor(monitor);
                        }
                    }
                }
            }
        }