Esempio n. 1
0
 private void RaiseNscaCheck(Nagios.Net.Client.Nsca.Level level, string serviceName, string msg)
 {
     if (NscaCheck != null)
         NscaCheck.Invoke(this, new NscaCheckEventArgs(string.IsNullOrWhiteSpace(serviceName) ? this.ModuleName : serviceName, level, msg));
 }
Esempio n. 2
0
        private void UpdateNrpe(Nagios.Net.Client.Nrpe.NrpeSettings nrpe)
        {
            nrpe.IP = this.nrpeAddresses.Text;
            int port = 5666;
            if (int.TryParse(this.nrpePort.Text, out port) == false)
            {
                MessageBox.Show("Can't parse Port value, new value will be reset to default value (5666)", "Parse error", MessageBoxButton.OK, MessageBoxImage.Error);
                port = 5666;
            }
            nrpe.Port = port;
            nrpe.SSL = this.nrpeUseSsl.IsChecked == true ? true : false;
            nrpe.Hosts.Clear();

            System.Net.IPAddress nrpeIp = null;
            foreach (var h in _nrpeHosts.Where(x=> System.Net.IPAddress.TryParse(x.Host, out nrpeIp) == true))
                nrpe.Hosts.Add(h);
            nrpe.SectionInformation.ForceSave = true;
        }
Esempio n. 3
0
 private void UpdateNsca(Nagios.Net.Client.Nsca.NscaSettings nsca)
 {
     nsca.NscaAddress = this.nscaAddress.Text;
     int port = 5667;
     if (int.TryParse(this.nscaPort.Text, out port) == false)
     {
         MessageBox.Show("Can't parse Port value, new value will be reset to default value (5667)", "Parse error", MessageBoxButton.OK, MessageBoxImage.Error);
         port = 5667;
     }
     nsca.Port = port;
     nsca.Password = this.nscaPassword.Password;
     nsca.EncryptionType = (Nagios.Net.Client.Nsca.NscaEncryptionType)Enum.Parse(typeof(Nagios.Net.Client.Nsca.NscaEncryptionType), (string)this.nscaEcnryption.SelectedItem);
     nsca.NscaHostName = this.nscaHostName.Text;
     nsca.SectionInformation.ForceSave = true;
 }
Esempio n. 4
0
 public NscaCheckEventArgs(string service, Nagios.Net.Client.Nsca.Level level, string message)
 {
     Service = service;
     Level = level;
     Message = message;
 }
Esempio n. 5
0
 private void RaiseNscaCheck(Nagios.Net.Client.Nsca.Level level, string msg)
 {
     if (NscaCheck != null)
         NscaCheck.Invoke(this, new NscaCheckEventArgs(this.ModuleName, level, msg));
 }
Esempio n. 6
0
 public EventTextLogArgs(string serviceName, Nagios.Net.Client.Nsca.Level level, string message)
 {
     this.serviceName = serviceName;
     this.level = level;
     this.message = message;
 }
Esempio n. 7
0
        public void Config(string folder, string fileFilter, string eventFilter, string service, Nagios.Net.Client.Nsca.Level level)
        {
            // find files
            DirectoryInfo di = new DirectoryInfo(folder);
            if (di.Exists == false)
            {
                Log.WriteLog(string.Format("Nsca LogParser Module: folder {0} is not exist, set full folder name by Configurator", folder), true);
                return;
            }
            try
            {
                FileInfo[] files = di.GetFiles(fileFilter);
                foreach (FileInfo f in files)
                {
                    _files.Add(new LogFileWatch(f.FullName, f.Length));
                }
                // setup watcher
                _watcher.EnableRaisingEvents = false;
                _watcher.Path = folder;
                _watcher.Filter = fileFilter;
                _watcher.IncludeSubdirectories = false;
                _watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;

                _serviceName = service;
                _eventFilter = eventFilter;
                _level = level;

                if (string.IsNullOrWhiteSpace(eventFilter) == false)
                {
                    _regExp = new Regex(eventFilter, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                }
                else
                    _regExp = null;
            }
            catch (Exception ex)
            {
                Log.WriteLog(ex.Message + System.Environment.NewLine + ex.StackTrace, true);
            }
        }
Esempio n. 8
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();
        }