Пример #1
0
        private async Task AddSensorAsync(RequestVersion version)
        {
            var builder = new StringBuilder();

            builder.Append("https://prtg.example.com/addsensor5.htm?name_=XML+Custom+EXE%2FScript+Sensor&priority_=3&inherittriggers_=1&intervalgroup=1&interval_=60%7C60+seconds");
            builder.Append("&errorintervalsdown_=1&tags_=xmlexesensor&exefile_=test.ps1%7Ctest.ps1%7C%7C&exeparams_=&environment_=0");
            builder.Append("&usewindowsauthentication_=0&mutexname_=&timeout_=60&writeresult_=0&sensortype=exexml&id=1001&");

            var auth = version == RequestVersion.v18_1 ? "tmpid=2" : "username=username&passhash=12345678";

            builder.Append(auth);

            var urls = new List <string>
            {
                ////We don't request status since we already injected our version
                UnitRequest.BeginAddSensorQuery(1001, "exexml"),
                builder.ToString()
            };

            if (version == RequestVersion.v18_1)
            {
                urls.Add(UnitRequest.AddSensorProgress(1001, 2, true));
            }

            var parameters = new ExeXmlSensorParameters("test.ps1");

            await ExecuteAsync(
                async c => await c.AddSensorAsync(1001, parameters, false),
                urls.ToArray(),
                version : version
                );
        }
Пример #2
0
        private Tuple <PrtgClient, AddressValidatorResponse> GetAddExcessiveSensorClient(List <WmiServiceTarget> services, RequestVersion version)
        {
            var formats = services.Select(s => "service__check=" + WebUtility.UrlEncode(((ISerializable)s).GetSerializedFormat())).ToList();

            var urls = new List <string>();

            //We don't request status since we already injected our version
            urls.Add(UnitRequest.BeginAddSensorQuery(1001, "wmiservice"));

            for (int i = 0; i < formats.Count; i += 30)
            {
                var thisRequest = formats.Skip(i).Take(30);

                var str = string.Join("&", thisRequest);

                var auth = version == RequestVersion.v18_1 ? "tmpid=2" : "username=username&passhash=12345678";

                var url = $"https://prtg.example.com/addsensor5.htm?name_=Service&priority_=3&inherittriggers_=1&intervalgroup=1&interval_=60%7C60+seconds&errorintervalsdown_=1&tags_=wmiservicesensor+servicesensor&restart_=0&monitorchange_=1&monitorextended_=0&service_=1&sensortype=wmiservice&{str}&id=1001&{auth}";

                urls.Add(url);

                if (i == 0 && version == RequestVersion.v18_1)
                {
                    urls.Add(UnitRequest.AddSensorProgress(1001, 2, true));
                }
            }

#pragma warning disable 618
            var response = new AddressValidatorResponse(urls.ToArray(), true);

            var client = Initialize_Client(response, version);
#pragma warning restore 618

            return(Tuple.Create(client, response));
        }
        public async Task DynamicSensorParameters_SensorQueryParameters_Throws_WhenParametersAreMissingAsync()
        {
            var client = Initialize_Client(new SensorQueryTargetParametersValidatorResponse(new[]
            {
                UnitRequest.SensorTypes(1001),
                UnitRequest.BeginAddSensorQuery(1001, "ptfadsreplfailurexml")
            }));

            await AssertEx.ThrowsAsync <InvalidOperationException>(
                async() => await client.GetDynamicSensorParametersAsync(1001, "ptfadsreplfailurexml", queryParameters: new SensorQueryTargetParameters()),
                "Failed to process request for sensor type 'oracletablespace': sensor query target parameters did not include mandatory parameters 'database_',"
                );
        }
Пример #4
0
        public void AddSensor_SensorQueryTarget_IgnoresTarget()
        {
            var client = Initialize_Client(new SensorQueryTargetValidatorResponse(new[]
            {
                UnitRequest.Status(),
                UnitRequest.BeginAddSensorQuery(1001, "snmplibrary"),
                UnitRequest.AddSensor("name_=test&priority_=3&inherittriggers_=1&intervalgroup=1&interval_=60%7C60+seconds&errorintervalsdown_=1&sensortype=snmplibrary&id=1001")
            }));

            var parameters = new RawSensorParameters("test", "snmplibrary");

            client.AddSensor(1001, parameters, false);
        }
        public async Task DynamicSensorParameters_SensorQueryTarget_ParsesTargetAsync()
        {
            var client = Initialize_Client(new SensorQueryTargetValidatorResponse(new[]
            {
                UnitRequest.SensorTypes(1001), //Get initial target

                UnitRequest.SensorTypes(1001), //Verify specified target
                UnitRequest.BeginAddSensorQuery(1001, "snmplibrary_nolist", "APC+UPS.oidlib"),
                UnitRequest.AddSensorProgress(1001, 2),
                UnitRequest.EndAddSensorQuery(1001, 2)
            }));

            var target = (await client.GetSensorTypesAsync(1001)).First(t => t.Id == "snmplibrary").QueryTargets.First();

            await client.GetDynamicSensorParametersAsync(1001, "snmplibrary", queryParameters : target);
        }
        public async Task DynamicSensorParameters_SensorQueryParameters_ParsesParametersAsync()
        {
            var client = Initialize_Client(new SensorQueryTargetParametersValidatorResponse(new[]
            {
                UnitRequest.SensorTypes(1001),
                UnitRequest.BeginAddSensorQuery(1001, "ptfadsreplfailurexml"),
                UnitRequest.ContinueAddSensorQuery(2055, 7, "database_=XE&sid_type_=0&prefix_=0"),
                UnitRequest.AddSensorProgress(1001, 7),
                UnitRequest.EndAddSensorQuery(1001, 7)
            }));

            await client.GetDynamicSensorParametersAsync(1001, "ptfadsreplfailurexml", queryParameters : new SensorQueryTargetParameters
            {
                ["database"] = "XE",
                ["sid_type"] = 0,
                ["prefix"]   = 0
            });
        }
Пример #7
0
        public void AddSensor_SensorQueryParameters_Throws_WhenSynthesizedParametersAreMissing()
        {
            var client = Initialize_Client(new SensorQueryTargetParametersValidatorResponse(new[]
            {
                UnitRequest.Status(),
                UnitRequest.BeginAddSensorQuery(1001, "oracletablespace"),
            }));

            var parameters = new RawSensorParameters("test", "oracletablespace")
            {
                ["sid_type"] = 0,
                ["prefix"]   = 0
            };

            AssertEx.Throws <InvalidOperationException>(
                () => client.AddSensor(1001, parameters, false),
                "Failed to process request for sensor type 'oracletablespace': sensor query target parameters did not include mandatory parameter 'database_'."
                );
        }
Пример #8
0
        public void AddSensor_SensorQueryParameters_SynthesizesParameters()
        {
            var client = Initialize_Client(new SensorQueryTargetParametersValidatorResponse(new[]
            {
                UnitRequest.Status(),
                UnitRequest.BeginAddSensorQuery(1001, "oracletablespace"),
                UnitRequest.ContinueAddSensorQuery(2055, 7, "database_=XE&sid_type_=0&prefix_=0"), //Response hardcodes 2055, however normally this will in fact match
                UnitRequest.AddSensor("name_=test&priority_=3&inherittriggers_=1&intervalgroup=1&interval_=60%7C60+seconds&errorintervalsdown_=1&database=XE&sid_type=0&prefix=0&sensortype=oracletablespace&id=1001")
            }));

            var parameters = new RawSensorParameters("test", "oracletablespace")
            {
                ["database"] = "XE",
                ["sid_type"] = 0,
                ["prefix"]   = 0
            };

            client.AddSensor(1001, parameters, false);
        }
        public void DynamicSensorParameters_SensorQueryParameters_ParsesParameters_ContainingNewLines()
        {
            //The issue is that even though we encode our newlines, the response URI has then un-encoded. This causes our attempts to extract a tmpid to fail without specifying RegexOptions.Singleline
            var client = Initialize_Client(new SensorQueryTargetParametersValidatorResponse(new[]
            {
                UnitRequest.SensorTypes(1001),
                UnitRequest.BeginAddSensorQuery(1001, "ptfadsreplfailurexml"),
                UnitRequest.ContinueAddSensorQuery(2055, 7, "database_=First%0ASecond&sid_type_=0&prefix_=0"),
                UnitRequest.AddSensorProgress(1001, 7),
                UnitRequest.EndAddSensorQuery(1001, 7)
            })
            {
                DecodeNewlines = true
            });

            client.GetDynamicSensorParameters(1001, "ptfadsreplfailurexml", queryParameters: new SensorQueryTargetParameters
            {
                ["database"] = $"First\nSecond",
                ["sid_type"] = 0,
                ["prefix"]   = 0
            });
        }