private void AddAndStartMonitorPack(string monitorPackPath) { try { StringBuilder sbNotifiers = new StringBuilder(); MonitorPack monitorPack = new MonitorPack(); EventLog.WriteEntry(serviceEventSource, string.Format("Starting QuickMon MonitorPack '{0}'", monitorPackPath), EventLogEntryType.Information, 0); monitorPack.Load(monitorPackPath); if (monitorPack.Notifiers != null && monitorPack.Notifiers.Count > 0) { foreach (var notifier in monitorPack.Notifiers) { sbNotifiers.AppendLine("\t" + notifier.Name); } } EventLog.WriteEntry(serviceEventSource, string.Format("MonitorPack '{0}' has the following notifiers\r\n{1}", monitorPack.Name, sbNotifiers.ToString()), EventLogEntryType.Information, 0); monitorPack.RaiseNotifierError += new RaiseNotifierErrorDelegare(monitorPack_RaiseNotifierError); monitorPack.RaiseCollectorError += new RaiseCollectorErrorDelegare(monitorPack_RaiseCollectorError); monitorPack.CollectorExecutionTimeEvent += new CollectorExecutionTimeDelegate(monitorPack_CollectorExecutionTimeEvent); monitorPack.RunCollectorCorrectiveWarningScript += new RaiseCollectorCalledDelegate(monitorPack_RunCollectorCorrectiveWarningScript); monitorPack.RunCollectorCorrectiveErrorScript += new RaiseCollectorCalledDelegate(monitorPack_RunCollectorCorrectiveErrorScript); monitorPack.PollingFreq = Properties.Settings.Default.PollingFreqSec * 1000; monitorPack.ConcurrencyLevel = concurrencyLevel; packs.Add(monitorPack); monitorPack.StartPolling(); PCSetMonitorPacksLoaded(packs.Count); } catch (Exception ex) { EventLog.WriteEntry(serviceEventSource, string.Format("Error loading/starting MonitorPack '{0}'\r\n{1}", monitorPackPath, ex.Message), EventLogEntryType.Error, 11); } }
private void AddAndStartMonitorPack(string monitorPackPath) { try { StringBuilder sbNotifiers = new StringBuilder(); MonitorPack monitorPack = new MonitorPack(); EventLog.WriteEntry(Globals.ServiceEventSourceName, string.Format("Starting QuickMon MonitorPack '{0}'", monitorPackPath), EventLogEntryType.Information, (int)QuickMonServiceEventIDs.MonitorPack); monitorPack.Load(monitorPackPath); monitorPack.ApplicationUserNameCacheMasterKey = Properties.Settings.Default.ApplicationMasterKey; monitorPack.ApplicationUserNameCacheFilePath = Properties.Settings.Default.ApplicationUserNameCacheFilePath; monitorPack.CollectorStateHistorySize = 0; //For service history is always disabled!! if (monitorPack.NotifierHosts != null && monitorPack.NotifierHosts.Count > 0) { foreach (var notifier in monitorPack.NotifierHosts) { sbNotifiers.AppendLine("\t" + notifier.Name); } } EventLog.WriteEntry(Globals.ServiceEventSourceName, string.Format("MonitorPack '{0}' has the following notifiers\r\n{1}", monitorPack.Name, sbNotifiers.ToString()), EventLogEntryType.Information, (int)QuickMonServiceEventIDs.MonitorPack); monitorPack.OnNotifierError += new NotifierHostWithMessageDelegate(monitorPack_NotifierError); monitorPack.OnCollectorError += new CollectorHostWithMessageDelegate(monitorPack_RaiseCollectorError); monitorPack.CollectorHostAllAgentsExecutionTime += new CollectorHostExecutionTimeDelegate(monitorPack_CollectorHostAllAgentsExecutionTime); monitorPack.CollectorHostRestorationScriptExecuted += MonitorPack_CollectorHostRestorationScriptExecuted; monitorPack.CollectorHostRestorationScriptFailed += MonitorPack_CollectorHostRestorationScriptFailed; monitorPack.CollectorHostWarningCorrectiveScriptExecuted += MonitorPack_CollectorHostWarningCorrectiveScriptExecuted; monitorPack.CollectorHostWarningCorrectiveScriptFailed += MonitorPack_CollectorHostWarningCorrectiveScriptFailed; monitorPack.CollectorHostErrorCorrectiveScriptExecuted += MonitorPack_CollectorHostErrorCorrectiveScriptExecuted; monitorPack.CollectorHostErrorCorrectiveScriptFailed += MonitorPack_CollectorHostErrorCorrectiveScriptFailed; monitorPack.MonitorPackEventReported += monitorPack_MonitorPackEventReported; monitorPack.PollingFreq = Properties.Settings.Default.PollingFreqSec * 1000; monitorPack.ConcurrencyLevel = concurrencyLevel; monitorPack.RunningAttended = AttendedOption.OnlyUnAttended; packs.Add(monitorPack); monitorPack.StartPolling(); PCSetMonitorPacksLoaded(packs.Count); } catch (Exception ex) { EventLog.WriteEntry(Globals.ServiceEventSourceName, string.Format("Error loading/starting MonitorPack '{0}'\r\n{1}", monitorPackPath, ex.Message), EventLogEntryType.Error, (int)QuickMonServiceEventIDs.MonitorPack); } }
static void Main(string[] args) { bool useBackgroundPolling = false; bool showManagement = false; bool reportOnlyStates = true; string currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string registeredAgentsPath = currentPath;// +@"\RegisteredAgents.qmral"; string pingAgentAssembly = currentPath + @"\QMPing.dll"; string fileCountAgentAssembly = currentPath + @"\QMFileCount.dll"; string serviceStateAgentAssembly = currentPath + @"\QMServiceState.dll"; string bizTalkSuspendedCountAgentAssembly = currentPath + @"\QMBizTalkSuspendedCount.dll"; string logFileAgentAssembly = currentPath + @"\QMLogFile.dll"; string configurationFile = currentPath + @"\workConfig.qmconfig"; MonitorPack monitorPack = new MonitorPack(); #region Agent registrations try { monitorPack.AgentsAssemblyPath = registeredAgentsPath; } catch { monitorPack.AgentRegistrations = new List <AgentRegistration>(); monitorPack.AgentRegistrations.AddRange(new AgentRegistration[] { new AgentRegistration() { Name = "Ping", AssemblyPath = pingAgentAssembly, ClassName = "QuickMon.Ping", IsCollector = true, IsNotifier = false }, new AgentRegistration() { Name = "FileCount", AssemblyPath = fileCountAgentAssembly, ClassName = "QuickMon.FileCount", IsCollector = true, IsNotifier = false }, new AgentRegistration() { Name = "ServiceState", AssemblyPath = serviceStateAgentAssembly, ClassName = "QuickMon.ServiceState", IsCollector = true, IsNotifier = false }, new AgentRegistration() { Name = "BizTalkSuspendedCount", AssemblyPath = bizTalkSuspendedCountAgentAssembly, ClassName = "QuickMon.BizTalkSuspendedCount", IsCollector = true, IsNotifier = false }, new AgentRegistration() { Name = "LogFile", AssemblyPath = logFileAgentAssembly, ClassName = "QuickMon.LogFile", IsCollector = false, IsNotifier = true } } ); //SerializationUtils.SerializeXMLToFile<List<AgentRegistration>>(registeredAgentsFile, monitorPack.AgentRegistrations); } #endregion monitorPack.Load(configurationFile); if (useBackgroundPolling) { //monitorPack.RaiseAlert += new RaiseAlertDelegate(monitorPack_RaiseAlert); monitorPack.PollingFreq = 10000; monitorPack.StartPolling(); Console.WriteLine("Press any key to stop polling"); Console.ReadKey(); monitorPack.IsPolling = false; Console.WriteLine("Done"); } else if (showManagement) { Management.MonitorPackManagement monitorPackManagement = new Management.MonitorPackManagement(); monitorPackManagement.ShowMonitorPack(monitorPack); } else if (reportOnlyStates) { ConsoleKeyInfo cki = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false); monitorPack.RaiseCurrentState += new RaiseCurrentStateDelegate(monitorPack_RaiseCurrentState); while (cki.Key != ConsoleKey.Escape) { Console.WriteLine(new string('-', 79)); MonitorStates globalState = monitorPack.RefreshStates(); Console.WriteLine("Global state: {0}", globalState); Console.WriteLine("Last time: {0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Console.WriteLine(new string('-', 79)); Console.WriteLine("Press ESC to end"); cki = ConsoleHelper.ReadKeyWithTimeOut(20000); } } else { //monitorPack.RaiseAlert += new RaiseAlertDelegate(monitorPack_RaiseAlert); MonitorStates globalState = monitorPack.RefreshStates(); Console.WriteLine(new string('-', 79)); Console.WriteLine(string.Format("Current global state: {0}", globalState)); string level = " "; foreach (CollectorEntry ce in (from c in monitorPack.Collectors where c.ParentCollectorId.Length == 0 select c)) { ShowCollectorEntryStatus(monitorPack.Collectors, ce, level); } Console.WriteLine("Press any key to continue or wait 30 seconds"); ConsoleKeyInfo cki = ConsoleHelper.ReadKeyWithTimeOut(30000); if (cki.Key == ConsoleKey.S) { monitorPack.Save(currentPath + @"\Test.qmconfig"); } } }