Esempio n. 1
0
        private bool IsNotified(MonitorItem item, string Key, string runtimeValue, string message, out NotifiedMonitorItem notified)
        {
            notified = null;
            var key = item.ToString() + ", " + Key + ", " + runtimeValue;

            if (!_notifiedAlerts.ContainsKey(key))
            {
                notified = new NotifiedMonitorItem {
                    Server = item.Server, CurrentValue = message, CreatedDate = DateTime.Now
                };
                _notifiedAlerts.Add(key, notified);
                if (Settings.Instance.LogHistory)
                {
                    Settings.Instance.NotifiedAlerts.Add(notified);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 2
0
 private void ShowAlert(MonitorItem item, string key, string currentValue)
 {
     var message = Settings.Instance.AlertTemplate;
     if (string.IsNullOrEmpty(message))
         message = Settings.DefaultTemplate;
     var type = string.Empty;
     var action = string.Empty;
     switch (item.AlertType)
     {
         case AlertTypes.Sql:
             action = currentValue;
             switch (item.CondictionType)
             {
                 case 0:
                     type = "SQL executes: ";
                     break;
                 case 1:
                     type = "SQL lasts: ";
                     break;
                 case 2:
                     type = "SQL blocked: ";
                     break;
                 case 3:
                     type = "Empty table: ";
                     break;
                 default:
                     break;
             }
             break;
         case AlertTypes.Server:
             break;
         //case AlertTypes.CPU:
         //    message = string.Format("CPU usage is now {0}, higher than {1}", CurrentValue, Item.CondictionValue);
         //    break;
         //case AlertTypes.Memory:
         //    message = string.Format("Available memory is now {0}, lower than {1}", CurrentValue, Item.CondictionValue);
         //    break;
         //case AlertTypes.Diskspace:
         //    break;
         default:
             break;
     }
     if (!string.IsNullOrEmpty(message))
     {
         var fullMessage = message.Replace("#Type#", type);
         fullMessage = fullMessage.Replace("#Action#", action);
         fullMessage = fullMessage.Replace("#Server#", item.Server);
         fullMessage = fullMessage.Replace("#Now#", DateTime.Now.ToString());
         NotifiedMonitorItem notified;
         if (!IsNotified(item, key, type + action, fullMessage, out notified))
             if (Alert != null)
                 Alert(this, new AlertEventArgs(item, notified, fullMessage));
     }
 }
Esempio n. 3
0
 private bool IsNotified(MonitorItem item, string Key, string runtimeValue, string message, out NotifiedMonitorItem notified)
 {
     notified = null;
     var key = item.ToString() + ", " + Key + ", " + runtimeValue;
     if (!_notifiedAlerts.ContainsKey(key))
     {
         notified = new NotifiedMonitorItem { Server = item.Server, CurrentValue = message, CreatedDate = DateTime.Now };
         _notifiedAlerts.Add(key, notified);
         if (Settings.Instance.LogHistory)
             Settings.Instance.NotifiedAlerts.Add(notified);
         return false;
     }
     else
         return true;
 }
Esempio n. 4
0
 public AlertEventArgs(MonitorItem item, NotifiedMonitorItem notification, string message)
     : base(message, false)
 {
     this.Item = item;
     this.Notification = notification;
 }
Esempio n. 5
0
        private void ShowAlert(MonitorItem item, string key, string currentValue)
        {
            var message = Settings.Instance.AlertTemplate;

            if (string.IsNullOrEmpty(message))
            {
                message = Settings.DefaultTemplate;
            }
            var type   = string.Empty;
            var action = string.Empty;

            switch (item.AlertType)
            {
            case AlertTypes.Sql:
                action = currentValue;
                switch (item.CondictionType)
                {
                case 0:
                    type = "SQL executes: ";
                    break;

                case 1:
                    type = "SQL lasts: ";
                    break;

                case 2:
                    type = "SQL blocked: ";
                    break;

                case 3:
                    type = "Empty table: ";
                    break;

                default:
                    break;
                }
                break;

            case AlertTypes.Server:
                break;

            //case AlertTypes.CPU:
            //    message = string.Format("CPU usage is now {0}, higher than {1}", CurrentValue, Item.CondictionValue);
            //    break;
            //case AlertTypes.Memory:
            //    message = string.Format("Available memory is now {0}, lower than {1}", CurrentValue, Item.CondictionValue);
            //    break;
            //case AlertTypes.Diskspace:
            //    break;
            default:
                break;
            }
            if (!string.IsNullOrEmpty(message))
            {
                var fullMessage = message.Replace("#Type#", type);
                fullMessage = fullMessage.Replace("#Action#", action);
                fullMessage = fullMessage.Replace("#Server#", item.Server);
                fullMessage = fullMessage.Replace("#Now#", DateTime.Now.ToString());
                NotifiedMonitorItem notified;
                if (!IsNotified(item, key, type + action, fullMessage, out notified))
                {
                    if (Alert != null)
                    {
                        Alert(this, new AlertEventArgs(item, notified, fullMessage));
                    }
                }
            }
        }
Esempio n. 6
0
 public AlertEventArgs(MonitorItem item, NotifiedMonitorItem notification, string message)
     : base(message, false)
 {
     this.Item         = item;
     this.Notification = notification;
 }