protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:     //Get a group
                Assert.AreEqual(UnitRequest.Groups("count=1", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem()));

            case 2:     //Are there any other groups called "Windows Infrastructure"?
                Assert.AreEqual(UnitRequest.Groups("count=*&filter_name=Windows+Infrastructure", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem()));

            case 3:     //Get all sensors under the group "Windows Infrastructure"
                Assert.AreEqual(UnitRequest.Sensors("count=*&filter_name=@sub(ping)&filter_group=Windows+Infrastructure", UrlFlag.Columns), address);
                return(new SensorResponse(new SensorItem(name: "First"), new SensorItem(name: "Ping")));

            case 4:     //Get the child groups of "Windows Infrastructure"
                Assert.AreEqual(UnitRequest.Groups("count=*&filter_parentid=2211", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem(name: "Child Group")));

            case 5:     //Are there any other groups called "Child Group"?
                Assert.AreEqual(UnitRequest.Groups("count=*&filter_name=Child+Group", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem(name: "Child Group")));

            case 6:     //Get all sensors under the group "Child Group"
                Assert.AreEqual(UnitRequest.Sensors("count=*&filter_name=@sub(ping)&filter_group=Child+Group", UrlFlag.Columns), address);
                return(new SensorResponse(new SensorItem(name: "Second"), new SensorItem(name: "Ping"), new SensorItem(name: "Ping")));

            default:
                throw UnknownRequest(address);
            }
        }
Пример #2
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Groups("count=1", UrlFlag.Columns), address);
                return(new BasicResponse(standardResponse.GetResponseText(ref address)));

            case 2:
                Assert.AreEqual(UnitRequest.Groups("filter_objid=9999"), address);
                return(new GroupResponse(new GroupItem(objid: "2000", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")));

            //Tree

            case 3:
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=2000"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3001"), new DeviceItem(objid: "3002")));

            case 4:
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3001"), address);
                return(new SensorResponse(new SensorItem(objid: "4001")));

            case 5:
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3002"), address);
                return(new SensorResponse(new SensorItem(objid: "4002")));

            default:
                throw UnknownRequest(address);
            }
        }
Пример #3
0
        public async Task SetTriggerProperty_ChannelAsync()
        {
            var triggerItem = NotificationTriggerItem.ThresholdTrigger(channel: "Backup State", parentId: "4000");
            var channelItem = new ChannelItem(name: "Backup State");
            var response    = new NotificationTriggerResponse(new[] { triggerItem }, new[] { channelItem });
            var client      = Initialize_Client(response);

            var trigger = client.GetNotificationTriggers(4000).First(t => t.Type == TriggerType.Threshold);

            await ExecuteAsync(
                async c =>
            {
                var channel = await c.GetChannelAsync(4000, 1);

                await c.SetTriggerPropertyAsync(trigger, TriggerProperty.Channel, channel);
            },
                new[]
            {
                UnitRequest.Channels(4000),
                UnitRequest.ChannelProperties(4000, 1),
                UnitRequest.Sensors("filter_objid=4000"),
                UnitRequest.Channels(4000),
                UnitRequest.ChannelProperties(4000, 1),
                UnitRequest.EditSettings("id=4000&subid=7&channel_7=1")
            }
                );
        }
Пример #4
0
        protected void ExecuteUnsupportedInternal <TSource, TResult>(
            Func <PrtgClient, IQueryable <TSource> > query,
            Func <IQueryable <TSource>, IQueryable <TResult> > illegalAction,
            string message,
            Func <IQueryable <TSource>, IEnumerable <TResult> > legalAction,
            string legalUrl,
            Action <List <TResult> > legalValidator
            )
        {
            AssertEx.Throws <NotSupportedException>(
                () => ExecuteClient(c => illegalAction(query(c)), new string[] { }, s => s.ToList()),
                message
                );

            var flags = UnitRequest.DefaultObjectFlags & ~UrlFlag.Count;

            if (!legalUrl.Contains("count"))
            {
                legalUrl = "count=500" + (string.IsNullOrEmpty(legalUrl) ? legalUrl : $"&{legalUrl}");
            }

            var urls = new[]
            {
                typeof(TSource) == typeof(Log) ? UnitRequest.Logs(legalUrl, flags) : UnitRequest.Sensors(legalUrl, flags)
            };

            ExecuteClient(c => legalAction(query(c)), urls, s => legalValidator(s.ToList()));
        }
Пример #5
0
        protected void ExecuteUnsupportedNow <TResult>(
            Func <IQueryable <Sensor>, TResult> illegalAction,
            string message,
            Func <IQueryable <Sensor>, TResult> legalAction,
            string legalUrl,
            Action <TResult> legalValidator
            )
        {
            AssertEx.Throws <NotSupportedException>(
                () => ExecuteClient(c => illegalAction(c.QuerySensors(true)), new string[] { }, null),
                message
                );

            var flags = UnitRequest.DefaultObjectFlags & ~UrlFlag.Count;

            if (!legalUrl.Contains("count"))
            {
                legalUrl = "count=500" + (string.IsNullOrEmpty(legalUrl) ? legalUrl : $"&{legalUrl}");
            }

            var urls = new[]
            {
                UnitRequest.Sensors(legalUrl, flags)
            };

            ExecuteClient(c => legalAction(c.QuerySensors(true)), urls, legalValidator);
        }
Пример #6
0
 public void Query_Where_Intermediate_NewSensor_ToWhere()
 {
     ExecuteClient(c => c.QuerySensors().Where(s => new Sensor
     {
         Message = s.Name
     }.Message == "test").Where(s => s.Id == 4000), new[] { UnitRequest.Sensors("count=500&filter_name=test&filter_objid=4000", UrlFlag.Columns) }, s => s.ToList());
 }
Пример #7
0
        public void Query_Where_Sensors_MatchAnyDevices()
        {
            var urls = new List <string>
            {
                UnitRequest.Sensors("count=500", UrlFlag.Columns)
            };

            var filters = new[]
            {
                "filter_objid=3000",
                "filter_objid=3001",
                "filter_objid=3002"
            };

            urls.AddRange(filters.SelectMany(f => new[]
            {
                UnitRequest.Devices($"count=500&{f}", UrlFlag.Columns)
            }
                                             ));

            var client = GetClient(urls.ToArray());

            var sensors = client.Item1.QuerySensors().Where(s => client.Item1.QueryDevices().Any(d => d.Id == s.Id - 1000)).ToList();

            Assert.AreEqual(3, sensors.Count);

            client.Item2.AssertFinished();
        }
Пример #8
0
        private void StreamSerial(SensorParameters parameters, string[] address, bool requestCount = false, int?count = null)
        {
            var url = new List <string>();

            if (requestCount)
            {
                url.Add(UnitRequest.SensorCount);
            }

            url.AddRange(address.Select(a => UnitRequest.Sensors(a, UrlFlag.Columns)));

            Dictionary <Content, int> countOverride = null;

            if (count != null)
            {
                countOverride = new Dictionary <Content, int>();
                countOverride[Content.Sensors] = count.Value;
            }

            Execute(
                c => c.StreamSensors(parameters, true).ToList(),
                url.ToArray(),
                countOverride
                );
        }
Пример #9
0
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:     //Get a group
                Assert.AreEqual(UnitRequest.Groups("count=1", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem(objid: "2000")));

            case 2:     //Are there any other groups called "Windows Infrastructure"?
                Assert.AreEqual(UnitRequest.Groups("count=*&filter_name=Windows+Infrastructure", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem(objid: "2000"), new GroupItem(objid: "2050")));

            case 3:     //Get all devices under the group "Windows Infrastructure" that we're piping from
                Assert.AreEqual(UnitRequest.Devices("count=*&filter_parentid=2000", UrlFlag.Columns), address);
                return(new DeviceResponse(new DeviceItem(name: "Device1", objid: "3000"), new DeviceItem(name: "Device2", objid: "3001")));

            case 4:     //Get all sensors from the child devices
                Assert.AreEqual(UnitRequest.Sensors("count=*&filter_name=@sub(ping)&filter_parentid=3000&filter_parentid=3001", UrlFlag.Columns), address);
                return(new SensorResponse(new SensorItem(name: "Ping", objid: "4000"), new SensorItem(name: "Pong2", objid: "4001")));

            case 5:     //Get all child groups under "Windows Infrastructure
                Assert.AreEqual(UnitRequest.Groups("count=*&filter_parentid=2000", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem(name: "Child Group", objid: "2001", totalsens: "0")));

            default:
                throw UnknownRequest(address);
            }
        }
Пример #10
0
 public void Query_Where_Intermediate_NewSensor_Select_FromSource()
 {
     ExecuteClient(c => c.QuerySensors().Where(s => new Sensor
     {
         Message = s.Name
     }.Message == "test").Select(s => s.Name), new[] { UnitRequest.Sensors("columns=name&count=500&filter_name=test", null) }, s => s.ToList());
 }
Пример #11
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(address, UnitRequest.Objects("filter_objid=1001"));
                return(new ProbeResponse(new ProbeItem(objid: "1001", name: "Local Probe")));

            case 2:
                Assert.AreEqual(address, UnitRequest.Probes("filter_objid=1001&filter_parentid=0"));
                return(new ProbeResponse(new ProbeItem(objid: "1001", name: "Local Probe")));

            //Probe -> Devices
            case 3:
                Assert.AreEqual(address, UnitRequest.Devices("filter_parentid=1001"));
                return(new DeviceResponse(
                           new DeviceItem(objid: "3001", name: "dc-1", position: "10", positionRaw: "10"),
                           new DeviceItem(objid: "3002", name: "dc-2", position: "20", positionRaw: "20")
                           ));

            //Probe -> Groups
            case 4:
                Assert.AreEqual(address, UnitRequest.Groups("filter_parentid=1001"));
                return(new GroupResponse(new GroupItem(objid: "2001", name: "Servers", position: "30", positionRaw: "30")));

            //Probe -> Triggers
            case 5:
                Assert.AreEqual(address, UnitRequest.Triggers(1001));
                return(new NotificationTriggerResponse(
                           NotificationTriggerItem.StateTrigger(onNotificationAction: "300|Trigger1", parentId: "1001"),
                           NotificationTriggerItem.StateTrigger(onNotificationAction: "301|Trigger2", parentId: "1001"),
                           NotificationTriggerItem.StateTrigger(onNotificationAction: "302|Trigger3", parentId: "1001")
                           ));

            //Probe -> Devices -> Sensors
            case 6:
                Assert.AreEqual(address, UnitRequest.Sensors("filter_parentid=3001"));
                return(new SensorResponse(
                           new SensorItem(name: "Sensor2", objid: "4002", position: "20", positionRaw: "20"),
                           new SensorItem(name: "Sensor1", objid: "4001", position: "10", positionRaw: "10")
                           ));

            case 7:
                Assert.AreEqual(address, UnitRequest.Sensors("filter_parentid=3002"));
                return(new SensorResponse());

            //Probe -> Groups -> Devices
            case 8:
                Assert.AreEqual(address, UnitRequest.Devices("filter_parentid=2001"));
                return(new DeviceResponse());

            //Probe -> Groups -> Groups
            case 9:
                Assert.AreEqual(address, UnitRequest.Groups("filter_parentid=2001"));
                return(new GroupResponse());

            default:
                throw UnknownRequest(address);
            }
        }
Пример #12
0
        public void Tree_Lazy_Child_ResolvesOnlyOnce()
        {
            var client = BaseTest.Initialize_Client(new TreeRequestResponse(TreeRequestScenario.MultiLevelContainer));

            var validator = new EventValidator(client, new[]
            {
                //Get Object
                UnitRequest.Objects("filter_objid=1001"),

                //Get Probe
                UnitRequest.Probes("filter_objid=1001&filter_parentid=0"),

                //Probe -> Devices/Groups
                UnitRequest.Devices("filter_parentid=1001"),
                UnitRequest.Groups("filter_parentid=1001"),

                //Probe -> Device -> Sensors
                UnitRequest.Sensors("filter_parentid=3001")
            });

            validator.MoveNext(2);
            var tree = client.GetTreeLazy(1001);

            validator.MoveNext(2);
            var child      = tree.Children[0];
            var childAgain = tree.Children[0];

            validator.MoveNext();
            var grandChild      = child.Children[0];
            var grandChildAgain = child.Children[0];
        }
Пример #13
0
        private Tuple <PrtgClient, AddressValidatorResponse> GetUntilMatchedClient(int pageSize = 500)
        {
            var items = new List <BaseItem>();

            items.AddRange(GetPage("Yes", pageSize));
            items.AddRange(GetPage("YeNo", pageSize));
            items.AddRange(GetPage("YeNo", pageSize));
            items.AddRange(GetPage("Yes", pageSize));
            items.AddRange(GetPage("YeNo", pageSize));
            items.AddRange(GetPage("Yes", pageSize));

            var urls = new object[]
            {
                UnitRequest.Sensors($"count={pageSize}&filter_name=@sub(Ye)", UrlFlag.Columns),                      //Yes
                UnitRequest.Sensors($"count={pageSize}&filter_name=@sub(Ye)&start={pageSize * 1}", UrlFlag.Columns), //YeNo
                UnitRequest.Sensors($"count={pageSize}&filter_name=@sub(Ye)&start={pageSize * 2}", UrlFlag.Columns), //YeNo
                UnitRequest.Sensors($"count={pageSize}&filter_name=@sub(Ye)&start={pageSize * 3}", UrlFlag.Columns)  //Yes
            };

#pragma warning disable 618
            var response = new AddressValidatorResponse(urls)
            {
                ItemOverride = new Dictionary <Content, BaseItem[]>
                {
                    [Content.Sensors] = items.ToArray()
                }
            };
#pragma warning restore 618

            var client = Initialize_Client(response);

            return(Tuple.Create(client, response));
        }
Пример #14
0
 public void Query_Select_NewSensor_Where_FromNothing()
 {
     ExecuteClient(c => c.QuerySensors().Select(s => new Sensor
     {
         Id      = s.ParentId,
         Message = "hello"
     }.Message).Where(v => v == "test"), new[] { UnitRequest.Sensors("count=500", UrlFlag.Columns) }, s => s.ToList());
 }
Пример #15
0
 public void Query_Where_Operators_Fake_EndsWith_Take()
 {
     ExecuteClient(
         c => c.QuerySensors(s => s.Name.EndsWith("0")).Take(2),
         new[] { UnitRequest.Sensors("count=500&filter_name=@sub(0)", UrlFlag.Columns) },
         s => Assert.AreEqual(1, s.Count())
         );
 }
Пример #16
0
 public void Query_Select_NewSensor_Where_FromOperation()
 {
     ExecuteClient(c => c.QuerySensors().Select(s => new Sensor
     {
         Id      = s.ParentId,
         Message = s.Name + s.Type
     }.Message).Where(v => v == "test"), new[] { UnitRequest.Sensors("columns=name,type&count=500", null) }, s => s.ToList());
 }
Пример #17
0
 public void Query_Where_SplitRequests_OmitsId_WithSingleRequest()
 {
     ExecuteClient(
         c => c.QuerySensors(s => s.Name == "Ping").Select(s => s.Name),
         new[] { UnitRequest.Sensors("columns=name&count=500&filter_name=Ping", null) },
         s => s.ToList()
         );
 }
Пример #18
0
 public void Query_Select_NewSensor_WhereInternalProperty_FromSource()
 {
     ExecuteClient(c => c.QuerySensors().Select(s => new Sensor
     {
         Id      = s.ParentId,
         Message = s.Name
     }.Message).Where(v => v == "test"), new[] { UnitRequest.Sensors("columns=name&count=500&filter_name=test", null) }, s => s.ToList());
 }
Пример #19
0
 public void Query_Where_AsEnumerable_EnumerableMethod_AsQueryable()
 {
     ExecuteClient(
         c => c.QuerySensors().Where(s => s.Id == 4000).AsEnumerable().Where(s => s.Name == "Volume IO _Total0").AsQueryable(),
         new[] { UnitRequest.Sensors("count=500&filter_objid=4000", UrlFlag.Columns) },
         s => Assert.AreEqual(1, s.Count())
         );
 }
        protected void ExecuteQuery(Func <IQueryable <Sensor>, IQueryable <Sensor> > func, string[] filters,
                                    Action <List <Sensor> > validator)
        {
            Func <string, string> getDelim = f => f != string.Empty ? "&" : "";

            var urls = filters.Select(f => UnitRequest.Sensors($"count=500{getDelim(f)}{f}", UrlFlag.Columns)).ToArray();

            Execute(func, urls, validator);
        }
        public void AddNotificationTrigger_TriggerChannel_StandardTriggerChannel_OnSensor()
        {
            var urls = new[]
            {
                UnitRequest.TriggerTypes(1001),              //Validate Supported Triggers
                UnitRequest.Sensors("filter_objid=1001")     //Validate TriggerChannel target compatibility
            };

            AssertEx.Throws <InvalidOperationException>(() => TestTriggerChannel(TriggerChannel.Total, urls, true), "Channel 'Total' is not a valid value");
        }
        public void AddNotificationTrigger_TriggerChannel_InvalidChannelId_OnContainer()
        {
            var urls = new[]
            {
                UnitRequest.TriggerTypes(1001),              //Validate Supported Triggers
                UnitRequest.Sensors("filter_objid=1001")     //Validate TriggerChannel target compatibility
            };

            AssertEx.Throws <InvalidOperationException>(() => TestTriggerChannel(new TriggerChannel(99), urls, false), "Channel ID '99' is not a valid channel");
        }
Пример #23
0
 public void Query_Skip_FromWhere()
 {
     ExecuteClient(
         c => c.QuerySensors().Where(s => s.Name.Contains("Volume")).Skip(1).ToList(),
         new[] {
         UnitRequest.Sensors("count=0&filter_name=@sub(Volume)", null),
         UnitRequest.Sensors("count=2&filter_name=@sub(Volume)&start=1", UrlFlag.Columns)
     },
         s => Assert.AreEqual(2, s.Count)
         );
 }
        public void AddNotificationTrigger_TriggerChannel_StandardTriggerChannel_OnContainer()
        {
            var urls = new[]
            {
                UnitRequest.TriggerTypes(1001),                                                                                                                                                                                   //Validate Supported Triggers
                UnitRequest.Sensors("filter_objid=1001"),                                                                                                                                                                         //Validate TriggerChannel target compatibility
                UnitRequest.EditSettings("id=1001&subid=new&onnotificationid_new=-1%7CNone&class=threshold&offnotificationid_new=-1%7CNone&channel_new=-1&condition_new=0&threshold_new=0&latency_new=60&objecttype=nodetrigger") //Add Trigger
            };

            TestTriggerChannel(TriggerChannel.Total, urls, false);
        }
        public void AddNotificationTrigger_TriggerChannel_ChannelId_OnSensor()
        {
            var urls = new[]
            {
                UnitRequest.TriggerTypes(1001),                                                                                                                                                                                  //Validate Supported Triggers
                UnitRequest.Sensors("filter_objid=1001"),                                                                                                                                                                        //Validate TriggerChannel target compatibility
                UnitRequest.ChannelProperties(1001, 3),
                UnitRequest.EditSettings("id=1001&subid=new&onnotificationid_new=-1%7CNone&class=threshold&offnotificationid_new=-1%7CNone&channel_new=3&condition_new=0&threshold_new=0&latency_new=60&objecttype=nodetrigger") //Add Trigger
            };

            TestTriggerChannel(new TriggerChannel(3), urls, true);
        }
Пример #26
0
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Sensors("count=2", UrlFlag.Columns), address);
                return(new SensorResponse(new SensorItem(), new SensorItem(), new SensorItem()));

            default:
                throw UnknownRequest(address);
            }
        }
Пример #27
0
 public void Query_Where_SplitRequests_IncludesId_WithMultipleRequests()
 {
     ExecuteClient(
         c => c.QuerySensors(s => s.Name == "Ping" || s.Device == "dc-1").Select(s => s.Name),
         new[]
     {
         UnitRequest.Sensors("columns=objid,name,device&count=500&filter_name=Ping", null),
         UnitRequest.Sensors("columns=objid,name,device&count=500&filter_device=dc-1", null)
     },
         s => s.ToList()
         );
 }
        protected void ExecuteSkip <TResult>(Func <IQueryable <Sensor>, TResult> func, string[] url, Action <TResult> validator, UrlFlag flags = UrlFlag.Columns | UrlFlag.Count, int count = 3)
        {
            var list = new List <string>();

            list.Add(UnitRequest.SensorCount);
            list.AddRange(url.Select(f => UnitRequest.Sensors(f, flags)));

            var client = GetClient(list.ToArray(), count);

            var result = func(client.Item1.QuerySensors());

            validator(result);

            client.Item2.AssertFinished();
        }
        public void AddNotificationTrigger_TriggerChannel_Channel_WithStandardTriggerChannelName_OnContainer()
        {
            var urls = new[]
            {
                UnitRequest.TriggerTypes(1001),              //Validate Supported Triggers
                UnitRequest.Sensors("filter_objid=1001")     //Validate TriggerChannel target compatibility
            };

            var channel = new Channel
            {
                Name = "Total"
            };

            AssertEx.Throws <InvalidOperationException>(() => TestTriggerChannel(channel, urls, false), "Channel 'Total' of type 'Channel' is not a valid channel");
        }
Пример #30
0
        public void Query_Skip_All_WithCount()
        {
            var parameters = new SensorParameters
            {
                Start = 3
            };

            ExecuteClient(
                c => c.StreamSensors(parameters, true),
                new[] {
                UnitRequest.SensorCount,
                UnitRequest.Sensors("count=0&start=3", UrlFlag.Columns)
            },
                s => s.ToList()
                );
        }