Example #1
0
        public async Task <IActionResult> Prtg()
        {
            var overview = await _jobStatusService.GetOverview();

            var prtg = new PrtgResult {
                Prtg = new Prtg
                {
                    Result = overview.Where(o => o.LastRun != null).Select(o => new PrtgChannel
                    {
                        Channel         = o.Job.Name,
                        Value           = (int)((o.LastRun + o.Job.ExpectedInterval) - DateTime.UtcNow)?.TotalSeconds,
                        Unit            = "TimeSeconds",
                        Warning         = o.IsDue ? 1 : 0,
                        LimitMinWarning = 0,
                        LimitMinError   = -(int)(o.Job.ExpectedInterval.TotalSeconds * 0.1),
                        LimitMode       = 1
                    }).ToList()
                }
            };

            JsonSerializerSettings serializerSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                ContractResolver  = new DefaultContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                }
            };

            return(new JsonResult(prtg, serializerSettings));
        }
        public void can_create_LimitMaxError_property()
        {
            var sut = new PrtgOptionalChannelPropertiesBuilder()
                      .WithLimitMaxError(100.923m);

            var result = new PrtgResult(channel: "TestChannel", value: 1, optionalProperties: sut.Build());

            result.Serialize().ToString().Should().Contain("<LimitMaxError>100.923</LimitMaxError>");
        }
        public void can_create_LimitMinWarning_property()
        {
            var sut = new PrtgOptionalChannelPropertiesBuilder()
                      .WithLimitMinWarning(999999999999999999999999.9999m);

            var result = new PrtgResult(channel: "TestChannel", value: 1, optionalProperties: sut.Build());

            result.Serialize().ToString().Should().Contain("<LimitMinWarning>999999999999999999999999.9999</LimitMinWarning>");
        }
        public void result_can_include_some_optional_properties()
        {
            var result = new PrtgResult("a channel", 10,
                                        new PrtgOptionalChannelProperty("some-property", "some-value"),
                                        new PrtgOptionalChannelProperty("other-property", "other-value"));

            var serializedResult = result.Serialize();

            serializedResult
            .Should().HaveElement("some-property")
            .Which.Should().HaveValue("some-value");

            serializedResult
            .Should().HaveElement("other-property")
            .Which.Should().HaveValue("other-value");
        }
Example #5
0
        public void WriteOutputTest()
        {
            string test =
                @"<prtg>
  <result>
    <limitmode>0</limitmode>
    <showtable>1</showtable>
    <showchart>1</showchart>
    <warning>0</warning>
    <decimalmode>2</decimalmode>
    <float>1</float>
    <mode>Absolute</mode>
    <speedtime>Second</speedtime>
    <volumesize>One</volumesize>
    <speedsize>One</speedsize>
    <unit>Custom</unit>
    <value>2.0</value>
    <channel>channel2</channel>
  </result>
  <result>
    <limitmode>0</limitmode>
    <showtable>1</showtable>
    <showchart>1</showchart>
    <warning>0</warning>
    <decimalmode>2</decimalmode>
    <float>1</float>
    <mode>Absolute</mode>
    <speedtime>Second</speedtime>
    <volumesize>One</volumesize>
    <speedsize>One</speedsize>
    <unit>Custom</unit>
    <value>1.0</value>
    <channel>channel1</channel>
  </result>
  <text>Yo, working!</text>
</prtg>".Replace(" ", "").Replace("\r\n", "");

            var channel1 = new PrtgChannel();
            var channel2 = new PrtgChannel();

            channel1.Channel = "channel1";
            channel2.Channel = "channel2";
            channel1.Value   = "1.0";
            channel2.Value   = "2.0";
            var channels = new Collection <PrtgChannel> {
                channel1, channel2
            };

            var result = new PrtgResult {
                Text = "Yo, working!"
            };

            foreach (var c in channels)
            {
                result.Channels.Add(c);
            }

            using (var consoleOutput = new CatchConsoleOutput())
            {
                result.WriteOutput();
                var tmp = consoleOutput.GetOuput().Replace(" ", "").Replace("\r\n", "");
                Assert.AreEqual(test, tmp);
                //this is just needed for output
                Console.SetOut(consoleOutput.OriginalOutput);
                Console.WriteLine(tmp);
            }
        }