public static NotificationEventBuilder From(INotificationEventCore coreEvent)
 {
     return(new NotificationEventBuilder
     {
         _notification = new NotificationEvent
         {
             AgentId = coreEvent.AgentId,
             CheckId = coreEvent.CheckId,
             CriticalFailure = coreEvent.CriticalFailure,
             CriticalFailureDetails = coreEvent.CriticalFailureDetails,
             DayBucket = coreEvent.DayBucket,
             EventType = coreEvent.EventType,
             GeneratedOnUtc = coreEvent.GeneratedOnUtc,
             HourBucket = coreEvent.HourBucket,
             Id = coreEvent.Id,
             Latitude = coreEvent.Latitude,
             Longitude = coreEvent.Longitude,
             Message = coreEvent.Message,
             MinuteBucket = coreEvent.MinuteBucket,
             Properties = coreEvent.Properties,
             ReceivedOnUtc = coreEvent.ReceivedOnUtc,
             Result = coreEvent.Result,
             ResultCount = coreEvent.ResultCount,
             DisplayUnit = coreEvent.DisplayUnit,
             SiteId = coreEvent.SiteId,
             Tags = coreEvent.Tags,
             Version = coreEvent.Version,
             Data = Serialiser.ToJson(coreEvent)
         }
     });
 }
 public static NotificationEventBuilder From(INotificationEventCore coreEvent)
 {
     return new NotificationEventBuilder
                {
                    _notification = new NotificationEvent
                                        {
                                            AgentId = coreEvent.AgentId,
                                            CheckId = coreEvent.CheckId,
                                            CriticalFailure = coreEvent.CriticalFailure,
                                            CriticalFailureDetails = coreEvent.CriticalFailureDetails,
                                            DayBucket = coreEvent.DayBucket,
                                            EventType = coreEvent.EventType,
                                            GeneratedOnUtc = coreEvent.GeneratedOnUtc,
                                            HourBucket = coreEvent.HourBucket,
                                            Id = coreEvent.Id,
                                            Latitude = coreEvent.Latitude,
                                            Longitude = coreEvent.Longitude,
                                            Message = coreEvent.Message,
                                            MinuteBucket = coreEvent.MinuteBucket,
                                            Properties = coreEvent.Properties,
                                            ReceivedOnUtc = coreEvent.ReceivedOnUtc,
                                            Result = coreEvent.Result,
                                            ResultCount = coreEvent.ResultCount,
                                            DisplayUnit = coreEvent.DisplayUnit,
                                            SiteId = coreEvent.SiteId,
                                            Tags = coreEvent.Tags,
                                            Version = coreEvent.Version,
                                            Data = Serialiser.ToJson(coreEvent)
                                        }
                };
 }
 public static NotificationRequestBuilder For(string notificationMode, INotificationEventCore message)
 {
     return new NotificationRequestBuilder
     {
         _request = new NotificationRequest
         {
             Notification = message,
             Mode = notificationMode
         }
     };
 }
 public static NotificationRequestBuilder For(string notificationMode, INotificationEventCore message)
 {
     return(new NotificationRequestBuilder
     {
         _request = new NotificationRequest
         {
             Notification = message,
             Mode = notificationMode
         }
     });
 }
Ejemplo n.º 5
0
        /// <summary>
        /// When a breach of the threshold is detected we want to send a list 
        /// the top 5 cpu hogging processes in the alert
        /// </summary>
        /// <param name="message"></param>
        protected override void AdjustMessageForBreach(INotificationEventCore message)
        {
            base.AdjustMessageForBreach(message);

            var counters = new List<ProcessCounterSample>();
            var ps = Process.GetProcesses();

            ps.ForEach(process =>
                           {
                               try
                               {
                                   var counter = (string.IsNullOrEmpty(_config.MachineName)
                                                      ? new PerformanceCounter("Process", "% Processor Time", process.ProcessName)
                                                      : new PerformanceCounter("Process", "% Processor Time", process.ProcessName, _config.MachineName));
                                   counter.ReadOnly = true;

                                   counters.Add(new ProcessCounterSample
                                                    {
                                                        Counter = counter,
                                                        Process = process,
                                                        Sample1 = counter.NextSample()
                                                    });
                               }
                               catch
                               {
                                   Logger.Debug("*** Process '{0}' has no Performance Counter ***", process.ProcessName);
                               }
                           });

            Logger.Info("Getting CPU% for {0} processes...", counters.Count);
            Thread.Sleep(1000);

            counters.ForEach(pcs =>
                                 {
                                     var sample2 = pcs.Counter.NextSample();
                                     pcs.Value = Math.Round(CounterSampleCalculator.ComputeCounterValue(pcs.Sample1, sample2));
                                 });

            counters.Where(pcs => pcs.Value > 0)
                .OrderByDescending(pcs => pcs.Value)
                .Take(5)
                .ForEach(pcs =>
                             {
                                 var name = string.Format("{0}[{1}]", pcs.Process.ProcessName, pcs.Process.Id);
                                 // TODO: add property to core notification properties?
                                 //message.AddProperty(name, Convert.ToString(pcs.Value));
                             });
        }
Ejemplo n.º 6
0
 /// <summary>
 /// By default a breached threshold is a failure, override this method to
 /// provide custom logic to set message properties in the event of a breach
 /// </summary>
 /// <param name="message"></param>
 protected virtual void AdjustMessageForBreach(INotificationEventCore message)
 {
     message.Result = false;
 }
 public static NotificationRequestBuilder AlwaysPublish(INotificationEventCore message)
 {
     return For(String.Empty, message);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// By default a breached threshold is a failure, override this method to
 /// provide custom logic to set message properties in the event of a breach
 /// </summary>
 /// <param name="message"></param>
 protected virtual void AdjustMessageForBreach(INotificationEventCore message)
 {
     message.Result = NagiosResult.Critical;
 }
Ejemplo n.º 9
0
 protected virtual string DefaultKeyGenerator(INotificationEventCore notification)
 {
     return(notification.CheckId.ToLower());
 }
 public static NotificationRequestBuilder AlwaysPublish(INotificationEventCore message)
 {
     return(For(String.Empty, message));
 }
 protected virtual string DefaultKeyGenerator(INotificationEventCore notification)
 {
     return notification.CheckId.ToLower();
 }