public override void RefreshDisplayData()
        {
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
            lvwEntries.BeginUpdate();
            foreach (ListViewItem itmX in lvwEntries.Items)
            {
                DynamicWSCollectorConfigEntry entry = (DynamicWSCollectorConfigEntry)itmX.Tag;
                try
                {
                    object obj = entry.RunMethod();

                    CollectorState state = entry.GetState(obj);
                    itmX.SubItems[1].Text = entry.LastFormattedValue;
                    if (state == CollectorState.Good)
                    {
                        itmX.ImageIndex = 0;
                        itmX.BackColor  = SystemColors.Window;
                    }
                    else
                    {
                        itmX.ImageIndex = 2;
                        itmX.BackColor  = Color.Salmon;
                    }
                }
                catch (Exception ex)
                {
                    itmX.SubItems[1].Text = ex.Message;
                    itmX.ImageIndex       = 2;
                    itmX.BackColor        = Color.Salmon;
                }
            }
            lvwEntries.EndUpdate();
            System.Windows.Forms.Cursor.Current = Cursors.Default;
            toolStripStatusLabelDetails.Text    = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
Beispiel #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);
        }
Beispiel #3
0
        public CollectorState GetState(float value)
        {
            CollectorState state = CollectorState.Good;

            if (!ReturnValueInverted)
            {
                if (ErrorValue <= value)
                {
                    state = CollectorState.Error;
                }
                else if (WarningValue <= value)
                {
                    state = CollectorState.Warning;
                }
            }
            else
            {
                if (ErrorValue >= value)
                {
                    state = CollectorState.Error;
                }
                else if (WarningValue >= value)
                {
                    state = CollectorState.Warning;
                }
            }
            return(state);
        }
Beispiel #4
0
        public CollectorState GetState(double value)
        {
            CollectorState state = CollectorState.Good;

            if (WarningValue < ErrorValue)
            {
                if (ErrorValue <= value)
                {
                    state = CollectorState.Error;
                }
                else if (WarningValue <= value)
                {
                    state = CollectorState.Warning;
                }
            }
            else
            {
                if (ErrorValue >= value)
                {
                    state = CollectorState.Error;
                }
                else if (WarningValue >= value)
                {
                    state = CollectorState.Warning;
                }
            }
            return(state);
        }
        public CollectorState GetState(PingCollectorResult pingResult)
        {
            CollectorState result = CollectorState.Good;

            if (pingResult.PingTime > -1)//  pingResult.Success)
            {
                if (pingResult.PingTime > TimeOutMS)
                {
                    result = CollectorState.Error;
                    pingResult.ResponseDetails = string.Format("Operation timed out! Max time allowed: {0}ms, {1}", TimeOutMS, pingResult.ResponseDetails);
                }
                else if (pingResult.PingTime > MaxTimeMS)
                {
                    result = CollectorState.Warning;
                    pingResult.ResponseDetails = string.Format("Operation did not finished in allowed time! Excepted time: {0}ms, {1}", MaxTimeMS, pingResult.ResponseDetails);
                }
                else
                {
                    result = CollectorState.Good;
                }
            }
            else
            {
                result = CollectorState.Error;
            }
            return(result);
        }
Beispiel #6
0
 public override void RefreshDisplayData()
 {
     try
     {
         CollectorState currentState = ((LoopbackCollector)Collector).GetState().State;
         lblDisplayedState.Text = currentState.ToString() + " - " + DateTime.Now.ToString("HH:mm:ss");
         if (currentState == CollectorState.Error)
         {
             lblDisplayedState.BackColor = Color.LightSalmon;
         }
         else if (currentState == CollectorState.Warning)
         {
             lblDisplayedState.BackColor = Color.Yellow;
         }
         else if (currentState == CollectorState.Good)
         {
             lblDisplayedState.BackColor = Color.LightGreen;
         }
         else
         {
             lblDisplayedState.BackColor = Color.Silver;
         }
     }
     catch (Exception ex)
     {
         lblDisplayedState.BackColor = Color.LightSalmon;
         lblDisplayedState.Text      = ex.Message + " - " + DateTime.Now.ToString("HH:mm:ss");
     }
 }
Beispiel #7
0
        private string GetQIValue(ListViewItem lvi, DirectoryServicesQueryCollectorConfigEntry dsQueryEntry)
        {
            string results = "";

            try
            {
                object         value        = dsQueryEntry.RunQuery();
                CollectorState currentstate = dsQueryEntry.GetState(value);

                results = FormatUtils.N(value, "[null]");
                if (currentstate == CollectorState.Error)
                {
                    lvi.ImageIndex = 3;
                }
                else if (currentstate == CollectorState.Warning)
                {
                    lvi.ImageIndex = 2;
                }
                else
                {
                    lvi.ImageIndex = 1;
                }
            }
            catch (Exception ex)
            {
                results = ex.Message;
            }
            return(results);
        }
Beispiel #8
0
        private CollectorState GetState(List <ServiceStateInfo> list)
        {
            CollectorState result          = CollectorState.Good;
            int            runningCount    = 0;
            int            notRunningCount = 0;

            foreach (var entry in list)
            {
                if (entry.Status == ServiceControllerStatus.Running)
                {
                    runningCount++;
                }
                else
                {
                    notRunningCount++;
                }
            }
            if (list.Count > 0)
            {
                if (runningCount > 0 && notRunningCount > 0)
                {
                    result = CollectorState.Warning;
                }
                else if (runningCount == 0 && notRunningCount > 0)
                {
                    result = CollectorState.Error;
                }
            }
            else
            {
                result = CollectorState.NotAvailable;
            }

            return(result);
        }
        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 override void RefreshDisplayData()
 {
     try
     {
         System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
         lvwEntries.BeginUpdate();
         foreach (ListViewItem itmX in lvwEntries.Items)
         {
             PingCollectorHostEntry host = (PingCollectorHostEntry)itmX.Tag;
             try
             {
                 PingCollectorResult pingResult = host.Ping();
                 CollectorState      result     = host.GetState(pingResult);
                 if (pingResult.Success)
                 {
                     itmX.SubItems[1].Text = pingResult.PingTime.ToString() + " ms";
                     itmX.SubItems[2].Text = pingResult.ResponseDetails;
                     if (result == CollectorState.Good)
                     {
                         itmX.ImageIndex = 0;
                         itmX.BackColor  = SystemColors.Window;
                     }
                     else if (result == CollectorState.Warning)
                     {
                         itmX.ImageIndex = 1;
                         itmX.BackColor  = Color.SandyBrown;
                     }
                     else
                     {
                         itmX.ImageIndex = 2;
                         itmX.BackColor  = Color.Salmon;
                     }
                 }
                 else
                 {
                     itmX.ImageIndex = 2;
                     itmX.BackColor  = Color.Salmon;
                     if (pingResult.PingTime < 0)
                     {
                         itmX.SubItems[1].Text = "Err";
                     }
                     itmX.SubItems[2].Text = pingResult.ResponseDetails;
                 }
             }
             catch (Exception ex)
             {
                 itmX.ImageIndex       = 2;
                 itmX.SubItems[1].Text = "Err";
                 itmX.SubItems[2].Text = ex.Message;
                 itmX.BackColor        = Color.Salmon;
             }
         }
         lvwEntries.EndUpdate();
         System.Windows.Forms.Cursor.Current = Cursors.Default;
         toolStripStatusLabelDetails.Text    = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
     }
     finally
     {
     }
 }
Beispiel #11
0
        public static ReturnTypes T(CollectorState state)
        {
            switch (state)
            {
            case CollectorState.OK:
                return(ReturnTypes.rtOK);

            case CollectorState.UNITIALIZED:
                return(ReturnTypes.rtErrorInitializeFirst);

            case CollectorState.WAIT_MORE:
                return(ReturnTypes.rtWaitMore);

            case CollectorState.NO_DATA:
                return(ReturnTypes.rtNoData);

            case CollectorState.BUSY:
                return(ReturnTypes.rtErrorBusy);

            case CollectorState.DECRYPT_ALL:
                return(ReturnTypes.rtDecryptAll);

            case CollectorState.DECRYPT_LIST:
                return(ReturnTypes.rtDecryptList);

            default:
                return(ReturnTypes.rtErrorUnknown);
            }
        }
        private string GetQIValue(ListViewItem lvi, OLEDBQueryInstance queryInstance)
        {
            string results = "";

            try
            {
                object         value        = queryInstance.RunQuery();
                CollectorState currentstate = queryInstance.GetState(value);

                results = FormatUtils.N(value, "[null]");
                if (currentstate == CollectorState.Error)
                {
                    lvi.ImageIndex = 3;
                }
                else if (currentstate == CollectorState.Warning)
                {
                    lvi.ImageIndex = 2;
                }
                else
                {
                    lvi.ImageIndex = 1;
                }
            }
            catch (Exception ex)
            {
                results = ex.Message;
            }
            return(results);
        }
Beispiel #13
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);
        }
        private void cmdTest_Click(object sender, EventArgs e)
        {
            if (DoValidate())
            {
                string lastStep = "Initialize values";
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    RegistryQueryCollectorConfigEntry testQueryInstance = new RegistryQueryCollectorConfigEntry();
                    testQueryInstance.Name                   = txtName.Text;
                    testQueryInstance.UseRemoteServer        = chkUseRemoteServer.Checked;
                    testQueryInstance.Server                 = txtServer.Text;
                    testQueryInstance.Path                   = txtPath.Text;
                    testQueryInstance.KeyName                = txtKey.Text;
                    testQueryInstance.ExpandEnvironmentNames = chkExpandEnvNames.Checked;
                    testQueryInstance.RegistryHive           = RegistryQueryCollectorConfigEntry.GetRegistryHiveFromString(cboRegistryHive.Text);

                    if (!chkValueIsANumber.Checked)
                    {
                        testQueryInstance.ReturnValueIsNumber = false;
                        testQueryInstance.ReturnValueInARange = false;
                        testQueryInstance.ReturnValueInverted = false;
                    }
                    else
                    {
                        testQueryInstance.ReturnValueIsNumber = true;
                        testQueryInstance.ReturnValueInARange = chkValueIsInARange.Checked;
                        testQueryInstance.ReturnValueInverted = !chkReturnValueNotInverted.Checked;
                    }

                    testQueryInstance.SuccessValue = cboSuccessValue.Text;
                    testQueryInstance.WarningValue = cboWarningValue.Text;
                    testQueryInstance.ErrorValue   = cboErrorValue.Text;

                    object returnValue = null;
                    returnValue = testQueryInstance.GetValue();
                    CollectorState state = testQueryInstance.EvaluateValue(returnValue);
                    if (state == CollectorState.Good)
                    {
                        MessageBox.Show(string.Format("Success!\r\nValue return: {0}", FormatUtils.FormatArrayToString(returnValue)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (state == CollectorState.Warning)
                    {
                        MessageBox.Show(string.Format("Warning!\r\nValue return: {0}", FormatUtils.FormatArrayToString(returnValue)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Error!\r\nValue return: {0}", FormatUtils.FormatArrayToString(returnValue)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
        }
        public CollectorState GetState(PingCollectorResult pingResult)
        {
            CollectorState result = CollectorState.Good;

            if (pingResult.PingTime > -1)
            {
                if (pingResult.PingTime > TimeOutMS)
                {
                    result = CollectorState.Error;
                    pingResult.ResponseDetails = string.Format("Operation timed out! Max time allowed: {0}ms, {1}", TimeOutMS, pingResult.ResponseDetails);
                }
                else if (pingResult.PingTime > MaxTimeMS)
                {
                    result = CollectorState.Warning;
                    pingResult.ResponseDetails = string.Format("Operation did not finished in allowed time! Excepted time: {0}ms, {1}", MaxTimeMS, pingResult.ResponseDetails);
                }
                else if (pingType == PingCollectorType.HTTP && HTMLContentContain != null && pingResult.ResponseContent.Trim().Length > 0 && HTMLContentContain.Trim().Length > 0 && !pingResult.ResponseContent.Contains(HTMLContentContain))
                {
                    result = CollectorState.Warning;
                    pingResult.ResponseDetails = string.Format("The returned HTML does not contain the specified string '{0}'", HTMLContentContain);
                }
                else
                {
                    result = CollectorState.Good;
                }
            }
            else
            {
                result = CollectorState.Error;
            }
            return(result);
        }
Beispiel #16
0
        private void cmdRunScript_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                PowerShellScriptRunnerEntry testEntry = new PowerShellScriptRunnerEntry();
                testEntry.Name = txtName.Text;
                testEntry.ReturnCheckSequence    = optGWE.Checked ? CollectorAgentReturnValueCheckSequence.GWE : CollectorAgentReturnValueCheckSequence.EWG;
                testEntry.TestScript             = txtScript.Text;
                testEntry.GoodScriptText         = txtSuccess.Text;
                testEntry.GoodResultMatchType    = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex;
                testEntry.WarningScriptText      = txtWarning.Text;
                testEntry.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex;
                testEntry.ErrorScriptText        = txtError.Text;
                testEntry.ErrorResultMatchType   = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex;

                string         scriptResult = testEntry.RunScript();
                CollectorState state        = testEntry.GetState(scriptResult);

                MessageBox.Show(scriptResult, "Test script", MessageBoxButtons.OK, state == CollectorState.Good ? MessageBoxIcon.Information : state == CollectorState.Warning ? MessageBoxIcon.Warning : MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.Message, "Run script", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Beispiel #17
0
        public CollectorState GetState(List <IISAppPoolStateInfo> list)
        {
            CollectorState result          = CollectorState.Good;
            int            runningCount    = 0;
            int            notRunningCount = 0;

            foreach (var entry in list)
            {
                if (entry.Status == AppPoolStatus.Started)
                {
                    runningCount++;
                }
                else
                {
                    notRunningCount++;
                }
            }
            if (list.Count > 0)
            {
                if (runningCount > 0 && notRunningCount > 0)
                {
                    result = CollectorState.Warning;
                }
                else if (runningCount == 0 && notRunningCount > 0)
                {
                    result = CollectorState.Error;
                }
            }
            else
            {
                result = CollectorState.NotAvailable;
            }

            return(result);
        }
        private CollectorState GetState(float value)
        {
            CollectorState state = CollectorState.Good;

            if (WarningValue < ErrorValue)
            {
                if (ErrorValue <= value)
                {
                    state = CollectorState.Error;
                }
                else if (WarningValue <= value)
                {
                    state = CollectorState.Warning;
                }
            }
            else
            {
                if (ErrorValue >= value)
                {
                    state = CollectorState.Error;
                }
                else if (WarningValue >= value)
                {
                    state = CollectorState.Warning;
                }
            }
            return(state);
        }
Beispiel #19
0
        public ReturnTypes IsReady()
        {
            log.Info("IsReady called");
            CollectorState res = collectorService.IsReady();

            log.InfoFormat("result {0}", res);
            return(T(res));
        }
 public void InitializeInstance()
 {
     this.CurrentState = CollectorState.MenuBuilded;
       this.ContextMenu = new Dictionary<Instance, ToolStripItem>();
       this.IsUnderConstruction = false;
       TrayPluginEvents.ContextMenuEntryConstructed += this.OnMenuEntryConstructed;
       TrayPluginEvents.ContextMenuConstructed += this.OnContextMenuConstructed;
 }
Beispiel #21
0
        public ReturnTypes ShowFileView()
        {
            log.Info("Called ShowFileView");

            CollectorState res = collectorService.ShowFileView();

            log.Info("result" + res);
            return(T(res));
        }
        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);
            }
        }
Beispiel #23
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);
        }
Beispiel #24
0
 internal CollectorState GetState(object value)
 {
     CollectorState currentState = CollectorState.Good;
     if (value == DBNull.Value)
     {
         if (ErrorValue == "[null]")
             currentState = CollectorState.Error;
         else if (WarningValue == "[null]")
             currentState = CollectorState.Warning;
     }
     else //non null value
     {
         if (!ReturnValueIsNumber)
         {
             if (value.ToString() == ErrorValue)
                 currentState = CollectorState.Error;
             else if (value.ToString() == WarningValue)
                 currentState = CollectorState.Warning;
             else if (value.ToString() == SuccessValue || SuccessValue == "[any]")
                 currentState = CollectorState.Good; //just to flag condition
             else if (WarningValue == "[any]")
                 currentState = CollectorState.Warning;
             else if (ErrorValue == "[any]")
                 currentState = CollectorState.Error;
         }
         else //now we know the value is not null and must be in a range
         {
             if (!value.IsNumber()) //value must be a number!
             {
                 currentState = CollectorState.Error;
             }
             else if (ErrorValue != "[any]" && ErrorValue != "[null]" &&
                     (
                      (!ReturnValueInverted && double.Parse(value.ToString()) >= double.Parse(ErrorValue)) ||
                      (ReturnValueInverted && double.Parse(value.ToString()) <= double.Parse(ErrorValue))
                     )
                 )
             {
                 currentState = CollectorState.Error;
             }
             else if (WarningValue != "[any]" && WarningValue != "[null]" &&
                    (
                     (!ReturnValueInverted && double.Parse(value.ToString()) >= double.Parse(WarningValue)) ||
                     (ReturnValueInverted && double.Parse(value.ToString()) <= double.Parse(WarningValue))
                    )
                 )
             {
                 currentState = CollectorState.Warning;
             }
         }
     }
     return currentState;
 }
Beispiel #25
0
        /// <summary>
        /// Extends the amount of post shown.
        /// </summary>
        /// <param name="extendCount"></param>
        public void ExtendCollection(int extendCount = 50)
        {
            // #todo #bug If we are refreshing we will grab 50 new post but listeners might already have 100
            // we need to indicate to them they should remove the rest of the posts that are old.
            lock (m_listHelper)
            {
                if (m_state == CollectorState.Updating || m_state == CollectorState.Extending)
                {
                    return;
                }

                // Otherwise do the extension
                m_state = CollectorState.Extending;
            }

            // Fire this not under lock
            FireStateChanged();

            // Kick off a new task to get the posts
            Task.Run(async() =>
            {
                try
                {
                    int previousCollectionSize = GetCurrentPostsInternal().Count;

                    // Get the next elements
                    // #todo make this lower when we have endless scrolling.
                    List <T> posts = ParseElementList(await m_listHelper.FetchNext(extendCount));

                    // Fire the notification that the list has updated.
                    FireCollectionUpdated(previousCollectionSize, posts, false, false);

                    // Update the state
                    lock (m_listHelper)
                    {
                        m_state = CollectorState.Idle;
                    }
                    FireStateChanged();
                }
                catch (Exception e)
                {
                    m_baconMan.MessageMan.DebugDia("Subreddit extension failed", e);

                    // Update the state
                    lock (m_listHelper)
                    {
                        m_state = CollectorState.Error;
                    }
                    FireStateChanged();
                }
            });
        }
        public CollectorState GetState(DirectoryFileInfo fileInfo)
        {
            CollectorState returnState = CollectorState.Good;

            LastErrorMsg = "";
            if (!fileInfo.Exists)
            {
                returnState  = CollectorState.Error;
                LastErrorMsg = string.Format("Directory '{0}' not found or not accessible!", DirectoryPath);
            }
            else if (DirectoryExistOnly)
            {
                returnState = CollectorState.Good;
            }
            else if (fileInfo.FileCount == -1)
            {
                returnState  = CollectorState.Error;
                LastErrorMsg = string.Format("An error occured while accessing '{0}'\r\n\t{1}", FilterFullPath, LastErrorMsg);
            }
            else if (ErrorOnFilesExist)
            {
                returnState = fileInfo.FileCount > 0 ? CollectorState.Error : CollectorState.Good;
            }
            else if (FilesExistOnly)
            {
                returnState = fileInfo.FileCount > 0 ? CollectorState.Good : CollectorState.Error;
            }
            else
            {
                if (
                    (CountErrorIndicator > 0 && CountErrorIndicator <= fileInfo.FileCount) ||
                    (SizeKBErrorIndicator > 0 && SizeKBErrorIndicator * 1024 <= fileInfo.FileSize)
                    )
                {
                    returnState  = CollectorState.Error;
                    LastErrorMsg = string.Format("Error state reached for '{0}': {1} file(s), {2}", FilterFullPath, fileInfo.FileCount, FormatUtils.FormatFileSize(fileInfo.FileSize));
                }
                else if (
                    (CountWarningIndicator > 0 && CountWarningIndicator <= fileInfo.FileCount) ||
                    (SizeKBWarningIndicator > 0 && SizeKBWarningIndicator * 1024 <= fileInfo.FileSize)
                    )
                {
                    returnState  = CollectorState.Warning;
                    LastErrorMsg = string.Format("Warning state reached for '{0}': {1} file(s), {2}", FilterFullPath, fileInfo.FileCount, FormatUtils.FormatFileSize(fileInfo.FileSize));
                }
                else
                {
                    returnState = CollectorState.Good;
                }
            }
            return(returnState);
        }
Beispiel #27
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);
        }
Beispiel #28
0
        public ReturnTypes AddFile(FileInfoStruct fileInfo)
        {
            log.Info("Add file called");
            BioFileInfo bioFileInfo = new BioFileInfo()
            {
                Filename   = fileInfo.Filename,
                FileNumber = fileInfo.FileNumber,
                FileSize   = fileInfo.FileSize,
                Timestamp  = fileInfo.ModificationDate,
                PathType   = fileInfo.type == FileEntityTypes.FOLDER ? BioFileInfo.EntityAtPathType.Folder : BioFileInfo.EntityAtPathType.Regular
            };
            CollectorState res = collectorService.AddFile(bioFileInfo);

            return(T(res));
        }
Beispiel #29
0
        public CollectorState GetState(MemInfo mi)
        {
            CollectorState state = CollectorState.Good;

            if (ErrorValue >= GetMonitoredValue(mi))
            {
                state = CollectorState.Error;
            }
            else if (WarningValue >= GetMonitoredValue(mi))
            {
                state = CollectorState.Warning;
            }

            return(state);
        }
Beispiel #30
0
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent         = Description,
                State            = CollectorState.Good,
                CurrentValueUnit = "%"
            };

            try
            {
                Renci.SshNet.SshClient sshConnection = SSHConnection.GetConnection();
                List <CPUInfo>         cpuInfos      = CPUInfo.GetCurrentCPUPerc(sshConnection, MSSampleDelay);
                SSHConnection.CloseConnection();
                currentState.State = CollectorState.NotAvailable;
                if (cpuInfos.Count > 0)
                {
                    currentState.CurrentValue = cpuInfos[0].CPUPerc.ToString("0.0");
                    currentState.State        = GetState(cpuInfos[0].CPUPerc);
                }

                for (int i = 1; i < cpuInfos.Count; i++)
                {
                    CollectorState currentCPUState = GetState(cpuInfos[i].CPUPerc);
                    if ((int)currentCPUState > (int)currentState.State && !UseOnlyTotalCPUvalue)
                    {
                        currentState.CurrentValue = cpuInfos[i].CPUPerc.ToString("0.0");
                        currentState.State        = currentCPUState;
                    }
                    MonitorState cpuState = new MonitorState()
                    {
                        ForAgent         = cpuInfos[i].Name,
                        State            = currentCPUState,
                        CurrentValue     = cpuInfos[i].CPUPerc.ToString("0.0"),
                        CurrentValueUnit = "%"
                    };
                    currentState.ChildStates.Add(cpuState);
                }
            }
            catch (Exception wsException)
            {
                currentState.State      = CollectorState.Error;
                currentState.RawDetails = wsException.Message;
            }

            return(currentState);
        }
        private void cmdTestService_Click(object sender, EventArgs e)
        {
            if (txtServiceURL.Text.Trim().Length > 0)
            {
                string lastStep = "Creating entry";
                try
                {
                    DynamicWSCollectorConfigEntry textEntry = new DynamicWSCollectorConfigEntry();
                    textEntry.ServiceBaseURL     = txtServiceURL.Text;
                    textEntry.ServiceBindingName = cboEndPoint.Text;
                    textEntry.MethodName         = cboMethodName.Text;
                    textEntry.ParametersFromString(txtParameters.Text);
                    textEntry.ResultIsSuccess         = !chkResultXOr.Checked;
                    textEntry.ValueExpectedReturnType = (WebServiceValueExpectedReturnTypeEnum)cboExpectedValueType.SelectedIndex;
                    if (cboValueFormatMacro.SelectedIndex == -1 || !(cboValueFormatMacro.SelectedItem is ValueFormatMacroDisplay))
                    {
                        textEntry.MacroFormatType = WebServiceMacroFormatTypeEnum.None;
                    }
                    else
                    {
                        textEntry.MacroFormatType = ((ValueFormatMacroDisplay)cboValueFormatMacro.SelectedItem).MacroFormatType;
                    }
                    textEntry.CheckValueArrayIndex  = (int)indexOrRowNumericUpDown.Value;
                    textEntry.CheckValueColumnIndex = (int)dataSetColumnNumericUpDown.Value;
                    textEntry.CheckValueOrMacro     = cboValueOrMacro.Text;
                    textEntry.UseRegEx = chkUseRegEx.Checked;

                    lastStep = "Running method";
                    object returnValue = textEntry.RunMethod();
                    lastStep = "Evaluating return value";
                    CollectorState state = textEntry.GetState(returnValue);
                    MessageBox.Show("Returned state: " + state.ToString() + "\r\nValue: " + textEntry.LastFormattedValue, "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Specified web service invalid or not available"))
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Last step: " + lastStep + "\r\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Beispiel #32
0
 private void SetState(CollectorState state) {
     this.State = state;
     if (this.StateChanged != null)
         StateChanged(state);
 }
 protected virtual void OnContextMenuConstructed(object sender, ConstructedMenuArgs args)
 {
     if (this.CurrentState == CollectorState.MenuBuilded)
       {
     throw new Exception("State inconsistency");
       }
       this.CurrentState = CollectorState.MenuBuilded;
       this.IsUnderConstruction = false;
       this.OnContextMenuUpdated();
 }
 protected virtual void OnMenuEntryConstructed(object sender, MenuEntryConstructedArgs args)
 {
     if (this.CurrentState == CollectorState.MenuBuilded)
       {
     this.IsUnderConstruction = true;
     this.ContextMenu = new Dictionary<Instance, ToolStripItem>();
     this.CurrentState = CollectorState.MenuBuilding;
       }
       this.AddInstanceEntry(args);
 }
Beispiel #35
0
        public void Dispose() {
            this.State = CollectorState.Stopped;
            this._watchTimer.Dispose();
            this._tickTimer.Dispose();

            this.GetDatasCancelTokenSource.Cancel();
            if (this.snmp != null)
                this.snmp.Dispose();
            
            this.StateChanged = null;
            this.DatasChanged = null;
            this.AwaitTick = null;            
        }