private IEnumerable <Message> Probe(TaskTimerElapsed arg) { if (!Enabled) { return(JanelObserver.Success()); } try { var failureMessage = "Alert !\n"; using (var client = new HttpClient()) { client.Timeout = TimeSpan.FromSeconds(TimeOutInSeconds); client.DefaultRequestHeaders.Add("x-probing", "janel"); using (var request = client.GetAsync(WebSite).Result) { switch (ProbeType) { case WebProbeType.HttpCode200: if (request.StatusCode != HttpStatusCode.OK) { Retries++; } else { Retries = 0; } break; case WebProbeType.ContentInPage: var content = request.Content.ReadAsStringAsync().Result; if (!content.Contains(PageContent)) { Retries++; } else { Retries = 0; } break; } } } if (Enabled && Retries >= RetriesBeforeFailure) { _alertManager.LogAlert(failureMessage, WebSite, Enum.GetName(typeof(WebProbeType), ProbeType), "", SeverityType.Moderate); } } catch (Exception e) { _alertManager.LogAlert($"Unable to probe {WebSite}. {e.Message}", WebSite, Enum.GetName(typeof(WebProbeType), ProbeType), "", SeverityType.Moderate); } return(JanelObserver.Success()); }
public ActionResult RegisterAlert(string description, string serviceName, string serviceInfo, string serviceIp, SeverityType severity = SeverityType.Unknown) { //http://localhost:55378/Api/RegisterAlert?description=Test%20Alert&serviceName=Serv1&serviceInfo=Magento&serviceIP=127.0.0.1 _alertManager.LogAlert(description, serviceName, serviceInfo, serviceIp, severity); return(Ok()); }
private IEnumerable <Message> Probe(TaskTimerElapsed arg) { if (!Enabled) { return(JanelObserver.Success()); } try { using (var authentication = new WindowsLogin(UserName, Domain, Password)) { var failedServices = new List <string>(); WindowsIdentity.RunImpersonated(authentication.Identity.AccessToken, () => { foreach (var service in Services) { var windowsService = new ServiceController(service, MachineName); if (windowsService.Status != ServiceControllerStatus.Running) { failedServices.Add(service); } } }); if (Enabled && failedServices.Any() && Retries++ >= RetriesBeforeFailure) { _alertManager.LogAlert($"Alert !\n\nServices not running : \n{string.Join("\n- ", failedServices)}", "Windows Services", MachineName, "", SeverityType.Critical); } else if (!Enabled || !failedServices.Any()) { Retries = 0; } } } catch (Exception exc) { _alertManager.LogAlert($"Unable to probe services of {MachineName}. {exc.Message}", MachineName, "", "", SeverityType.Moderate); } return(JanelObserver.Success()); }
private IEnumerable <Message> Probe(TaskTimerElapsed arg) { _alertManager.LogAlert("Timeout from Monitis", "www.robotshop.com", "EC2BLABLA", "127.0.0.1", SeverityType.Critical); return(JanelObserver.Success()); }
public async Task <List <ChannelMessage> > SendMessages(string platform, List <BroadcastMessage> messages) { var channelMessages = new List <ChannelMessage>(); foreach (var message in messages) { var chat = await _discordService.GetMessageChannel(message.GuildId, message.ChannelId); if (chat != null) { try { ChannelMessage channelMessage = new ChannelMessage(); channelMessage.ChannelId = message.ChannelId; channelMessage.GuildId = message.GuildId; channelMessage.DeleteOffline = message.DeleteOffline; if (message.Embed != null) { RequestOptions options = new RequestOptions(); options.RetryMode = RetryMode.AlwaysRetry; var msg = await chat.SendMessageAsync(message.Message, false, message.Embed, options); if (msg != null || msg.Id != 0) { channelMessage.MessageId = msg.Id; } } else { var msg = await chat.SendMessageAsync(message.Message); if (msg != null || msg.Id != 0) { channelMessage.MessageId = msg.Id; } } channelMessages.Add(channelMessage); if (platform.Equals(Constants.Mixer)) { await _statisticsManager.AddToBeamAlertCount(); await _alertManager.LogAlert(Constants.Mixer, message.GuildId); } else if (platform.Equals(Constants.Smashcast)) { await _statisticsManager.AddToHitboxAlertCount(); await _alertManager.LogAlert(Constants.Smashcast, message.GuildId); } else if (platform.Equals(Constants.Twitch)) { await _statisticsManager.AddToTwitchAlertCount(); await _alertManager.LogAlert(Constants.Twitch, message.GuildId); } else if (platform.Equals(Constants.YouTubeGaming)) { await _statisticsManager.AddToYouTubeAlertCount(); await _alertManager.LogAlert(Constants.YouTubeGaming, message.GuildId); } else if (platform.Equals(Constants.Picarto)) { await _statisticsManager.AddToPicartoAlertCount(); await _alertManager.LogAlert(Constants.Picarto, message.GuildId); } else if (platform.Equals(Constants.VidMe)) { await _statisticsManager.AddToVidMeAlertCount(); await _alertManager.LogAlert(Constants.VidMe, message.GuildId); } else if (message.Platform.Equals(Constants.YouTube)) { await _statisticsManager.AddToYouTubeAlertCount(); await _alertManager.LogAlert(Constants.YouTube, message.GuildId); } else if (message.Platform.Equals(Constants.Mobcrush)) { await _statisticsManager.AddToMobcrushAlertCount(); await _alertManager.LogAlert(Constants.Mobcrush, message.GuildId); } } catch (Exception ex) { Logging.LogError("Send Message Error: " + ex.Message + " in server " + message.GuildId); } } } return(channelMessages); }