Esempio n. 1
0
        private static void CreateNewCheck(PingdomConfiguration pingdomConfiguration, string hostName, string checkName, string tags, IEnumerable <Check> allChecks)
        {
            // var allchecks = GetAllChecks(pingdomConfiguration);
            var alreadyExists = allChecks.Any(x => x.hostname == hostName);

            if (!alreadyExists)
            {
                Logger.Info("Adding Check to Pingdom");
                var check = new CheckCreateDto
                {
                    host        = hostName,
                    name        = checkName,
                    type        = "http",
                    encryption  = true,
                    port        = 443,
                    sendtoemail = true,
                    resolution  = 1,
                    tags        = tags
                };
                var pp         = new PingdomProcesser(pingdomConfiguration);
                var jsonOutput = pp.CreateNewCheck(check);

                Logger.Info($"{Environment.NewLine}{jsonOutput}");
            }
            else
            {
                Logger.Info("Check already exists");
            }
        }
Esempio n. 2
0
        private static List <Check> GetAllChecks(PingdomConfiguration pingdomConfiguration)
        {
            var pp = new PingdomProcesser(pingdomConfiguration);

            var jsonOutput = pp.GetChecks();

            //var rootElementObj = JsonConvert.DeserializeObject<Rootobject>(jsonOutput);
            //foreach (var check in rootElementObj.checks)
            //{
            //    Logger.Info($"Host: {check.hostname} Status: {check.status} ");
            //}

            return(jsonOutput);
        }
Esempio n. 3
0
        private static void WriteUptimeReport(PingdomConfiguration pingdomConfiguration, IEnumerable <Check> allchecks, int timePeriod)
        {
            if (allchecks == null)
            {
                throw new ArgumentNullException(nameof(allchecks));
            }

            var sb       = new StringBuilder();
            var pp       = new PingdomProcesser(pingdomConfiguration);
            var firstDay = new DateTime(timePeriod, 1, 1);
            var lastDay  = new DateTime(timePeriod, 12, 31);
            IEnumerable <Check> checks = allchecks.ToList();
            var groupsNoReportOn       = new List <string> {
                "SB3 ", "TEST"
            };

            foreach (var check in checks.OrderBy(x => x.name))
            {
                if (check.status == "paused")
                {
                    continue;
                }

                Logger.Info($"Processing:{check.name}");

                var res = pp.GetSummaryUptime(check, firstDay, lastDay);
                if (res == null)
                {
                    continue;
                }

                check.UpTime = res.status.CalculateUptime();
                sb.AppendLine($"|{check.id}|{check.name}|{res.status.totaldown}|{res.status.totalup}|{check.UpTime:P2}|");
            }

            sb.AppendLine(GroupCheckSummaries(checks.OrderBy(x => x.name), groupsNoReportOn));

            WriteOutputFile(string.Join(Environment.NewLine, sb.ToString()), $"PingdomUpTime-{timePeriod}");
        }