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"); } }
private static void ProcessInputBatchFile(PingdomConfiguration pingdomConfiguration, string optionsInputFilePath, List <Check> allchecks) { if (File.Exists(_clp.Options.InputFilePath)) { var logFile = File.ReadAllLines(optionsInputFilePath); var logList = new List <string>(logFile); foreach (var checkAndUrl in logList) { if (string.IsNullOrEmpty(checkAndUrl)) { continue; } var splitval = checkAndUrl.Split('|'); var checkname = splitval[0]; var hostUrl = splitval[1]; var tags = splitval[2]; CreateNewCheck(pingdomConfiguration, hostUrl, checkname, tags, allchecks); } return; } Logger.Error("Input file does not exist"); throw new ArgumentNullException($"InputFilePath", "Missing input file"); }
public static void Main(string[] args) { Logger.Info("Program startup"); ConfigureCommandLIne(args); var pingdomConfiguration = new PingdomConfiguration { BaseUrl = System.Configuration.ConfigurationManager.AppSettings["pingdom:BaseUrl"], AccountApiKey = System.Configuration.ConfigurationManager.AppSettings["pingdom:AppKey"], Accountemail = System.Configuration.ConfigurationManager.AppSettings["pingdom:UserName"], Accountpw = System.Configuration.ConfigurationManager.AppSettings["pingdom:Password"] }; // --a all checks --u "Hudson.com" --c "TestMe" --t "Azure,API" --o output.md //command line --h --a --o var allchecks = GetAllChecks(pingdomConfiguration); if (_clp.Options.GetAll) { Logger.Info("Write out list of all checks"); WriteOutListOfChecks(allchecks); } if (!string.IsNullOrEmpty(_clp.Options.HostName) && !string.IsNullOrEmpty(_clp.Options.CheckName)) { Logger.Info("Create new check"); CreateNewCheck(pingdomConfiguration, _clp.Options.HostName, _clp.Options.CheckName, string.Empty, allchecks); } if (!string.IsNullOrEmpty(_clp.Options.InputFilePath)) { Logger.Info("Create new check from inputfile"); ProcessInputBatchFile(pingdomConfiguration, _clp.Options.InputFilePath, allchecks); } if (_clp.Options.IsExport) { Logger.Info("Export existing checks"); WriteOutListOfCheckIdAndCheckName(allchecks); } if (!string.IsNullOrEmpty(_clp.Options.UptimePeriod)) { Logger.Info("Get Uptime Report"); WriteUptimeReport(pingdomConfiguration, allchecks, GetTimePeriodFromCommandLineArgs()); } Logger.Info("Program End"); //Console.ReadLine(); }
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); }
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}"); }
public PingdomProcesser(PingdomConfiguration config) { Config = config; }