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; }
private void SetGeneral() { Nagios.Net.Client.Nsca.NscaSettings nsca = _appConfig.GetSection("nscaSettings") as Nagios.Net.Client.Nsca.NscaSettings; if (nsca != null) { this.nscaAddress.Text = nsca.NscaAddress; this.nscaPort.Text = nsca.Port.ToString(); this.nscaPassword.Password = nsca.Password; this.nscaEcnryption.SelectedItem = nsca.EncryptionType.ToString(); this.nscaHostName.Text = nsca.NscaHostName; } else { MessageBox.Show("NSCA settings not founded in config file!", "Error config loading", MessageBoxButton.OK, MessageBoxImage.Error); } Nagios.Net.Client.Nrpe.NrpeSettings nrpe = _appConfig.GetSection("nrpeSettings") as Nagios.Net.Client.Nrpe.NrpeSettings; if (nrpe != null) { this.nrpeAddresses.Text = nrpe.IP; this.nrpePort.Text = nrpe.Port.ToString(); this.nrpeUseSsl.IsChecked = nrpe.SSL; _nrpeHosts = new ObservableCollection <Nagios.Net.Client.Nrpe.FilteredHost>(); foreach (var h in nrpe.Hosts) { _nrpeHosts.Add((Nagios.Net.Client.Nrpe.FilteredHost)h); } if (_nrpeHosts.Count == 0) { _nrpeHosts.Add(new Nagios.Net.Client.Nrpe.FilteredHost("Any")); } this.nrpeHosts.ItemsSource = _nrpeHosts; this.nrpeHosts.SelectionMode = System.Windows.Controls.SelectionMode.Single; } else { MessageBox.Show("NRPE settings not founded in config file!", "Error config loading", MessageBoxButton.OK, MessageBoxImage.Error); } }
private bool SaveConfig() { bool rslt = false; Nagios.Net.Client.Nsca.NscaSettings nsca = _appConfig.GetSection("nscaSettings") as Nagios.Net.Client.Nsca.NscaSettings; if (nsca != null) { UpdateNsca(nsca); } else { MessageBox.Show("NSCA section of config has critical error, please restore config to original value", "Error config loading", MessageBoxButton.OK, MessageBoxImage.Error); } Nagios.Net.Client.Nrpe.NrpeSettings nrpe = _appConfig.GetSection("nrpeSettings") as Nagios.Net.Client.Nrpe.NrpeSettings; if (nrpe != null) { UpdateNrpe(nrpe); } else { MessageBox.Show("NRPE section of config has critical error, please restore config to original value", "Error config loading", MessageBoxButton.OK, MessageBoxImage.Error); } try { _appConfig.Save(ConfigurationSaveMode.Full); this.statusMsg.Foreground = SystemColors.ControlTextBrush; this.statusMsg.Text = "Data saved at " + DateTime.Now.ToString("HH:mm:ss"); rslt = true; } catch (Exception ex) { this.statusMsg.Foreground = new SolidColorBrush(Colors.Red); this.statusMsg.Text = "Erorr: " + ex.Message; } return(rslt); }
private void FirewallButton_Click(object sender, RoutedEventArgs e) { if (SaveAll() == false) { return; } try { var fw = (NetFwTypeLib.INetFwMgr)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwMgr")); if (fw == null || fw.LocalPolicy.CurrentProfile.FirewallEnabled == false) { MessageBox.Show("Can't set firewall rules. Windows Firewall diabled. Please enable firewall.", "Firewall", MessageBoxButton.OK, MessageBoxImage.Warning); return; } // check firewall rules NetFwTypeLib.INetFwPolicy2 firewallPolicy = (NetFwTypeLib.INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2")); if (firewallPolicy != null) { firewallPolicy.Rules.Remove(fRuleNscaName); firewallPolicy.Rules.Remove(fRuleNrpeName); Nagios.Net.Client.Nsca.NscaSettings nsca = _appConfig.GetSection("nscaSettings") as Nagios.Net.Client.Nsca.NscaSettings; if (nsca != null) { NetFwTypeLib.INetFwRule nscaRule = (NetFwTypeLib.INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule")); if (nscaRule != null) { nscaRule.Protocol = (int)NetFwTypeLib.NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP; nscaRule.Action = NetFwTypeLib.NET_FW_ACTION_.NET_FW_ACTION_ALLOW; nscaRule.Description = "Used to allow Nagios Net client send NSCA messages to Nagios server"; nscaRule.Direction = NetFwTypeLib.NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_OUT; nscaRule.Enabled = true; nscaRule.InterfaceTypes = "All"; nscaRule.Name = fRuleNscaName; nscaRule.RemoteAddresses = nsca.NscaAddress; nscaRule.RemotePorts = nsca.Port.ToString(); firewallPolicy.Rules.Add(nscaRule); } } Nagios.Net.Client.Nrpe.NrpeSettings nrpe = _appConfig.GetSection("nrpeSettings") as Nagios.Net.Client.Nrpe.NrpeSettings; if (nrpe != null) { NetFwTypeLib.INetFwRule nrpeRule = (NetFwTypeLib.INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule")); if (nrpeRule != null) { nrpeRule.Protocol = (int)NetFwTypeLib.NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP; nrpeRule.Action = NetFwTypeLib.NET_FW_ACTION_.NET_FW_ACTION_ALLOW; nrpeRule.Description = "Used to allow Nagios Net client receive NRPE commands and send replies to Nagios server"; nrpeRule.Direction = NetFwTypeLib.NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN; nrpeRule.Enabled = true; nrpeRule.InterfaceTypes = "All"; nrpeRule.Name = fRuleNrpeName; StringBuilder fhs = new StringBuilder(); foreach (Nagios.Net.Client.Nrpe.FilteredHost fh in nrpe.Hosts) { if (fhs.Length > 0) { fhs.Append(","); } fhs.Append(fh.Host); } nrpeRule.RemoteAddresses = fhs.Length > 0 ? fhs.ToString() : "*"; nrpeRule.LocalAddresses = nrpe.IP.ToUpper().Contains("ANY") ? "*" : nrpe.IP; nrpeRule.LocalPorts = nrpe.Port.ToString(); firewallPolicy.Rules.Add(nrpeRule); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Firewall Rules", MessageBoxButton.OK, MessageBoxImage.Error); } }