Ejemplo n.º 1
0
        public void RunCommand(string command, string[] parameters, out Nagios.Net.Client.Nrpe.MessageState level, out string message)
        {
            // module process commands without parameters
            if (GetRegisteredCommands().Contains(command) == false)
            {
                level   = Nagios.Net.Client.Nrpe.MessageState.STATE_UNKNOWN;
                message = "Incorrect Command";
                return;
            }

            PCounter c = _counters.Where(x => x.Config.Command == command).FirstOrDefault();

            if (c == null)
            {
                level   = Nagios.Net.Client.Nrpe.MessageState.STATE_UNKNOWN;
                message = "Incorrect Command";
                return;
            }
            float value = c.Value;

            if ((c.Config.CriticalMethod == (int)(ExpressionMethods.Equal) && c.Config.CriticalValue == value) ||
                (c.Config.CriticalMethod == (int)(ExpressionMethods.GreateThen) && c.Config.CriticalValue < value) ||
                (c.Config.CriticalMethod == (int)(ExpressionMethods.LessThen) && c.Config.CriticalValue > value) ||
                (c.Config.CriticalMethod == (int)(ExpressionMethods.GreaterOrEqual) && c.Config.CriticalValue <= value) ||
                (c.Config.CriticalMethod == (int)(ExpressionMethods.LessOrEqual) && c.Config.CriticalValue >= value))
            {
                level = Nagios.Net.Client.Nrpe.MessageState.STATE_CRITICAL;
            }
            else if ((c.Config.WarningMethod == (int)(ExpressionMethods.Equal) && c.Config.WarningValue == value) ||
                     (c.Config.WarningMethod == (int)(ExpressionMethods.GreateThen) && c.Config.WarningValue < value) ||
                     (c.Config.WarningMethod == (int)(ExpressionMethods.LessThen) && c.Config.WarningValue > value) ||
                     (c.Config.WarningMethod == (int)(ExpressionMethods.GreaterOrEqual) && c.Config.WarningValue <= value) ||
                     (c.Config.WarningMethod == (int)(ExpressionMethods.LessOrEqual) && c.Config.WarningValue >= value))
            {
                level = Nagios.Net.Client.Nrpe.MessageState.STATE_WARNING;
            }
            else
            {
                level = Nagios.Net.Client.Nrpe.MessageState.STATE_OK;
            }
            message = value.ToString();
        }
Ejemplo n.º 2
0
        private void Configurate()
        {
            _timer.Enabled = false;

            // read config
            try
            {
                string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), NrpePerfCountersModule.Configurator.ConfigConstants.ConfigFileName);
                System.Configuration.Configuration _cfg = ConfigurationManager.OpenExeConfiguration(path);
                if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.Counters) == true)
                {
                    _counters.Clear();
                    PerfCounters cc = PerfCounters.Load(_cfg.AppSettings.Settings[ConfigConstants.Counters].Value);
                    if (cc != null)
                    {
                        this._counters.ForEach(x => x.Dispose());
                        this._counters.Clear();
                        foreach (PerfCounter pc in cc.Counters)
                        {
                            PCounter c = new PCounter();
                            c.Config = pc;
                            if (pc.Instance != "Default")
                            {
                                c.Counter = new System.Diagnostics.PerformanceCounter(pc.Category, pc.Counter, pc.Instance, true);
                            }
                            else
                            {
                                c.Counter = new System.Diagnostics.PerformanceCounter(pc.Category, pc.Counter, true);
                            }
                            _counters.Add(c);
                        }
                        RaiseCommandsChanged();
                    }
                }
            }
            catch (Exception ex)
            {
                Nagios.Net.Client.Log.WriteLog(string.Format("{0}\n{1}", ex.Message, ex.StackTrace), true);
            }

            _timer.Enabled = true;
        }
Ejemplo n.º 3
0
        private void Configurate()
        {
            _timer.Enabled = false;

            // read config
            try
            {
                string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), NrpePerfCountersModule.Configurator.ConfigConstants.ConfigFileName);
                System.Configuration.Configuration _cfg = ConfigurationManager.OpenExeConfiguration(path);
                if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.Counters) == true)
                {
                    _counters.Clear();
                    PerfCounters cc = PerfCounters.Load(_cfg.AppSettings.Settings[ConfigConstants.Counters].Value);
                    if (cc != null)
                    {
                        this._counters.ForEach(x => x.Dispose());
                        this._counters.Clear();
                        foreach (PerfCounter pc in cc.Counters)
                        {
                            PCounter c = new PCounter();
                            c.Config = pc;
                            if (pc.Instance != "Default")
                                c.Counter = new System.Diagnostics.PerformanceCounter(pc.Category, pc.Counter, pc.Instance, true);
                            else
                                c.Counter = new System.Diagnostics.PerformanceCounter(pc.Category, pc.Counter, true);
                            _counters.Add(c);
                        }
                        RaiseCommandsChanged();
                    }
                }

            }
            catch (Exception ex)
            {
                Nagios.Net.Client.Log.WriteLog(string.Format("{0}\n{1}", ex.Message, ex.StackTrace), true);
            }

            _timer.Enabled = true;
        }