示例#1
0
 private void SendTo(MonitorTarget target, MonitorWorkItem workItem, ILog log, string subjectPrefix)
 {
     MonitorEntry[] entries = workItem.GetEntries(target);
     if (entries.Length != 0)
     {
         if (target.Recipients == null || target.Recipients.Length == 0)
         {
             log.Warning(Target.Service, "No recipients found for target '{0}'.", new object[] { target });
             return;
         }
         log.Message("Sending {0} entries to {1}.", new object[] { (int)entries.Length, target });
         StringBuilder          stringBuilder = new StringBuilder();
         ApplicationEnvironment environment   = this._runtimeSettings.Environment;
         if (environment != null)
         {
             stringBuilder.AppendFormat("[{0}] ", environment);
         }
         if (!string.IsNullOrWhiteSpace(subjectPrefix))
         {
             stringBuilder.AppendFormat("{0}: ", subjectPrefix);
         }
         stringBuilder.AppendFormat("Monitoring ({0})", workItem.CheckRange);
         this._emailService.Send(new MonitorEmailTemplate(stringBuilder.ToString(), entries, target), target.Recipients);
     }
 }
示例#2
0
        private void SendTo(MonitorTarget target, ITaskExecutionContext <MonitorWorkItem> context)
        {
            MonitorEntry[] entries = context.WorkItem.GetEntries(target);

            if (entries.Length > 0)
            {
                if (target.Recipients == null || target.Recipients.Length == 0)
                {
                    context.Log.Warning(Target.Service, "No recipients found for target '{0}'.", target);
                    return;
                }

                context.Log.Message("Sending {0} entries to {1}.", entries.Length, target);

                var subject = new StringBuilder();

                ApplicationEnvironment environment = _runtimeSettings.Environment;

                if (environment != null)
                {
                    subject.AppendFormat("[{0}] ", environment);
                }

                if (!string.IsNullOrWhiteSpace(context.WorkItem.Configuration.SubjectPrefix))
                {
                    subject.AppendFormat("{0}: ", context.WorkItem.Configuration.SubjectPrefix);
                }

                subject.AppendFormat("Monitoring ({0})", context.WorkItem.CheckRange);

                _emailService.Send(new MonitorEmailTemplate(subject.ToString(), entries, target), target.Recipients);
            }
        }
 public MonitorEmailTemplate(string subject, MonitorEntry[] entries, MonitorTarget target)
 {
     if (entries == null)
     {
         throw new ArgumentNullException("entries");
     }
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     this._subject = subject;
     this._entries = entries;
     this._target  = target;
 }
        internal void Assert()
        {
            if (Targets == null)
            {
                throw new InvalidOperationException("No targets defined for MonitorConfiguration.");
            }

            MonitorTarget service = Targets.SingleOrDefault(x => x.Equals(Target.Service));

            if (service == null)
            {
                throw new InvalidOperationException($"Missing required target '{Target.Service}' for MonitorConfiguration.");
            }
        }
        public MonitorEmailTemplate(string subject, MonitorEntry[] entries, MonitorTarget target)
        {
            if (entries == null)
            {
                throw new ArgumentNullException(nameof(entries));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            Subject  = subject;
            _entries = entries;
            _target  = target;
        }
        public MonitorTarget EnsureMonitorTarget(ITarget target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            MonitorTarget[] targets       = this.Targets ?? new MonitorTarget[0];
            MonitorTarget   monitorTarget = targets.FirstOrDefault <MonitorTarget>((MonitorTarget x) => x.Equals(target));

            if (monitorTarget == null)
            {
                monitorTarget = new MonitorTarget(target.Name);
                this.Targets  = targets.Concat <MonitorTarget>((IEnumerable <MonitorTarget>)(new MonitorTarget[] { monitorTarget })).ToArray <MonitorTarget>();
            }
            return(monitorTarget);
        }
示例#7
0
 public override void End(MonitorWorkItem workItem, ITaskExecutionContext context)
 {
     Target[] targetArray;
     if (workItem.HasEntriesForUnconfiguredTargets(out targetArray))
     {
         context.Log.Error(Target.Service, "Create missing configuration for the following targets: [{0}].", new object[]
                           { string.Join(", ", from x in (IEnumerable <Target>) targetArray select x.Name) });
     }
     MonitorTarget[] targets = workItem.Configuration.Targets ?? new MonitorTarget[0];
     for (int i = 0; i < (int)targets.Length; i++)
     {
         MonitorTarget monitorTarget = targets[i];
         this.SendTo(monitorTarget, workItem, context.Log, workItem.Configuration.SubjectPrefix);
     }
     workItem.Configuration.LastRun = workItem.CheckRange.UpperBound;
     this._configuration.Save <MonitorConfiguration>(workItem.Configuration, base.Name, false);
 }
        public MonitorTarget EnsureMonitorTarget(ITarget target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var existingTargets = Targets ?? new MonitorTarget[0];

            MonitorTarget monitorTarget = existingTargets.FirstOrDefault(x => x.Equals(target));

            if (monitorTarget == null)
            {
                monitorTarget = new MonitorTarget(target.Name);
                Targets       = existingTargets.Concat(new[] { monitorTarget }).ToArray();
            }

            return(monitorTarget);
        }