public void TestGetKeyword() { var html = @" <!doctype html> <html lang='en'> <head> <!-- Required meta tags --> <meta charset='utf-8'> <meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'> <link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css'> <title>Hello World</title> </head> <body> <div class='container'> <p> Hello World </p> </div> <script src='https://code.jquery.com/jquery-3.3.1.slim.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js'></script> <script src='https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js'></script> </body> </html>"; var keyWord = "Hello World"; MonitoringHelper.EnsureKeyWordExists(html, keyWord); }
public static LongRunningOperationResponse TestFailover( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer protectionContainer, ReplicationProtectedItem protectedItem) { TestFailoverInput tfoInput = new TestFailoverInput() { Properties = new TestFailoverInputProperties() { ProviderSpecificDetails = new ProviderSpecificFailoverInput() } }; if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure") { HyperVReplicaAzureFailoverProviderInput hvrAFOInput = new HyperVReplicaAzureFailoverProviderInput() { VaultLocation = "West US", }; string networkId = (protectedItem.Properties.ProviderSpecificDetails as HyperVReplicaAzureReplicationDetails) .SelectedRecoveryAzureNetworkId; TestFailoverInputProperties tfoProp = new TestFailoverInputProperties() { ProviderSpecificDetails = hvrAFOInput, NetworkType = string.IsNullOrEmpty(networkId) ? null : "VmNetworkAsInput", NetworkId = networkId }; tfoInput.Properties = tfoProp; } DateTime startTFO = DateTime.UtcNow; var tfoOp = client.ReplicationProtectedItem.TestFailover( primaryFabric.Name, protectionContainer.Name, protectedItem.Name, tfoInput, GetRequestHeaders()); var jobs = MonitoringHelper.GetJobId(MonitoringHelper.TestFailoverJobName, startTFO, client, GetRequestHeaders()); ResumeJobParamsProperties resProp = new ResumeJobParamsProperties() { Comments = "Res TFO" }; ResumeJobParams resParam = new ResumeJobParams() { Properties = resProp }; return(client.Jobs.Resume(jobs.Name, resParam, GetRequestHeaders())); }
private void PingMonitor(IEnumerable <Monitor> pingMonitors) { foreach (var monitor in pingMonitors) { monitor.LastMonitorDate = DateTime.UtcNow; var monitorLog = new MonitorLog { MonitorId = monitor.Id }; try { var successfullPing = MonitoringHelper.PingHost(monitor.Url); if (successfullPing) { monitor.LastMonitorSuccess = true; monitorLog.Successful = true; monitor.Triggered = false; } else { throw new PingException("Unable to ping "); } } catch (PingException ex) { monitorLog.Successful = false; monitorLog.ExceptionMessage = ex.Message; monitor.LastMonitorSuccess = false; _failedMonitors.Add(new Monitor(monitor)); monitor.Triggered = true; } catch (Exception ex) { monitorLog.Successful = false; monitorLog.ExceptionMessage = ex.Message; monitor.LastMonitorSuccess = false; _failedMonitors.Add(new Monitor(monitor)); monitor.Triggered = true; } finally { _processedMonitors.Add(monitor); _monitorLogs.Add(monitorLog); } } }
private static void RunSample(int listSize, int sampleSize) { List <int> exampleList = new List <int>(listSize); for (int i = 0; i < listSize; i++) { exampleList.Add(RandomInputGenerator.GenerateRandomInt()); } exampleList = exampleList.OrderBy(r => r).ToList(); ISearchStrategy strategy = new ForeachSearchStrategy(); TimeSpan span = MonitoringHelper.RunInMonitoredScope(delegate() { exampleList.FindInList(RandomInputGenerator.GenerateRandomInt(), strategy); }, sampleSize); Console.WriteLine($"Foreach {listSize} {sampleSize} {span.TotalMilliseconds}"); strategy = new FindSearchStrategy(); span = MonitoringHelper.RunInMonitoredScope(delegate() { exampleList.FindInList(RandomInputGenerator.GenerateRandomInt(), strategy); }, sampleSize); Console.WriteLine($"Find {listSize} {sampleSize} {span.TotalMilliseconds}"); strategy = new InListOrderedSearchStrategy(); span = MonitoringHelper.RunInMonitoredScope(delegate() { exampleList.FindInList(RandomInputGenerator.GenerateRandomInt(), strategy); }, sampleSize); Console.WriteLine($"Ordered D&C Copy {listSize} {sampleSize} {span.TotalMilliseconds}"); strategy = new BinaryRangeLimitStrategy(); span = MonitoringHelper.RunInMonitoredScope(delegate() { exampleList.FindInList(RandomInputGenerator.GenerateRandomInt(), strategy); }, sampleSize); Console.WriteLine($"Ordered D&C move index {listSize} {sampleSize} {span.TotalMilliseconds}"); span = MonitoringHelper.RunInMonitoredScope(delegate() { exampleList.FindInList(RandomInputGenerator.GenerateRandomInt()); }, sampleSize); Console.WriteLine($"Binary {listSize} {sampleSize} {span.TotalMilliseconds}"); strategy = new InListBinaryOwnSearchStrategy(); span = MonitoringHelper.RunInMonitoredScope(delegate() { exampleList.FindInList(RandomInputGenerator.GenerateRandomInt(), strategy); }, sampleSize); Console.WriteLine($"BinaryOwn {listSize} {sampleSize} {span.TotalMilliseconds}"); }
private async Task KeyWordMonitor(IEnumerable <Monitor> keyWordMonitors) { foreach (var monitor in keyWordMonitors) { monitor.LastMonitorDate = DateTime.UtcNow; using (var httpClient = new HttpClient()) { var monitorLog = new MonitorLog { MonitorId = monitor.Id }; var responseCode = 0; try { httpClient.BaseAddress = new Uri(monitor.Url); httpClient.DefaultRequestHeaders.Accept.Clear(); var response = await httpClient.GetAsync(""); responseCode = (int)response.StatusCode; response.EnsureSuccessStatusCode(); using (var content = response.Content) { var html = await content.ReadAsStringAsync(); MonitoringHelper.EnsureKeyWordExists(html, monitor.KeyWord); monitor.LastMonitorSuccess = true; monitorLog.ResponseCode = responseCode; monitorLog.Successful = true; monitor.Triggered = false; } } catch (KeyWordNotFoundException) { monitorLog.ResponseCode = responseCode; monitorLog.Successful = false; monitorLog.ExceptionMessage = "Unable to find keyword"; monitor.LastMonitorSuccess = false; _failedMonitors.Add(new Monitor(monitor)); monitor.Triggered = true; } catch (Exception ex) { monitorLog.ResponseCode = responseCode; monitorLog.Successful = false; monitorLog.ExceptionMessage = ex.Message; monitor.LastMonitorSuccess = false; _failedMonitors.Add(new Monitor(monitor)); monitor.Triggered = true; } finally { _processedMonitors.Add(monitor); _monitorLogs.Add(monitorLog); } } } }
protected override bool IsKnownException(Exception exception) { return(base.IsKnownException(exception) || DataAccessHelper.IsDataAccessKnownException(exception) || MonitoringHelper.IsKnownExceptionForMonitoring(exception)); }
public void TestPing() { var urlToTest = "www.google.com"; MonitoringHelper.PingHost(urlToTest); }
public void TestFailingSitePing() { var fakeUrl = "joshuakaluba.kaluba"; MonitoringHelper.PingHost(fakeUrl); }
protected override bool IsKnownException(Exception e) { return(base.IsKnownException(e) || MonitoringHelper.IsKnownExceptionForMonitoring(e)); }