예제 #1
0
 private void lvwRemoteHosts_DoubleClick(object sender, EventArgs e)
 {
     if (lvwRemoteHosts.SelectedItems.Count == 1)
     {
         try
         {
             ListViewItem               lvi           = lvwRemoteHosts.SelectedItems[0];
             RemoteAgentInfo            ri            = (RemoteAgentInfo)lvi.Tag;
             string                     remoteHostURL = string.Format("http://{0}:{1}/QuickMonRemoteHost", ri.Computer, ri.PortNumber);
             System.Diagnostics.Process p             = new System.Diagnostics.Process();
             p.StartInfo          = new System.Diagnostics.ProcessStartInfo();
             p.StartInfo.FileName = remoteHostURL;
             try
             {
                 p.Start();
             }
             catch (System.ComponentModel.Win32Exception ex)
             {
                 System.Diagnostics.Trace.WriteLine(ex.ToString());
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
예제 #2
0
        private void LoadKnownRemoteHosts()
        {
            ListViewItem lvi;

            if (Properties.Settings.Default.KnownRemoteHosts == null)
            {
                Properties.Settings.Default.KnownRemoteHosts = new System.Collections.Specialized.StringCollection();
            }
            else
            {
                lvwRemoteHosts.Items.Clear();
                foreach (string rh in (from string s in Properties.Settings.Default.KnownRemoteHosts
                                       orderby s
                                       select s))
                {
                    try
                    {
                        RemoteAgentInfo ri = RemoteAgentInfo.FromString(rh);
                        lvi = new ListViewItem(ri.Computer);
                        lvi.SubItems.Add(ri.PortNumber.ToString());
                        string computerNameOnly = rh;

                        lvi.SubItems.Add(""); //Version info to be added afterwards
                        lvi.SubItems.Add(""); //Packs info to be added afterwards
                        lvi.Tag        = ri;
                        lvi.ImageIndex = 0;
                        lvwRemoteHosts.Items.Add(lvi);
                    }
                    catch { }
                }
            }
        }
예제 #3
0
 private void cmdAdd_Click(object sender, EventArgs e)
 {
     if (txtComputer.Text.Length > 0)
     {
         try
         {
             if ((from ListViewItem lvi in lvwRemoteHosts.Items
                  where lvi.Text.ToLower() == txtComputer.Text.ToLower() &&
                  lvi.SubItems[1].Text == remoteportNumericUpDown.Value.ToString()
                  select lvi).Count() > 0)
             {
                 MessageBox.Show("Remote agent is already in the list!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else
             {
                 System.Net.IPAddress[] aa = System.Net.Dns.GetHostAddresses(txtComputer.Text);
                 if (aa.Length == 0)
                 {
                     MessageBox.Show("Computer not found or not available", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 else
                 {
                     RemoteAgentInfo ri = new RemoteAgentInfo();
                     ri.Computer   = txtComputer.Text;
                     ri.PortNumber = (int)remoteportNumericUpDown.Value;
                     ListViewItem lvi = new ListViewItem(txtComputer.Text);
                     lvi.SubItems.Add(remoteportNumericUpDown.Value.ToString());
                     lvi.SubItems.Add(""); //Version info to be added afterwards
                     lvi.Tag        = ri;
                     lvi.ImageIndex = 3;
                     lvwRemoteHosts.Items.Add(lvi);
                     RefreshServiceStates();
                     txtComputer.Text = "";
                     txtComputer.Focus();
                 }
             }
         }
         catch (Exception ex)
         {
             if (ex.Message.Contains("The requested name is valid, but no data of the requested type was found"))
             {
                 MessageBox.Show("Computer inaccessible or name invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
예제 #4
0
 private void attemptToStartAgentToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (lvwRemoteHosts.SelectedItems.Count > 0)
         {
             RemoteAgentInfo   ri   = (RemoteAgentInfo)lvwRemoteHosts.SelectedItems[0].Tag;
             ServiceController srvc = new ServiceController("QuickMon 3 Service", ri.Computer);
             srvc.Start();
             lvwRemoteHosts.SelectedItems[0].ImageIndex = 0;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #5
0
 private void monitorPacksToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (lvwRemoteHosts.SelectedItems.Count > 0)
     {
         StringBuilder sb        = new StringBuilder();
         bool          anyErrors = false;
         foreach (ListViewItem lvi in lvwRemoteHosts.SelectedItems)
         {
             RemoteAgentInfo ri = (RemoteAgentInfo)lvi.Tag;
             try
             {
                 int packCount = 0;
                 sb.AppendFormat("***{0}:{1}***\r\n", ri.Computer.ToUpper(), ri.PortNumber);
                 foreach (string mpFile in RemoteCollectorHostService.GetCurrentMonitorPacks(ri.Computer, ri.PortNumber))
                 {
                     sb.AppendLine("  " + mpFile.Replace(' ', ' ').TrimEnd());
                     packCount++;
                 }
                 if (packCount == 0)
                 {
                     sb.AppendLine("  No Monitor packs found.");
                 }
             }
             catch (Exception ex)
             {
                 anyErrors = true;
                 if (ex.Message.Contains("ContractFilter mismatch"))
                 {
                     sb.AppendFormat("  The service on {0}:{1} does not yet support this functionality.\r\n  Please check the version number!\r\n", ri.Computer, ri.PortNumber);
                 }
                 else
                 {
                     sb.AppendLine("  " + ex.Message);
                 }
             }
         }
         MessageBox.Show(sb.ToString(), "Monitor packs", MessageBoxButtons.OK, anyErrors ? MessageBoxIcon.Warning : MessageBoxIcon.Information);
     }
 }
예제 #6
0
            public static RemoteAgentInfo FromString(string remoteAgentStr)
            {
                RemoteAgentInfo newRemoteAgentInfo = new RemoteAgentInfo();

                if (remoteAgentStr.Contains(":"))
                {
                    newRemoteAgentInfo.Computer = remoteAgentStr.Substring(0, remoteAgentStr.IndexOf(":"));
                    if (remoteAgentStr.Substring(newRemoteAgentInfo.Computer.Length + 1).IsNumber())
                    {
                        newRemoteAgentInfo.PortNumber = int.Parse(remoteAgentStr.Substring(newRemoteAgentInfo.Computer.Length + 1));
                    }
                    else
                    {
                        newRemoteAgentInfo.PortNumber = 8181;
                    }
                }
                else
                {
                    newRemoteAgentInfo.Computer   = remoteAgentStr;
                    newRemoteAgentInfo.PortNumber = 8181;
                }
                return(newRemoteAgentInfo);
            }
예제 #7
0
        private void RemoteHostsManager_Load(object sender, EventArgs e)
        {
            ListViewItem lvi;

            try
            {
                ServiceController[] allServices = ServiceController.GetServices();
                ServiceController   qm3srvc     = (from s in allServices
                                                   where s.DisplayName == "QuickMon 3 Service"
                                                   select s).FirstOrDefault();
                if (qm3srvc == null)
                {
                    llblLocalServiceRegistered.Visible = true;
                }
                else
                {
                    llblLocalServiceRegistered.Visible = false;
                }

                try
                {
                    llblFirewallRule.Visible = true;
                    Microsoft.Win32.RegistryKey fwrules = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\services\SharedAccess\Parameters\FirewallPolicy\FirewallRules");
                    string quickMonRule = fwrules.GetValue("{F811AB2E-286C-4DB6-8512-4C991A8A54E9}").ToString();
                    if (quickMonRule.Length > 0)
                    {
                        llblFirewallRule.Visible = false;
                    }
                }
                catch { }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (Properties.Settings.Default.KnownRemoteHosts == null)
            {
                Properties.Settings.Default.KnownRemoteHosts = new System.Collections.Specialized.StringCollection();
            }
            else
            {
                foreach (string rh in (from string s in Properties.Settings.Default.KnownRemoteHosts
                                       orderby s
                                       select s))
                {
                    try
                    {
                        RemoteAgentInfo ri = RemoteAgentInfo.FromString(rh);

                        lvi = new ListViewItem(ri.Computer);
                        lvi.SubItems.Add(ri.PortNumber.ToString());
                        string computerNameOnly = rh;

                        lvi.SubItems.Add(""); //Version info to be added afterwards
                        lvi.Tag        = ri;
                        lvi.ImageIndex = 3;
                        lvwRemoteHosts.Items.Add(lvi);
                    }
                    catch { }
                }
            }
        }
예제 #8
0
        private void RefreshItem(object o)
        {
            ListViewItem lvi = (ListViewItem)o;

            try
            {
                try
                {
                    bool            hostExists = false;
                    RemoteAgentInfo ri         = (RemoteAgentInfo)lvi.Tag;
                    CollectorEntry  ce         = new CollectorEntry();
                    ce.EnableRemoteExecute              = true;
                    ce.RemoteAgentHostAddress           = ri.Computer;
                    ce.RemoteAgentHostPort              = ri.PortNumber;
                    ce.CollectorRegistrationName        = "PingCollector";
                    ce.CollectorRegistrationDisplayName = "Ping Collector";
                    ce.InitialConfiguration             = "<config><hostAddress><entry pingMethod=\"Ping\" address=\"localhost\" description=\"\" maxTimeMS=\"1000\" timeOutMS=\"5000\" httpProxyServer=\"\" socketPort=\"23\" receiveTimeoutMS=\"30000\" sendTimeoutMS=\"30000\" useTelnetLogin=\"False\" userName=\"\" password=\"\" /></hostAddress></config>";


                    hostExists = System.Net.Dns.GetHostAddresses(ri.Computer).Count() != 0;
                    if (!hostExists)
                    {
                        UpdateListViewItem(lvi, 3, "N/A");
                    }
                    else
                    {
                        MonitorState testState = CollectorEntryRelay.GetRemoteAgentState(ce);
                        if (testState.State == CollectorState.Good)
                        {
                            try
                            {
                                string versionInfo = CollectorEntryRelay.GetRemoteAgentHostVersion(ri.Computer, ri.PortNumber);
                                UpdateListViewItem(lvi, 0, versionInfo);
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message.Contains("ContractFilter"))
                                {
                                    UpdateListViewItem(lvi, 2, "Remote host does not support version info query! Check that QuickMon 3.13 or later is installed.");
                                }
                                else
                                {
                                    UpdateListViewItem(lvi, 2, ex.Message);
                                }
                            }
                        }
                        else
                        {
                            UpdateListViewItem(lvi, 2, "N/A");
                        }
                    }
                }
                catch (Exception delegateEx)
                {
                    if (delegateEx.Message.Contains("The formatter threw an exception while trying to deserialize the message"))
                    {
                        UpdateListViewItem(lvi, 3, "Old version of Remote agent host does not support query or format does not match! Please update remote agent host version.");
                    }
                    else
                    {
                        UpdateListViewItem(lvi, 3, delegateEx.Message);
                    }
                }
            }
            catch (Exception riEx)
            {
                UpdateListViewItem(lvi, 1, riEx.ToString());
            }
        }
예제 #9
0
        private void cmdAdd_Click(object sender, EventArgs e)
        {
            bool accepted = false;

            if (txtComputer.Text.Length > 0)
            {
                try
                {
                    if ((from ListViewItem lvi in lvwRemoteHosts.Items
                         where lvi.Text.ToLower() == txtComputer.Text.ToLower() &&
                         lvi.SubItems[1].Text == remoteportNumericUpDown.Value.ToString()
                         select lvi).Count() > 0)
                    {
                        MessageBox.Show("Remote host is already in the list!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        accepted = false;
                    }
                    else
                    {
                        System.Net.IPAddress[] aa = System.Net.Dns.GetHostAddresses(txtComputer.Text);
                        if (aa.Length == 0)
                        {
                            if (MessageBox.Show("Computer not found or not available!\r\nAccept anyway?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Yes)
                            {
                                accepted = true;
                            }
                        }
                        else
                        {
                            accepted = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("The requested name is valid, but no data of the requested type was found"))
                    {
                        if (MessageBox.Show("Computer inaccessible or name invalid!\r\nAccept anyway?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Yes)
                        {
                            accepted = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                if (accepted)
                {
                    RemoteAgentInfo ri = new RemoteAgentInfo();
                    ri.Computer   = txtComputer.Text;
                    ri.PortNumber = (int)remoteportNumericUpDown.Value;
                    ListViewItem lvi = new ListViewItem(txtComputer.Text);
                    lvi.SubItems.Add(remoteportNumericUpDown.Value.ToString());
                    lvi.SubItems.Add(""); //Version info to be added afterwards
                    lvi.SubItems.Add(""); //Packs
                    lvi.Tag        = ri;
                    lvi.ImageIndex = 3;
                    lvwRemoteHosts.Items.Add(lvi);
                    RefreshServiceStates();
                    txtComputer.Text = "";
                    txtComputer.Focus();

                    Properties.Settings.Default.KnownRemoteHosts = new System.Collections.Specialized.StringCollection();
                    foreach (ListViewItem l in lvwRemoteHosts.Items)
                    {
                        if (l.Tag is RemoteAgentInfo)
                        {
                            Properties.Settings.Default.KnownRemoteHosts.Add(((RemoteAgentInfo)l.Tag).ToString());
                        }
                    }
                    Properties.Settings.Default.Save();
                }
            }
        }
예제 #10
0
        private void RefreshItem(object o)
        {
            ListViewItem lvi = (ListViewItem)o;

            try
            {
                try
                {
                    bool            hostExists = false;
                    RemoteAgentInfo ri         = (RemoteAgentInfo)lvi.Tag;
                    string          configXml  = "<collectorHost uniqueId=\"Ping" + ri.Computer.EscapeXml() + "\" name=\"Ping " + ri.Computer.EscapeXml() + " tests\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"\" " +
                                                 "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                                                 "enableRemoteExecute=\"True\" " +
                                                 "forceRemoteExcuteOnChildCollectors=\"False\" remoteAgentHostAddress=\"" + ri.Computer.EscapeXml() + "\" remoteAgentHostPort=\"48191\" " +
                                                 "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"True\" >\r\n" +
                                                 "<collectorAgents>\r\n" +
                                                 "<collectorAgent type=\"PingCollector\">\r\n" +
                                                 "<config>\r\n" +
                                                 "<entries>\r\n" +
                                                 "<entry pingMethod=\"Ping\" address=\"" + ri.Computer.EscapeXml() + "\" />\r\n" +
                                                 "</entries>\r\n" +
                                                 "</config>\r\n" +
                                                 "</collectorAgent>\r\n" +
                                                 "</collectorAgents>\r\n" +
                                                 "</collectorHost>\r\n";
                    CollectorHost ce = CollectorHost.FromXml(configXml);

                    ce.EnableRemoteExecute    = true;
                    ce.RemoteAgentHostAddress = ri.Computer;
                    ce.RemoteAgentHostPort    = ri.PortNumber;
                    try
                    {
                        hostExists = System.Net.Dns.GetHostAddresses(ri.Computer).Count() != 0;
                    }
                    catch { }
                    if (!hostExists)
                    {
                        UpdateListViewItem(lvi, 4, "", "Host not found");
                    }
                    else if (!CanPingHost(ri.Computer))
                    {
                        UpdateListViewItem(lvi, 4, "", "Host not pingable");
                    }
                    else
                    {
                        MonitorState testState = RemoteCollectorHostService.GetCollectorHostState(ce);
                        if (testState.State == CollectorState.Good)
                        {
                            try
                            {
                                string versionInfo = RemoteCollectorHostService.GetRemoteAgentHostVersion(ri.Computer, ri.PortNumber);
                                string packs       = "0";

                                //Pack count
                                try
                                {
                                    packs = RemoteCollectorHostService.GetCurrentMonitorPacks(ri.Computer, ri.PortNumber).Count().ToString();
                                }
                                catch (Exception packsEx)
                                {
                                    packs = packsEx.Message;
                                    if (packsEx.Message.Contains("ContractFilter mismatch"))
                                    {
                                        packs = "Check version!";
                                    }
                                    else
                                    {
                                        packs = packsEx.Message;
                                    }
                                }

                                UpdateListViewItem(lvi, 1, versionInfo, packs);
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message.Contains("ContractFilter"))
                                {
                                    UpdateListViewItem(lvi, 2, "", "Remote host does not support version info query! Check that QuickMon 4.x or later is installed.");
                                }
                                else
                                {
                                    UpdateListViewItem(lvi, 2, "", ex.Message);
                                }
                            }
                        }
                        else
                        {
                            UpdateListViewItem(lvi, 3, "N/A", "N/A");
                        }
                    }
                }
                catch (Exception delegateEx)
                {
                    if (delegateEx.Message.StartsWith("There was no endpoint listening"))
                    {
                        UpdateListViewItem(lvi, 3, "", "Service not running or inaccessible");
                    }
                    else if (delegateEx.Message.Contains("The formatter threw an exception while trying to deserialize the message"))
                    {
                        UpdateListViewItem(lvi, 3, "", "Old version of Remote agent host does not support query or format does not match! Please update remote agent host version.");
                    }
                    else
                    {
                        UpdateListViewItem(lvi, 3, "", delegateEx.Message);
                    }
                }
            }
            catch (Exception riEx)
            {
                UpdateListViewItem(lvi, 1, "", riEx.ToString());
            }
        }