public void testSummary()
        {
            // set up by loading in xml from file
            XElement dataFromFile =
                XElement.Load(@"/Users/stefanevans/Development/reporter/services/prtg/sam-app/test/PRTGService.Test/TestService/PRTGTestInputXmlFile.xml");
            var itemsList = from item in dataFromFile.Elements() select item;

            Console.WriteLine("testSummary");
            StatsSummaryHolder stats = new StatsSummaryHolder();

            // test
            var summaryCalculator = new SummaryCalculator();

            stats = summaryCalculator.GetDataXml(stats, itemsList);

            var cpu = summaryCalculator.GetAverageFromSummary(stats, "CPU Utilization");

            Assert.Equal("0.56", cpu);

            var status = summaryCalculator.GetAverageFromSummary(stats, "Status (Ok)");

            Assert.Equal("100", status);

            var balance = summaryCalculator.GetAverageFromSummary(stats, "CPU Credit Balance");

            Assert.Equal("576", balance);

            var networkIn = summaryCalculator.GetAverageFromSummary(stats, "Network In");

            Assert.Equal("3.44", networkIn);
        }
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
        {
            try {
                //var queryStrings = apigProxyEvent.QueryStringParameters["sdate"];
                Console.WriteLine("apigProxyEvent count " + apigProxyEvent.QueryStringParameters.Count());

                var id       = apigProxyEvent.QueryStringParameters["id"];
                var sdate    = apigProxyEvent.QueryStringParameters["sdate"];
                var edate    = apigProxyEvent.QueryStringParameters["edate"];
                var username = apigProxyEvent.QueryStringParameters["username"];
                var passhash = apigProxyEvent.QueryStringParameters["passhash"];

                // load xml into XElement
                XElement dataFromPRTG =
                    XElement.Load(GetPRTGSummary(
                                      id,
                                      sdate,
                                      edate,
                                      username,
                                      passhash
                                      ).Result);
                var itemsList = from item in dataFromPRTG.Elements() select item;

                // get stats from xml
                StatsSummaryHolder stats = new StatsSummaryHolder();
                var summaryCalculator    = new SummaryCalculator();
                stats = summaryCalculator.GetDataXml(stats, itemsList);

                var cpu = summaryCalculator.GetAverageFromSummary(stats, "CPU Utilization");

                Dictionary <string, string> body = new Dictionary <string, string>
                {
                    { "status", "success" },
                    { "cpu", cpu },
                };

                return(new APIGatewayProxyResponse
                {
                    Body = JsonConvert.SerializeObject(body),
                    StatusCode = 200,
                    Headers = new Dictionary <string, string> {
                        { "Content-Type", "application/json" }
                    }
                });
            } catch (Exception e) {
                // catch error
                Dictionary <string, string> body = new Dictionary <string, string>
                {
                    { "status", "error" },
                    { "message", e.Message },
                    { "stacktrace", e.StackTrace },
                };

                return(new APIGatewayProxyResponse
                {
                    Body = JsonConvert.SerializeObject(body),
                    StatusCode = 500,
                    Headers = new Dictionary <string, string> {
                        { "Content-Type", "application/json" }
                    }
                });
            }
        }