Ejemplo n.º 1
0
        public static NotifierEntry FromConfig(XmlElement xmlNotifierEntry)
        {
            NotifierEntry notifierEntry = new NotifierEntry();

            notifierEntry.Name = xmlNotifierEntry.Attributes.GetNamedItem("name").Value;
            notifierEntry.NotifierRegistrationName = xmlNotifierEntry.Attributes.GetNamedItem("notifier").Value;
            notifierEntry.Enabled       = bool.Parse(xmlNotifierEntry.Attributes.GetNamedItem("enabled").Value);
            notifierEntry.AlertLevel    = (AlertLevel)Enum.Parse(typeof(AlertLevel), xmlNotifierEntry.Attributes.GetNamedItem("alertLevel").Value);
            notifierEntry.DetailLevel   = (DetailLevel)Enum.Parse(typeof(DetailLevel), xmlNotifierEntry.Attributes.GetNamedItem("detailLevel").Value);
            notifierEntry.Configuration = xmlNotifierEntry.SelectSingleNode("config").OuterXml;

            XmlNode serviceWindowsNode = xmlNotifierEntry.SelectSingleNode("collectors");

            if (serviceWindowsNode != null)
            {
                foreach (XmlElement colNode in serviceWindowsNode.SelectNodes("collector"))
                {
                    string collectorName = colNode.ReadXmlElementAttr("name", "");
                    if (collectorName.Length > 0)
                    {
                        notifierEntry.AlertForCollectors.Add(collectorName);
                    }
                }
            }

            return(notifierEntry);
        }
Ejemplo n.º 2
0
 private void ShowNotifierError(NotifierEntry notifier, string errorMessage)
 {
     if (MessageBox.Show(string.Format("There was a problem recording an alert with notifier {0}\r\nDo you want to disable it?\r\n{1}", notifier.Name, errorMessage), "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Yes)
     {
         notifier.Enabled = false;
     }
 }
Ejemplo n.º 3
0
        public static NotifierEntry FromConfig(XmlElement xmlNotifierEntry)
        {
            NotifierEntry notifierEntry = new NotifierEntry();

            notifierEntry.Name = xmlNotifierEntry.ReadXmlElementAttr("name");
            notifierEntry.NotifierRegistrationName = xmlNotifierEntry.ReadXmlElementAttr("notifier");
            notifierEntry.Enabled                = xmlNotifierEntry.ReadXmlElementAttr("enabled", false);
            notifierEntry.AlertLevel             = (AlertLevel)Enum.Parse(typeof(AlertLevel), xmlNotifierEntry.ReadXmlElementAttr("alertLevel", "Warning"));
            notifierEntry.DetailLevel            = (DetailLevel)Enum.Parse(typeof(DetailLevel), xmlNotifierEntry.ReadXmlElementAttr("detailLevel", "Detail"));
            notifierEntry.AttendedOptionOverride = (AttendedOption)Enum.Parse(typeof(AttendedOption), xmlNotifierEntry.ReadXmlElementAttr("attendedOptionOverride", "AttendedAndUnAttended"));
            if (xmlNotifierEntry.SelectSingleNode("config") != null)
            {
                notifierEntry.InitialConfiguration = xmlNotifierEntry.SelectSingleNode("config").OuterXml;
            }

            //Service windows config
            notifierEntry.ServiceWindows = new ServiceWindows();
            XmlNode serviceWindowsNode = xmlNotifierEntry.SelectSingleNode("serviceWindows");

            if (serviceWindowsNode != null) //Load service windows info
            {
                notifierEntry.ServiceWindows.CreateFromConfig(serviceWindowsNode.OuterXml);
            }
            else
            {
                notifierEntry.ServiceWindows.CreateFromConfig("<serviceWindows />");
            }

            XmlNode collectorsNode = xmlNotifierEntry.SelectSingleNode("collectors");

            if (collectorsNode != null)
            {
                foreach (XmlElement colNode in collectorsNode.SelectNodes("collector"))
                {
                    string collectorName = colNode.ReadXmlElementAttr("name", "");
                    if (collectorName.Length > 0)
                    {
                        notifierEntry.AlertForCollectors.Add(collectorName);
                    }
                }
            }
            XmlNode configVarsNode = xmlNotifierEntry.SelectSingleNode("configVars");

            if (configVarsNode != null)
            {
                foreach (XmlNode configVarNode in configVarsNode.SelectNodes("configVar"))
                {
                    notifierEntry.ConfigVariables.Add(ConfigVariable.FromXml(configVarNode.OuterXml));
                }
            }
            return(notifierEntry);
        }
Ejemplo n.º 4
0
        internal void SwapNotifierEntries(NotifierEntry n1, NotifierEntry n2)
        {
            int index1 = Notifiers.FindIndex(c => c.Name == n1.Name);
            int index2 = Notifiers.FindIndex(c => c.Name == n2.Name);

            if (index1 > -1 && index2 > -1 && index1 != index2)
            {
                Notifiers.RemoveAt(index1);
                Notifiers.RemoveAt(index2);
                Notifiers.Insert(index2, n1);
                Notifiers.Insert(index1, n2);
            }
        }
Ejemplo n.º 5
0
 private void monitorPack_RaiseNotifierError(NotifierEntry notifier, string errorMessage)
 {
     if (this.InvokeRequired)
     {
         this.Invoke((MethodInvoker) delegate
         {
             ShowNotifierError(notifier, errorMessage);
         });
     }
     else
     {
         ShowNotifierError(notifier, errorMessage);
     }
 }
Ejemplo n.º 6
0
 private void RaiseRaiseNotifierError(NotifierEntry notifier, string errorMessage)
 {
     try
     {
         if (RaiseNotifierError != null)
         {
             RaiseNotifierError(notifier, errorMessage);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine(string.Format("Error in RaiseRaiseNotifierError: {0}", ex.Message));
     }
 }
Ejemplo n.º 7
0
 private void openViewerToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (lvwNotifiers.SelectedItems.Count == 1 &&
             lvwNotifiers.SelectedItems[0].Tag is NotifierEntry &&
             ((NotifierEntry)lvwNotifiers.SelectedItems[0].Tag).Notifier.HasViewer)
         {
             NotifierEntry ne = (NotifierEntry)lvwNotifiers.SelectedItems[0].Tag;
             ne.OpenViewer();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 8
0
        public static NotifierEntry CreateAndEditNewNotifier(MonitorPack monitorPack)
        {
            NotifierEntry newNotifierEntry = CreateNewNotifier();

            if (newNotifierEntry != null)
            {
                Management.EditNotifierEntry editNotifierEntry = new Management.EditNotifierEntry();
                editNotifierEntry.SelectedEntry      = newNotifierEntry;
                editNotifierEntry.LaunchAddEntry     = LastLaunchAddEntryOption;
                editNotifierEntry.ShowRawEditOnStart = LastShowRawEditOnStartOption;

                if (editNotifierEntry.ShowDialog(monitorPack) != System.Windows.Forms.DialogResult.OK)
                {
                    newNotifierEntry = null;
                }
            }
            return(newNotifierEntry);
        }
Ejemplo n.º 9
0
        public static NotifierEntry CreateNewNotifier()
        {
            NotifierEntry      newNotifierEntry   = null;
            SelectNewAgentType selectNewAgentType = new SelectNewAgentType();

            selectNewAgentType.InitialRegistrationName = "";
            if (selectNewAgentType.ShowNotifierSelection() == System.Windows.Forms.DialogResult.OK)
            {
                LastLaunchAddEntryOption     = selectNewAgentType.SelectedPreset == null;
                LastShowRawEditOnStartOption = selectNewAgentType.ImportConfigAfterSelect;
                newNotifierEntry             = new NotifierEntry();
                RegisteredAgent ar = null;
                if (selectNewAgentType.SelectedPreset != null)
                {
                    ar = RegisteredAgentCache.GetRegisteredAgentByClassName(selectNewAgentType.SelectedPreset.AgentClassName, false);
                }
                else if (selectNewAgentType.SelectedAgent != null)
                {
                    ar = selectNewAgentType.SelectedAgent;
                }
                else
                {
                    return(null);
                }

                if (ar == null) //in case agent is not loaded or available
                {
                    return(null);
                }
                else
                {
                    string initialConfig = "";
                    if (selectNewAgentType.SelectedPreset != null)
                    {
                        initialConfig         = MacroVariables.FormatVariables(selectNewAgentType.SelectedPreset.Config);
                        newNotifierEntry.Name = selectNewAgentType.SelectedPreset.Description;
                    }
                    newNotifierEntry.CreateAndConfigureEntry(ar.ClassName, initialConfig, true, false);
                }
            }
            return(newNotifierEntry);
        }
Ejemplo n.º 10
0
 private void monitorPack_RaiseNotifierError(NotifierEntry notifier, string errorMessage)
 {
     EventLog.WriteEntry(serviceEventSource, string.Format("There was a problem recording an alert with notifier {0}\r\n{1}", notifier.Name, errorMessage), EventLogEntryType.Error, 1);
 }
Ejemplo n.º 11
0
 public static System.Windows.Forms.DialogResult EditNotifierEntry(NotifierEntry notifierEntry, MonitorPack monitorPack)
 {
     Management.EditNotifierEntry editNotifierEntry = new Management.EditNotifierEntry();
     editNotifierEntry.SelectedEntry = notifierEntry;
     return(editNotifierEntry.ShowDialog(monitorPack));
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Loading QuickMon monitor pack file
        /// </summary>
        /// <param name="configurationFile">Serialzed monitor pack file</param>
        public void Load(string configurationFile)
        {
            XmlDocument configurationXml = new XmlDocument();

            configurationXml.LoadXml(System.IO.File.ReadAllText(configurationFile, Encoding.UTF8));
            XmlElement root = configurationXml.DocumentElement;

            Name               = root.Attributes.GetNamedItem("name").Value;
            Enabled            = bool.Parse(root.Attributes.GetNamedItem("enabled").Value);
            AgentsAssemblyPath = root.ReadXmlElementAttr("agentRegistrationPath");

            string defaultViewerNotifierName = root.ReadXmlElementAttr("defaultViewerNotifier");

            RunCorrectiveScripts = bool.Parse(root.ReadXmlElementAttr("runCorrectiveScripts", "false"));
            foreach (XmlElement xmlCollectorEntry in root.SelectNodes("collectorEntries/collectorEntry"))
            {
                CollectorEntry newCollectorEntry = CollectorEntry.FromConfig(xmlCollectorEntry);
                ApplyCollectorConfig(newCollectorEntry);
                Collectors.Add(newCollectorEntry);
            }
            foreach (XmlElement xmlNotifierEntry in root.SelectNodes("notifierEntries/notifierEntry"))
            {
                NotifierEntry     newNotifierEntry = NotifierEntry.FromConfig(xmlNotifierEntry);
                AgentRegistration currentNotifier  = null;
                if (AgentRegistrations != null)
                {
                    currentNotifier = (from o in AgentRegistrations
                                       where o.IsNotifier && o.Name == newNotifierEntry.NotifierRegistrationName
                                       select o).FirstOrDefault();
                }
                if (currentNotifier != null)
                {
                    newNotifierEntry.Notifier = NotifierEntry.CreateNotifierEntry(currentNotifier.AssemblyPath, currentNotifier.ClassName);
                    XmlDocument configDoc = new XmlDocument();
                    configDoc.LoadXml(newNotifierEntry.Configuration);
                    try
                    {
                        newNotifierEntry.Notifier.ReadConfiguration(configDoc);
                    }
                    catch                     // (Exception ex)
                    {
                        newNotifierEntry.Enabled = false;
                    }
                }
                else
                {
                    newNotifierEntry.Enabled = false;
                }
                Notifiers.Add(newNotifierEntry);
                if (newNotifierEntry.Name.ToUpper() == defaultViewerNotifierName.ToUpper())
                {
                    DefaultViewerNotifier = newNotifierEntry;
                }
            }
            MonitorPackPath = configurationFile;
            RaiseMonitorPackPathChanged(MonitorPackPath);
            if (Properties.Settings.Default.recentMonitorPacks == null)
            {
                Properties.Settings.Default.recentMonitorPacks = new System.Collections.Specialized.StringCollection();
            }
            if (!Properties.Settings.Default.recentMonitorPacks.Contains(configurationFile))
            {
                Properties.Settings.Default.recentMonitorPacks.Add(configurationFile);
                Properties.Settings.Default.Save();
            }
            InitializeGlobalPerformanceCounters();
        }