예제 #1
0
        public override MonitorState GetCurrentState()
        {
            string         returnedData = "";
            CollectorState agentState   = CollectorState.NotAvailable;

            try
            {
                returnedData = ExecuteCommand();

                CurrentAgentValue = FormatUtils.FormatArrayToString(returnedData, "[null]");
                agentState        = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence,
                                                                                    GoodResultMatchType, GoodValue,
                                                                                    WarningResultMatchType, WarningValue,
                                                                                    ErrorResultMatchType, ErrorValue,
                                                                                    CurrentAgentValue);
            }
            catch (Exception wsException)
            {
                agentState   = CollectorState.Error;
                returnedData = wsException.Message;
            }

            MonitorState currentState = new MonitorState()
            {
                ForAgent         = Description,
                State            = agentState,
                CurrentValue     = returnedData == null ? "N/A" : returnedData,
                CurrentValueUnit = OutputValueUnit
            };

            return(currentState);
        }
예제 #2
0
        public MonitorState GetCurrentState()
        {
            object         wsData     = null;
            CollectorState agentState = CollectorState.NotAvailable;

            try
            {
                wsData = GetValue();

                CurrentAgentValue = FormatUtils.FormatArrayToString(wsData, "[null]");
                agentState        = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence,
                                                                                    GoodResultMatchType, GoodValue,
                                                                                    WarningResultMatchType, WarningValue,
                                                                                    ErrorResultMatchType, ErrorValue,
                                                                                    CurrentAgentValue);
            }
            catch (Exception wsException)
            {
                agentState = CollectorState.Error;
                wsData     = wsException.Message;
            }

            MonitorState currentState = new MonitorState()
            {
                ForAgent         = Description,
                State            = agentState,
                CurrentValue     = wsData == null ? "N/A" : wsData.ToString(),
                CurrentValueUnit = OutputValueUnit
            };

            return(currentState);
        }
        private void cmdTest_Click(object sender, EventArgs e)
        {
            try
            {
                LinuxSSHCommandEntry testEntry = new LinuxSSHCommandEntry()
                {
                    SSHConnection = sshConnectionDetails
                };
                testEntry.CommandString = txtCommandText.Text;

                testEntry.ValueReturnCheckSequence = optEWG.Checked ? CollectorAgentReturnValueCheckSequence.EWG : CollectorAgentReturnValueCheckSequence.GWE;
                testEntry.ValueReturnType          = (SSHCommandValueReturnType)cboReturnType.SelectedIndex;
                testEntry.SuccessMatchType         = (CollectorAgentReturnValueCompareMatchType )cboSuccessMatchType.SelectedIndex;
                testEntry.SuccessValueOrMacro      = txtGoodValueOrMacro.Text;
                testEntry.WarningMatchType         = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
                testEntry.WarningValueOrMacro      = txtWarningValueOrMacro.Text;
                testEntry.ErrorMatchType           = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;
                testEntry.ErrorValueOrMacro        = txtErrorValueOrMacro.Text;

                string         value        = testEntry.ExecuteCommand();
                CollectorState currentState = CollectorAgentReturnValueCompareEngine.GetState(testEntry.ValueReturnCheckSequence, testEntry.SuccessMatchType, testEntry.SuccessValueOrMacro,
                                                                                              testEntry.WarningMatchType, testEntry.WarningValueOrMacro, testEntry.ErrorMatchType, testEntry.ErrorValueOrMacro, value);

                MessageBox.Show(string.Format("Returned state: {0}\r\nOutput: {1}", currentState, value), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
 public CollectorState GetState(string scriptResultText)
 {
     return(CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence,
                                                            GoodResultMatchType, GoodScriptText,
                                                            WarningResultMatchType, WarningScriptText,
                                                            ErrorResultMatchType, ErrorScriptText,
                                                            scriptResultText));
 }
        private void cmdTest_Click(object sender, EventArgs e)
        {
            try
            {
                string commandText      = ApplyConfigVarsOnField(txtCommandText.Text);
                string successText      = ApplyConfigVarsOnField(txtSuccess.Text);
                string warningText      = ApplyConfigVarsOnField(txtWarning.Text);
                string errorText        = ApplyConfigVarsOnField(txtError.Text);
                string connectionString = ApplyConfigVarsOnField(sshConnectionDetails.ConnectionString);
                SSHConnectionDetails sshConnection;
                if (connectionString.Length > 0)
                {
                    sshConnection = SSHConnectionDetails.FromConnectionString(connectionString);
                }
                else
                {
                    sshConnection = sshConnectionDetails.Clone();
                    sshConnection.ComputerName   = ApplyConfigVarsOnField(sshConnection.ComputerName);
                    sshConnection.UserName       = ApplyConfigVarsOnField(sshConnection.UserName);
                    sshConnection.Password       = ApplyConfigVarsOnField(sshConnection.Password);
                    sshConnection.PrivateKeyFile = ApplyConfigVarsOnField(sshConnection.PrivateKeyFile);
                    sshConnection.PassPhrase     = ApplyConfigVarsOnField(sshConnection.PassPhrase);
                    sshConnection.ConnectionName = ApplyConfigVarsOnField(sshConnection.ConnectionName);
                }

                SSHCommandCollectorConfigEntry testEntry = new SSHCommandCollectorConfigEntry()
                {
                    SSHConnection = sshConnection
                };

                testEntry.CommandString          = commandText;
                testEntry.ValueReturnType        = (SSHCommandValueReturnType)cboReturnType.SelectedIndex;
                testEntry.ReturnCheckSequence    = (CollectorAgentReturnValueCheckSequence)cboReturnCheckSequence.SelectedIndex;
                testEntry.GoodResultMatchType    = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex;
                testEntry.GoodValue              = successText;
                testEntry.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
                testEntry.WarningValue           = warningText;
                testEntry.ErrorResultMatchType   = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;
                testEntry.ErrorValue             = errorText;
                testEntry.OutputValueUnit        = cboOutputValueUnit.Text;

                string         value        = testEntry.ExecuteCommand();
                CollectorState currentState = CollectorAgentReturnValueCompareEngine.GetState(testEntry.ReturnCheckSequence,
                                                                                              testEntry.GoodResultMatchType, testEntry.GoodValue,
                                                                                              testEntry.WarningResultMatchType, testEntry.WarningValue,
                                                                                              testEntry.ErrorResultMatchType, testEntry.ErrorValue, value);

                MessageBox.Show(string.Format("Returned state: {0}\r\nOutput: {1}", currentState, value), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
예제 #6
0
        public MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent = Description
            };

            object         wsData     = null;
            CollectorState agentState = CollectorState.NotAvailable;

            try
            {
                wsData = RunMethod();
                if (ValueExpectedReturnType == WebServiceValueExpectedReturnTypeEnum.CheckAvailabilityOnly)
                {
                    agentState = CollectorState.Good;
                }
                else
                {
                    FormatCurrentAgentValue(wsData);
                    agentState = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence,
                                                                                 GoodResultMatchType, GoodScriptText,
                                                                                 WarningResultMatchType, WarningScriptText,
                                                                                 ErrorResultMatchType, ErrorScriptText,
                                                                                 CurrentAgentValue);
                }
            }
            catch (Exception wsException)
            {
                agentState = CollectorState.Error;
                if (wsException.Message.Contains("Method") && wsException.Message.Contains("not found or parameters invalid!"))
                {
                    wsData = "Invalid Method/Parameters!";
                }
                else if (wsException.Message.Contains("Object reference not set to an instance of an object"))
                {
                    wsData = "Object instance not found!";
                }
                else if (wsException.Message.Contains("There was an error downloading"))
                {
                    wsData = "WS down/Invalid URL!";
                }
                else
                {
                    wsData = "WS Error";
                }
                currentState.RawDetails = wsException.Message;
            }

            currentState.State        = agentState;
            currentState.CurrentValue = CurrentAgentValue != null ? CurrentAgentValue : wsData == null ? "N/A" : wsData.ToString();
            return(currentState);
        }
예제 #7
0
        public MonitorState GetCurrentState()
        {
            object value    = RunQuery();
            string unitName = OutputValueUnit;

            if (UseRowCountAsValue && OutputValueUnit.Length == 0)
            {
                unitName = "row(s)";
            }
            MonitorState currentState = new MonitorState()
            {
                State = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence, GoodResultMatchType, GoodValue,
                                                                        WarningResultMatchType, WarningValue, ErrorResultMatchType, ErrorValue, value),
                ForAgent         = Name,
                CurrentValue     = value,
                CurrentValueUnit = unitName
            };

            //object value = null;
            //if (!ReturnValueIsInt)
            //{
            //    value = RunQueryWithSingleResult();
            //}
            //else
            //{
            //    if (UseRowCountAsValue)
            //    {
            //        value = RunQueryWithCountResult();
            //    }
            //    else
            //    {
            //        value = RunQueryWithSingleResult();
            //    }
            //}
            //CurrentAgentValue = value == null ? "[null]" : value;
            //MonitorState currentState = new MonitorState()
            //{
            //    ForAgent = Description,
            //    CurrentValue = value == null ? "[null]" : value,
            //    CurrentValueUnit = OutputValueUnit,
            //    State = GetState(value)
            //};
            if (currentState.State == CollectorState.Error)
            {
                currentState.RawDetails = string.Format("(Trigger '{0}')", ErrorValue);
            }
            else if (currentState.State == CollectorState.Warning)
            {
                currentState.RawDetails = string.Format("(Trigger '{0}')", WarningValue);
            }
            return(currentState);
        }
예제 #8
0
        public MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent = Description
            };

            try
            {
                string scriptResultText = RunScript();
                if (scriptResultText.Contains("System.Management.Automation.CommandNotFoundException"))
                {
                    currentState.State            = CollectorState.Error;
                    currentState.CurrentValue     = "Bad command(s)";
                    currentState.CurrentValueUnit = "";
                    CurrentAgentValue             = "Bad command(s)";
                    currentState.RawDetails       = scriptResultText;
                }
                else if (scriptResultText.Contains("The remote server returned an error: (401) Unauthorized"))
                {
                    currentState.State            = CollectorState.Error;
                    currentState.CurrentValue     = "Unauthorized";
                    currentState.CurrentValueUnit = "";
                    CurrentAgentValue             = "Unauthorized";
                    currentState.RawDetails       = scriptResultText;
                }
                else
                {
                    CurrentAgentValue             = scriptResultText;
                    currentState.CurrentValue     = scriptResultText;
                    currentState.CurrentValueUnit = OutputValueUnit;
                    CollectorState currentScriptState = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence,
                                                                                                        GoodResultMatchType, GoodScriptText,
                                                                                                        WarningResultMatchType, WarningScriptText,
                                                                                                        ErrorResultMatchType, ErrorScriptText,
                                                                                                        scriptResultText);
                    currentState.State = currentScriptState;
                }
            }
            catch (Exception ex)
            {
                currentState.State            = CollectorState.Error;
                currentState.CurrentValue     = "Unknown error";
                currentState.CurrentValueUnit = "";
                currentState.RawDetails       = ex.Message;
            }

            return(currentState);
        }
예제 #9
0
        public MonitorState GetCurrentState()
        {
            object       value        = GetStateQueryValue();
            string       unitName     = ValueReturnType == DataBaseQueryValueReturnType.RowCount ? "row(s)" : ValueReturnType == DataBaseQueryValueReturnType.QueryTime ? "ms" : OutputValueUnit;
            MonitorState currentState = new MonitorState()
            {
                State = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence, GoodResultMatchType, GoodValue,
                                                                        WarningResultMatchType, WarningValue, ErrorResultMatchType, ErrorValue, value),
                ForAgent         = Name,
                CurrentValue     = value,
                CurrentValueUnit = unitName
            };

            return(currentState);
        }
예제 #10
0
        public MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent = Name
            };

            try
            {
                object value    = RunQuery();
                string unitName = OutputValueUnit;
                if (UseRowCountAsValue && OutputValueUnit.Length == 0)
                {
                    unitName = "row(s)";
                }
                currentState.State = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence, GoodResultMatchType, GoodValue,
                                                                                     WarningResultMatchType, WarningValue, ErrorResultMatchType, ErrorValue, value);
                currentState.CurrentValue     = value;
                currentState.CurrentValueUnit = unitName;
                if (currentState.State == CollectorState.Error)
                {
                    currentState.RawDetails = string.Format("(Trigger '{0}')", ErrorValue);
                }
                else if (currentState.State == CollectorState.Warning)
                {
                    currentState.RawDetails = string.Format("(Trigger '{0}')", WarningValue);
                }
            }
            catch (Exception ex)
            {
                currentState.State      = CollectorState.Error;
                currentState.RawDetails = ex.Message;
                if (ex.Message.Contains("Invalid class"))
                {
                    currentState.CurrentValue = "Invalid class";
                }
                else if (ex.Message.Contains("Invalid query"))
                {
                    currentState.CurrentValue = "Invalid query";
                }
            }
            return(currentState);
        }
        public MonitorState GetCurrentState()
        {
            string scriptResultText = RunScript();

            CurrentAgentValue = scriptResultText;
            MonitorState currentState = new MonitorState()
            {
                ForAgent     = Description,
                CurrentValue = scriptResultText
            };
            CollectorState currentScriptState = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence,
                                                                                                GoodResultMatchType, GoodScriptText,
                                                                                                WarningResultMatchType, WarningScriptText,
                                                                                                ErrorResultMatchType, ErrorScriptText,
                                                                                                scriptResultText);

            currentState.State = currentScriptState;

            return(currentState);
        }
예제 #12
0
        public MonitorState GetCurrentState()
        {
            object         wsData     = null;
            CollectorState agentState = CollectorState.NotAvailable;

            try
            {
                wsData = RunMethod();
                if (ValueExpectedReturnType == WebServiceValueExpectedReturnTypeEnum.CheckAvailabilityOnly)
                {
                    agentState = CollectorState.Good;
                }
                else
                {
                    FormatCurrentAgentValue(wsData);
                    agentState = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence,
                                                                                 GoodResultMatchType, GoodScriptText,
                                                                                 WarningResultMatchType, WarningScriptText,
                                                                                 ErrorResultMatchType, ErrorScriptText,
                                                                                 CurrentAgentValue);
                }
            }
            catch (Exception wsException)
            {
                agentState = CollectorState.Error;
                wsData     = wsException.Message;
            }

            MonitorState currentState = new MonitorState()
            {
                ForAgent     = Description,
                State        = agentState,
                CurrentValue = wsData == null ? "N/A" : wsData.ToString()
            };

            return(currentState);
        }
예제 #13
0
        public override MonitorState RefreshState()
        {
            MonitorState returnState = new MonitorState();
            string       lastAction  = "";
            int          errors      = 0;
            int          warnings    = 0;
            int          success     = 0;
            double       sumValue    = 0;

            try
            {
                LinuxSSHCommandCollectorConfig currentConfig = (LinuxSSHCommandCollectorConfig)AgentConfig;
                returnState.CurrentValue = null;
                foreach (LinuxSSHCommandEntry entry in currentConfig.Entries)
                {
                    string         value        = entry.ExecuteCommand();
                    CollectorState currentState = CollectorAgentReturnValueCompareEngine.GetState(entry.ValueReturnCheckSequence, entry.SuccessMatchType, entry.SuccessValueOrMacro,
                                                                                                  entry.WarningMatchType, entry.WarningValueOrMacro, entry.ErrorMatchType, entry.ErrorValueOrMacro, value);
                    if (value.IsNumber())
                    {
                        sumValue += Double.Parse(value.ToString());
                    }

                    if (currentState == CollectorState.Error)
                    {
                        errors++;
                    }
                    else if (currentState == CollectorState.Warning)
                    {
                        warnings++;
                    }
                    else
                    {
                        success++;
                    }
                    returnState.ChildStates.Add(
                        new MonitorState()
                    {
                        ForAgent         = entry.Name,
                        State            = currentState,
                        CurrentValue     = value.ToString(),
                        CurrentValueUnit = ""
                    });
                }
                if (sumValue > 0)
                {
                    returnState.CurrentValue = sumValue;
                }

                if (errors > 0 && warnings == 0 && success == 0) // any errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (errors > 0 || warnings > 0) //any warnings
                {
                    returnState.State = CollectorState.Warning;
                }
                else
                {
                    returnState.State = CollectorState.Good;
                }
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = ex.Message;
                returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message);
                returnState.State       = CollectorState.Error;
            }
            return(returnState);
        }
예제 #14
0
        public MonitorState GetCurrentState()
        {
            object         wsData     = null;
            CollectorState agentState = CollectorState.NotAvailable;

            try
            {
                wsData = GetValue();
                //if (ReturnValueIsNumber && !wsData.IsNumber())
                //{
                //    agentState = CollectorState.Error;
                //    wsData = "Returned value is not a number! (" + wsData.ToString() + ")";
                //}
                //else
                //{
                CurrentAgentValue = FormatUtils.FormatArrayToString(wsData, "[null]");
                agentState        = CollectorAgentReturnValueCompareEngine.GetState(ReturnCheckSequence,
                                                                                    GoodResultMatchType, GoodValue,
                                                                                    WarningResultMatchType, WarningValue,
                                                                                    ErrorResultMatchType, ErrorValue,
                                                                                    CurrentAgentValue);
                //}
            }
            catch (Exception wsException)
            {
                agentState = CollectorState.Error;
                wsData     = wsException.Message;
            }

            MonitorState currentState = new MonitorState()
            {
                ForAgent         = Description,
                State            = agentState,
                CurrentValue     = wsData == null ? "N/A" : wsData.ToString(),
                CurrentValueUnit = OutputValueUnit
            };

            return(currentState);

            //object value = GetValue();
            //CurrentAgentValue = value;
            //MonitorState currentState = new MonitorState()
            //{
            //    ForAgent = Name,
            //    CurrentValue = FormatUtils.FormatArrayToString(value, "[null]"),
            //    State = EvaluateValue(value)
            //};

            //if (currentState.State == CollectorState.Error)
            //{
            //    currentState.RawDetails = string.Format("'{0}' - value '{1}' - Error (trigger {2})", Name, FormatUtils.FormatArrayToString(value, "[null]"), ErrorValue);
            //    currentState.HtmlDetails = string.Format("'{0}' - value '{1}' - <b>Error</b> (trigger {2})", Name, FormatUtils.FormatArrayToString(value, "[null]"), ErrorValue);
            //}
            //else if (currentState.State == CollectorState.Warning)
            //{
            //    currentState.RawDetails = string.Format("'{0}' - value '{1}' - Warning (trigger {2})", Name, FormatUtils.FormatArrayToString(value, "[null]"), WarningValue);
            //    currentState.HtmlDetails = string.Format("'{0}' - value '{1}' - <b>Warning</b> (trigger {2})", Name, FormatUtils.FormatArrayToString(value, "[null]"), WarningValue);
            //}
            //else
            //{
            //    currentState.RawDetails = string.Format("'{0}' - value '{1}'", Name, FormatUtils.FormatArrayToString(value, "[null]"));
            //    currentState.HtmlDetails = string.Format("'{0}' - value '{1}'", Name, FormatUtils.FormatArrayToString(value, "[null]"));
            //}

            //return currentState;
        }
예제 #15
0
        public override MonitorState RefreshState()
        {
            MonitorState returnState = new MonitorState();
            string       lastAction  = "";
            int          errors      = 0;
            int          warnings    = 0;
            int          success     = 0;

            try
            {
                SqlQueryCollectorConfig currentConfig = (SqlQueryCollectorConfig)AgentConfig;

                returnState.RawDetails   = string.Format("Running {0} queries", currentConfig.Entries.Count);
                returnState.HtmlDetails  = string.Format("<b>Running {0} queries</b>", currentConfig.Entries.Count);
                returnState.CurrentValue = 0;
                foreach (SqlQueryCollectorEntry entry in currentConfig.Entries)
                {
                    object         value        = entry.GetStateQueryValue();
                    CollectorState currentState = CollectorAgentReturnValueCompareEngine.GetState(entry.ValueReturnCheckSequence, entry.SuccessMatchType, entry.SuccessValueOrMacro,
                                                                                                  entry.WarningMatchType, entry.WarningValueOrMacro, entry.ErrorMatchType, entry.ErrorValueOrMacro, value);
                    if (value.IsNumber())
                    {
                        returnState.CurrentValue = Double.Parse(returnState.CurrentValue.ToString()) + Double.Parse(value.ToString());
                    }
                    if (currentState == CollectorState.Error)
                    {
                        errors++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            State        = CollectorState.Error,
                            ForAgent     = entry.Name,
                            CurrentValue = value //,
                                                 //RawDetails = string.Format("(Trigger '{0}')", entry.TriggerSummary)
                        });
                    }
                    else if (currentState == CollectorState.Warning)
                    {
                        warnings++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            State        = CollectorState.Warning,
                            ForAgent     = entry.Name,
                            CurrentValue = value //,
                                                 //RawDetails = string.Format("(Trigger '{0}')", entry.TriggerSummary)
                        });
                    }
                    else
                    {
                        success++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            State        = CollectorState.Good,
                            ForAgent     = entry.Name,
                            CurrentValue = value
                        });
                    }
                }

                if (errors > 0 && warnings == 0 && success == 0) // any errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (errors > 0 || warnings > 0) //any warnings
                {
                    returnState.State = CollectorState.Warning;
                }
                else
                {
                    returnState.State = CollectorState.Good;
                }
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = ex.Message;
                returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message);
                returnState.State       = CollectorState.Error;
            }
            return(returnState);
        }