예제 #1
0
        public System.Data.DataSet GetCollectorHostDetails(QuickMon.RemoteCollectorHost entry)
        {
            StringBuilder consoleOutPut = new StringBuilder();

            System.Data.DataSet result = new System.Data.DataSet();
            try
            {
                Console.WriteLine("{0}: Getting collector host data set: {1}\r\n{2}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name, new string('*', 79));
                CollectorHost ch = CollectorHost.FromXml(entry.ToCollectorHostXml());
                result = ch.GetAllAgentDetails();
                consoleOutPut.AppendFormat("{0}: Results for collector host: {1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name);
                consoleOutPut.AppendFormat("  Data set request received: {0}\r\n", entry.Name);
                if (result != null)
                {
                    consoleOutPut.AppendFormat("   Tables: {0}\r\n", result.Tables.Count);
                    for (int i = 0; i < result.Tables.Count; i++)
                    {
                        consoleOutPut.AppendFormat("    Table[{0}]: {1} row(s)\r\n", i, result.Tables[i].Rows.Count);
                    }
                }
                else
                {
                    consoleOutPut.AppendFormat("  Warning! Data set is empty!\r\n");
                }
            }
            catch (Exception ex)
            {
                consoleOutPut.AppendFormat(" Error: {0}\r\n", ex);
                System.Data.DataTable dt = new System.Data.DataTable("Exception");
                dt.Columns.Add(new System.Data.DataColumn("Text", typeof(string)));
                dt.Rows.Add(ex.ToString());
                result.Tables.Add(dt);
            }
            consoleOutPut.AppendLine(new string('*', 79));
            Console.WriteLine(consoleOutPut.ToString());
            return(result);
        }
예제 #2
0
        public MonitorState GetState(QuickMon.RemoteCollectorHost entry)
        {
            StringBuilder consoleOutPut = new StringBuilder();
            MonitorState  monitorState  = new MonitorState();

            /*** For Console debugging **/
            consoleOutPut.AppendFormat("{0}: Running collector host: {1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name);
            try
            {
                OperationContext context = OperationContext.Current;
                System.ServiceModel.Channels.MessageProperties             messageProperties = context.IncomingMessageProperties;
                System.ServiceModel.Channels.RemoteEndpointMessageProperty endpointProperty  =
                    messageProperties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty;

                consoleOutPut.AppendFormat(" Requested from {0}:{1}\r\n", endpointProperty.Address, endpointProperty.Port);
            }
            catch (Exception ex)
            {
                consoleOutPut.AppendFormat(" Error getting caller info: {0}\r\n", ex.Message);
            }
            consoleOutPut.AppendFormat("{0}\r\n", new string('*', 79));
            Console.WriteLine(consoleOutPut.ToString());
            consoleOutPut = new StringBuilder();
            /*** For Console debugging **/

            try
            {
                string collectorHostConfig = entry.ToCollectorHostXml();
                string tempMonitorPack     = "<monitorPack version=\"5.0.0.0\" name=\"\" typeName=\"\" enabled=\"True\" defaultNotifier=\"\" runCorrectiveScripts=\"False\" collectorStateHistorySize=\"1\" pollingFreqSecOverride=\"0\">" +
                                             "<collectorHosts>" +
                                             collectorHostConfig +
                                             "</collectorHosts>\r\n" +
                                             "<notifierHosts>\r\n" +
                                             "</notifierHosts>\r\n" +
                                             "</monitorPack>";
                MonitorPack m = new MonitorPack();
                m.LoadXml(tempMonitorPack);
                m.ApplicationUserNameCacheMasterKey = ApplicationUserNameCacheMasterKey;
                m.ApplicationUserNameCacheFilePath  = ApplicationUserNameCacheFilePath;
                m.BlockedCollectorAgentTypes.AddRange(BlockedCollectorAgentTypes.ToArray());
                m.ScriptsRepositoryDirectory = ScriptsRepositoryDirectory;
                if (m.CollectorHosts.Count == 1)
                {
                    m.RefreshStates();
                    //Since there is only one CollectorHost
                    CollectorHost ch = m.CollectorHosts[0];
                    monitorState       = ch.CurrentState;
                    monitorState.RanAs = ch.CurrentState.RanAs;
                }
                else
                {
                    monitorState.CurrentValue = "There was a problem loading the Collector Host config on the remote host!";
                    monitorState.RawDetails   = collectorHostConfig;
                    monitorState.HtmlDetails  = collectorHostConfig.EscapeXml();
                    monitorState.State        = CollectorState.Error;
                }
                //If hosted in console test app
                consoleOutPut.AppendFormat("{0}: Results for collector host: {1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name);
                consoleOutPut.AppendFormat(" State   : {0}\r\n", monitorState.State);
                consoleOutPut.AppendFormat(" Ran as  : {0}\r\n", monitorState.RanAs);
                consoleOutPut.AppendFormat(" Details : {0}\r\n", monitorState.ReadAllRawDetails());
            }
            catch (Exception ex)
            {
                consoleOutPut.AppendFormat(" Error: {0}\r\n", ex);
                monitorState.CurrentValue = ex.Message;
                monitorState.State        = CollectorState.Error;
                monitorState.RawDetails   = ex.ToString();
                monitorState.HtmlDetails  = ex.ToString().EscapeXml();
            }

            consoleOutPut.AppendLine(new string('*', 79));
            Console.WriteLine(consoleOutPut.ToString());

            monitorState.ExecutedOnHostComputer = System.Net.Dns.GetHostName();
            return(monitorState);
        }