Esempio n. 1
0
        private void lblColumnNameSequence_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                WMIQueryCollectorConfigEntry tmpWMIConfig = new WMIQueryCollectorConfigEntry();
                tmpWMIConfig.Name                = txtName.Text;
                tmpWMIConfig.Namespace           = txtNamespace.Text;
                tmpWMIConfig.Machinename         = txtMachines.Text;
                tmpWMIConfig.StateQuery          = txtStateQuery.Text;
                tmpWMIConfig.ReturnValueIsInt    = chkIsReturnValueInt.Checked;
                tmpWMIConfig.ReturnValueInverted = !chkReturnValueNotInverted.Checked;
                tmpWMIConfig.UseRowCountAsValue  = chkUseRowCountAsValue.Checked;
                tmpWMIConfig.SuccessValue        = cboSuccessValue.Text;
                tmpWMIConfig.WarningValue        = cboWarningValue.Text;
                tmpWMIConfig.ErrorValue          = cboErrorValue.Text;
                tmpWMIConfig.DetailQuery         = txtDetailQuery.Text;
                tmpWMIConfig.ColumnNames         = txtColumnNames.Text.ToListFromCSVString();
                // tmpWMIConfig.KeyColumn = (int)keyColumnNumericUpDown.Value;

                List <DataColumn> columns = tmpWMIConfig.GetDetailQueryColumns();
                txtColumnNames.Text = "";
                columns.ForEach(c => txtColumnNames.Text += c.ColumnName + ", ");
                txtColumnNames.Text = txtColumnNames.Text.TrimEnd(' ', ',');
            }
            catch { }
        }
Esempio n. 2
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (DoValidate())
            {
                if (SelectedEntry == null)
                {
                    SelectedEntry = new WMIQueryCollectorConfigEntry();
                }
                WMIQueryCollectorConfigEntry selectedEntry = (WMIQueryCollectorConfigEntry)SelectedEntry;

                selectedEntry.Name                = txtName.Text;
                selectedEntry.Namespace           = txtNamespace.Text;
                selectedEntry.Machinename         = txtMachines.Text;
                selectedEntry.StateQuery          = txtStateQuery.Text;
                selectedEntry.ReturnValueIsInt    = chkIsReturnValueInt.Checked;
                selectedEntry.ReturnValueInverted = !chkReturnValueNotInverted.Checked;
                selectedEntry.UseRowCountAsValue  = chkUseRowCountAsValue.Checked;
                selectedEntry.SuccessValue        = cboSuccessValue.Text;
                selectedEntry.WarningValue        = cboWarningValue.Text;
                selectedEntry.ErrorValue          = cboErrorValue.Text;
                selectedEntry.DetailQuery         = txtDetailQuery.Text;
                selectedEntry.ColumnNames         = txtColumnNames.Text.ToListFromCSVString();

                SelectedEntry = selectedEntry;
                //WmiIConfig.KeyColumn = (int)keyColumnNumericUpDown.Value;
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
Esempio n. 3
0
 private void EditConfig_Shown(object sender, EventArgs e)
 {
     if (SelectedEntry != null)
     {
         WMIQueryCollectorConfigEntry selectedEntry = (WMIQueryCollectorConfigEntry)SelectedEntry;
         txtName.Text                      = selectedEntry.Name;
         txtNamespace.Text                 = selectedEntry.Namespace == null ? "root\\CIMV2" : selectedEntry.Namespace;
         txtMachines.Text                  = selectedEntry.Machinename == null ? "." : selectedEntry.Machinename;
         txtStateQuery.Text                = selectedEntry.StateQuery;
         chkIsReturnValueInt.Checked       = selectedEntry.ReturnValueIsInt;
         chkReturnValueNotInverted.Checked = !selectedEntry.ReturnValueInverted;
         chkUseRowCountAsValue.Checked     = selectedEntry.UseRowCountAsValue;
         cboSuccessValue.Text              = selectedEntry.SuccessValue;
         cboWarningValue.Text              = selectedEntry.WarningValue;
         cboErrorValue.Text                = selectedEntry.ErrorValue;
         txtDetailQuery.Text               = selectedEntry.DetailQuery;
         txtColumnNames.Text               = selectedEntry.ColumnNames.ToCSVString();
     }
 }
Esempio n. 4
0
        public void FromXml(string configurationString)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(configurationString);
            Entries.Clear();
            XmlElement root = config.DocumentElement;

            foreach (XmlElement wmiQueryNode in root.SelectNodes("wmiQueries/wmiQuery"))
            {
                WMIQueryCollectorConfigEntry entry = new WMIQueryCollectorConfigEntry();
                entry.Namespace   = wmiQueryNode.ReadXmlElementAttr("namespace", "root\\CIMV2");
                entry.Machinename = wmiQueryNode.ReadXmlElementAttr("machineName", ".");
                entry.Name        = wmiQueryNode.ReadXmlElementAttr("name", entry.Machinename);
                XmlNode stateQueryNode = wmiQueryNode.SelectSingleNode("stateQuery");
                entry.StateQuery          = stateQueryNode.ReadXmlElementAttr("syntax", "");
                entry.ReturnValueIsInt    = bool.Parse(stateQueryNode.ReadXmlElementAttr("returnValueIsInt", "True"));
                entry.ReturnValueInverted = bool.Parse(stateQueryNode.ReadXmlElementAttr("returnValueInverted", "False"));
                entry.WarningValue        = stateQueryNode.ReadXmlElementAttr("warningValue", "0");
                entry.ErrorValue          = stateQueryNode.ReadXmlElementAttr("errorValue", "0");
                entry.SuccessValue        = stateQueryNode.ReadXmlElementAttr("successValue", "[any]");
                entry.UseRowCountAsValue  = bool.Parse(stateQueryNode.ReadXmlElementAttr("useRowCountAsValue", "True"));
                XmlNode detailQueryNode = wmiQueryNode.SelectSingleNode("detailQuery");
                entry.DetailQuery = detailQueryNode.ReadXmlElementAttr("syntax", "");
                string columns = detailQueryNode.ReadXmlElementAttr("columnNames", "");
                entry.ColumnNames = new List <string>();
                if (columns.Length > 0 && columns.IndexOf(',') > -1)
                {
                    entry.ColumnNames = columns.ToListFromCSVString();
                }
                else if (columns.Length > 0)
                {
                    entry.ColumnNames.Add(columns);
                }
                Entries.Add(entry);
            }
        }
Esempio n. 5
0
        private void cmdTestDB_Click(object sender, EventArgs e)
        {
            if (DoValidate())
            {
                string lastStep          = "Initialize values";
                string columnWarningText = "";
                try
                {
                    WMIQueryCollectorConfigEntry tmpWMIConfig = new WMIQueryCollectorConfigEntry();
                    tmpWMIConfig.Name                = txtName.Text;
                    tmpWMIConfig.Namespace           = txtNamespace.Text;
                    tmpWMIConfig.Machinename         = txtMachines.Text;
                    tmpWMIConfig.StateQuery          = txtStateQuery.Text;
                    tmpWMIConfig.ReturnValueIsInt    = chkIsReturnValueInt.Checked;
                    tmpWMIConfig.ReturnValueInverted = !chkReturnValueNotInverted.Checked;
                    tmpWMIConfig.UseRowCountAsValue  = chkUseRowCountAsValue.Checked;
                    tmpWMIConfig.SuccessValue        = cboSuccessValue.Text;
                    tmpWMIConfig.WarningValue        = cboWarningValue.Text;
                    tmpWMIConfig.ErrorValue          = cboErrorValue.Text;
                    tmpWMIConfig.DetailQuery         = txtDetailQuery.Text;
                    tmpWMIConfig.ColumnNames         = txtColumnNames.Text.ToListFromCSVString();

                    //tmpWMIConfig.KeyColumn = (int)keyColumnNumericUpDown.Value;

                    object returnValue = null;
                    if (tmpWMIConfig.UseRowCountAsValue)
                    {
                        lastStep    = "Run summary query (row count as value)";
                        returnValue = tmpWMIConfig.RunQueryWithCountResult();
                    }
                    else
                    {
                        lastStep = "Run summary query";
                        if (returnValue.IsIntegerTypeNumber())
                        {
                            object currentValue = null;
                            currentValue = tmpWMIConfig.RunQueryWithSingleResult();
                            if (currentValue.IsNumber())
                            {
                                returnValue = (decimal)currentValue;
                            }
                            else
                            {
                                throw new Exception(string.Format("Return value is not an integer!\r\nValue returned: {0}", returnValue));
                            }
                        }
                        else
                        {
                            returnValue = tmpWMIConfig.RunQueryWithSingleResult();
                        }
                    }

                    if (tmpWMIConfig.ReturnValueIsInt)
                    {
                        lastStep = "Test return value is an Integer";
                        if (!returnValue.IsIntegerTypeNumber())
                        {
                            throw new Exception(string.Format("Return value is not an integer!\r\nValue returned: {0}", returnValue));
                        }
                    }
                    //testing detail query
                    lastStep = "Testing detail query - Getting column names";
                    List <DataColumn> columns = tmpWMIConfig.GetDetailQueryColumns();
                    lastStep = "Testing detail query - Custom column name sequence check";
                    StringBuilder sbColumns = new StringBuilder();
                    for (int i = 1; i < columns.Count; i++)
                    {
                        sbColumns.AppendLine(columns[i].ColumnName);
                    }
                    foreach (string columnName in tmpWMIConfig.ColumnNames)
                    {
                        if ((from c in columns
                             where c.ColumnName.ToUpper() == columnName.ToUpper()
                             select c).Count() != 1)
                        {
                            columnWarningText += columnName + ", ";
                        }
                    }
                    if (chkCopyColumnNames.Checked)
                    {
                        Clipboard.SetText(sbColumns.ToString());
                    }

                    lastStep = "Testing detail query";
                    DataSet ds = tmpWMIConfig.RunDetailQuery();
                    if (columnWarningText.Length == 0)
                    {
                        MessageBox.Show(string.Format("Success!\r\nSummary value return: {0}\r\nDetail row count: {1}\r\nDetail columns: {2}", returnValue, ds.Tables[0].Rows.Count, columns.ToCSVString()), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Success (with warning)!\r\nSummary value return: {0}\r\nDetail row count: {1}\r\nDetail columns returned: {2}\r\nColumns not found: {3}", returnValue, ds.Tables[0].Rows.Count, columns.ToCSVString(), columnWarningText), "Test", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Esempio n. 6
0
 public WMIQueryCollectorEditEntry()
 {
     InitializeComponent();
     SelectedEntry = new WMIQueryCollectorConfigEntry();
 }
Esempio n. 7
0
        public void FromXml(string configurationString)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(configurationString);
            Entries.Clear();
            XmlElement root = config.DocumentElement;

            //version 4 type config
            foreach (XmlElement wmiQueryNode in root.SelectNodes("wmiQueries/wmiQuery"))
            {
                WMIQueryCollectorConfigEntry entry = new WMIQueryCollectorConfigEntry();
                entry.Name            = wmiQueryNode.ReadXmlElementAttr("name", entry.Machinename);
                entry.Namespace       = wmiQueryNode.ReadXmlElementAttr("namespace", "root\\CIMV2");
                entry.Machinename     = wmiQueryNode.ReadXmlElementAttr("machineName", ".");
                entry.PrimaryUIValue  = wmiQueryNode.ReadXmlElementAttr("primaryUIValue", false);
                entry.OutputValueUnit = wmiQueryNode.ReadXmlElementAttr("outputValueUnit", "");

                XmlNode stateQueryNode = wmiQueryNode.SelectSingleNode("stateQuery");
                entry.StateQuery = stateQueryNode.ReadXmlElementAttr("syntax", "");
                //entry.ReturnValueIsInt = bool.Parse(stateQueryNode.ReadXmlElementAttr("returnValueIsInt", "True"));
                //entry.ReturnValueInverted = bool.Parse(stateQueryNode.ReadXmlElementAttr("returnValueInverted", "False"));

                if (bool.Parse(stateQueryNode.ReadXmlElementAttr("returnValueInverted", "False")))
                {
                    entry.ReturnCheckSequence = CollectorAgentReturnValueCheckSequence.EWG;
                }
                else
                {
                    entry.ReturnCheckSequence = CollectorAgentReturnValueCheckSequence.GWE;
                }
                entry.GoodResultMatchType    = CollectorAgentReturnValueCompareMatchType.Match;
                entry.WarningResultMatchType = CollectorAgentReturnValueCompareMatchType.Match;
                entry.ErrorResultMatchType   = CollectorAgentReturnValueCompareMatchType.Match;
                entry.WarningValue           = stateQueryNode.ReadXmlElementAttr("warningValue", "0");
                entry.ErrorValue             = stateQueryNode.ReadXmlElementAttr("errorValue", "0");
                entry.GoodValue          = stateQueryNode.ReadXmlElementAttr("successValue", "0");
                entry.UseRowCountAsValue = bool.Parse(stateQueryNode.ReadXmlElementAttr("useRowCountAsValue", "True"));
                XmlNode detailQueryNode = wmiQueryNode.SelectSingleNode("detailQuery");
                entry.DetailQuery = detailQueryNode.ReadXmlElementAttr("syntax", "");
                string columns = detailQueryNode.ReadXmlElementAttr("columnNames", "");
                entry.ColumnNames = new List <string>();
                if (columns.Length > 0 && columns.IndexOf(',') > -1)
                {
                    entry.ColumnNames = columns.ToListFromCSVString();
                }
                else if (columns.Length > 0)
                {
                    entry.ColumnNames.Add(columns);
                }
                Entries.Add(entry);
            }

            //version 5 type config
            foreach (XmlElement carvceEntryNode in root.SelectNodes("carvcesEntries/carvceEntry"))
            {
                XmlNode dataSourceNode             = carvceEntryNode.SelectSingleNode("dataSource");
                WMIQueryCollectorConfigEntry entry = new WMIQueryCollectorConfigEntry();
                entry.Name            = dataSourceNode.ReadXmlElementAttr("name", "");
                entry.Namespace       = dataSourceNode.ReadXmlElementAttr("namespace", "root\\CIMV2");
                entry.Machinename     = dataSourceNode.ReadXmlElementAttr("machineName", ".");
                entry.PrimaryUIValue  = dataSourceNode.ReadXmlElementAttr("primaryUIValue", false);
                entry.OutputValueUnit = dataSourceNode.ReadXmlElementAttr("outputValueUnit", "");

                XmlNode stateQueryNode = dataSourceNode.SelectSingleNode("stateQuery");
                //entry.ReturnValueIsInt = bool.Parse(stateQueryNode.ReadXmlElementAttr("returnValueIsInt", "False"));
                entry.UseRowCountAsValue = bool.Parse(stateQueryNode.ReadXmlElementAttr("useRowCountAsValue", "False"));
                entry.StateQuery         = stateQueryNode.InnerText;

                XmlNode detailQueryNode = dataSourceNode.SelectSingleNode("detailQuery");
                string  columns         = detailQueryNode.ReadXmlElementAttr("columnNames", "");
                entry.ColumnNames = new List <string>();
                if (columns.Length > 0 && columns.IndexOf(',') > -1)
                {
                    entry.ColumnNames = columns.ToListFromCSVString();
                }
                else if (columns.Length > 0)
                {
                    entry.ColumnNames.Add(columns);
                }
                entry.DetailQuery = detailQueryNode.InnerText;

                XmlNode testConditionsNode = carvceEntryNode.SelectSingleNode("testConditions");
                if (testConditionsNode != null)
                {
                    entry.ReturnCheckSequence = CollectorAgentReturnValueCompareEngine.CheckSequenceTypeFromString(testConditionsNode.ReadXmlElementAttr("testSequence", "gwe"));
                    XmlNode goodScriptNode = testConditionsNode.SelectSingleNode("success");
                    entry.GoodResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(goodScriptNode.ReadXmlElementAttr("testType", "match"));
                    entry.GoodValue           = goodScriptNode.InnerText;

                    XmlNode warningScriptNode = testConditionsNode.SelectSingleNode("warning");
                    entry.WarningResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(warningScriptNode.ReadXmlElementAttr("testType", "match"));
                    entry.WarningValue           = warningScriptNode.InnerText;

                    XmlNode errorScriptNode = testConditionsNode.SelectSingleNode("error");
                    entry.ErrorResultMatchType = CollectorAgentReturnValueCompareEngine.MatchTypeFromString(errorScriptNode.ReadXmlElementAttr("testType", "match"));
                    entry.ErrorValue           = errorScriptNode.InnerText;
                }
                else
                {
                    entry.ReturnCheckSequence = CollectorAgentReturnValueCheckSequence.GWE;
                }

                Entries.Add(entry);
            }
        }