Make "agent setup" ask the user for the endpoint names

refs #7423
This commit is contained in:
Gunnar Beutner 2014-10-23 04:23:22 +02:00
parent 9ee523e601
commit 9161b17122
7 changed files with 155 additions and 57 deletions

View File

@ -74,6 +74,7 @@
this.txtError = new System.Windows.Forms.TextBox();
this.lblError = new System.Windows.Forms.Label();
this.picBanner = new System.Windows.Forms.PictureBox();
this.colInstanceName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tabFinish.SuspendLayout();
this.tabConfigure.SuspendLayout();
this.tabParameters.SuspendLayout();
@ -308,8 +309,10 @@
// lvwEndpoints
//
this.lvwEndpoints.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colInstanceName,
this.colHost,
this.colPort});
this.lvwEndpoints.FullRowSelect = true;
this.lvwEndpoints.Location = new System.Drawing.Point(11, 83);
this.lvwEndpoints.Name = "lvwEndpoints";
this.lvwEndpoints.Size = new System.Drawing.Size(500, 176);
@ -321,12 +324,12 @@
// colHost
//
this.colHost.Text = "Host";
this.colHost.Width = 300;
this.colHost.Width = 200;
//
// colPort
//
this.colPort.Text = "Port";
this.colPort.Width = 120;
this.colPort.Width = 80;
//
// rdoNoMaster
//
@ -545,6 +548,11 @@
this.picBanner.TabIndex = 1;
this.picBanner.TabStop = false;
//
// colInstanceName
//
this.colInstanceName.Text = "Instance Name";
this.colInstanceName.Width = 200;
//
// AgentWizard
//
this.AcceptButton = this.btnNext;
@ -634,6 +642,7 @@
private System.Windows.Forms.Label lblError;
private System.Windows.Forms.TextBox txtTicket;
private System.Windows.Forms.Label lblTicket;
private System.Windows.Forms.ColumnHeader colInstanceName;
}
}

View File

@ -66,6 +66,21 @@ namespace Icinga
}
}
private bool GetMasterHostPort(out string host, out string port)
{
foreach (ListViewItem lvi in lvwEndpoints.Items) {
if (lvi.SubItems.Count > 1) {
host = lvi.SubItems[1].Text;
port = lvi.SubItems[2].Text;
return true;
}
}
host = null;
port = null;
return false;
}
private void EnableFeature(string feature)
{
using (FileStream fp = File.Open(Icinga2InstallDir + String.Format("\\etc\\icinga2\\features-enabled\\{0}.conf", feature), FileMode.Create)) {
@ -185,10 +200,16 @@ namespace Icinga
args += " --master";
Invoke((MethodInvoker)delegate {
args += " --master_host " + lvwEndpoints.Items[0].SubItems[0].Text + "," + lvwEndpoints.Items[0].SubItems[1].Text;
string master_host, master_port;
GetMasterHostPort(out master_host, out master_port);
args += " --master_host " + master_host + "," + master_port;
foreach (ListViewItem lvi in lvwEndpoints.Items) {
args += " --endpoint " + lvi.SubItems[0].Text + "," + lvi.SubItems[1].Text;
args += " --endpoint " + lvi.SubItems[0].Text;
if (lvi.SubItems.Count > 1)
args += "," + lvi.SubItems[1].Text + "," + lvi.SubItems[2].Text;
}
});
@ -221,6 +242,13 @@ namespace Icinga
"--scm-uninstall",
out output);
if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
"daemon --validate",
out output)) {
ShowErrorText(output);
return;
}
if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
"--scm-install daemon",
out output)) {
@ -291,9 +319,17 @@ namespace Icinga
return;
}
if (rdoNoMaster.Checked && lvwEndpoints.Items.Count == 0) {
Warning("You need to add at least one master endpoint.");
return;
if (rdoNoMaster.Checked) {
if (lvwEndpoints.Items.Count == 0) {
Warning("You need to add at least one master endpoint.");
return;
}
string host, port;
if (!GetMasterHostPort(out host, out port)) {
Warning("Please enter a remote host and port for at least one of your endpoints.");
return;
}
}
if (rdoListener.Checked && (txtListenerPort.Text == "")) {
@ -328,7 +364,10 @@ namespace Icinga
if (tbcPages.SelectedTab == tabRetrieveCertificate) {
ListViewItem lvi = lvwEndpoints.Items[0];
Thread thread = new Thread((ThreadStart)delegate { VerifyCertificate(lvi.SubItems[0].Text, lvi.SubItems[1].Text); });
string master_host, master_port;
GetMasterHostPort(out master_host, out master_port);
Thread thread = new Thread((ThreadStart)delegate { VerifyCertificate(master_host, master_port); });
thread.Start();
}
@ -399,6 +438,8 @@ namespace Icinga
txtX509Issuer.Text = certificate.Issuer;
txtX509Subject.Text = certificate.Subject;
lvwX509Fields.Items.Clear();
AddCertificateField("Version", "V" + certificate.Version.ToString());
AddCertificateField("Serial number", certificate.SerialNumber);
AddCertificateField("Signature algorithm", certificate.SignatureAlgorithm.FriendlyName);
@ -422,8 +463,12 @@ namespace Icinga
return;
ListViewItem lvi = new ListViewItem();
lvi.Text = eib.txtHost.Text;
lvi.SubItems.Add(eib.txtPort.Text);
lvi.Text = eib.txtInstanceName.Text;
if (eib.chkConnect.Checked) {
lvi.SubItems.Add(eib.txtHost.Text);
lvi.SubItems.Add(eib.txtPort.Text);
}
lvwEndpoints.Items.Add(lvi);
}

View File

@ -27,7 +27,6 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.txtHost = new System.Windows.Forms.TextBox();
@ -35,52 +34,53 @@
this.label1 = new System.Windows.Forms.Label();
this.lblHost = new System.Windows.Forms.Label();
this.lblPort = new System.Windows.Forms.Label();
this.errErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
((System.ComponentModel.ISupportInitialize)(this.errErrorProvider)).BeginInit();
this.lblInstanceName = new System.Windows.Forms.Label();
this.txtInstanceName = new System.Windows.Forms.TextBox();
this.chkConnect = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// btnOK
//
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point(150, 120);
this.btnOK.Location = new System.Drawing.Point(196, 171);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 2;
this.btnOK.TabIndex = 4;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.CausesValidation = false;
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(231, 120);
this.btnCancel.Location = new System.Drawing.Point(277, 171);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 3;
this.btnCancel.TabIndex = 5;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
//
// txtHost
//
this.txtHost.Location = new System.Drawing.Point(55, 49);
this.txtHost.Enabled = false;
this.txtHost.Location = new System.Drawing.Point(101, 103);
this.txtHost.Name = "txtHost";
this.txtHost.Size = new System.Drawing.Size(251, 20);
this.txtHost.TabIndex = 0;
this.txtHost.Validating += new System.ComponentModel.CancelEventHandler(this.txtHost_Validating);
this.txtHost.TabIndex = 2;
//
// txtPort
//
this.txtPort.Location = new System.Drawing.Point(55, 80);
this.txtPort.Enabled = false;
this.txtPort.Location = new System.Drawing.Point(101, 134);
this.txtPort.Name = "txtPort";
this.txtPort.Size = new System.Drawing.Size(100, 20);
this.txtPort.TabIndex = 1;
this.txtPort.TabIndex = 3;
this.txtPort.Text = "5665";
this.txtPort.Validating += new System.ComponentModel.CancelEventHandler(this.txtPort_Validating);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(17, 16);
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(276, 13);
this.label1.TabIndex = 4;
@ -89,7 +89,7 @@
// lblHost
//
this.lblHost.AutoSize = true;
this.lblHost.Location = new System.Drawing.Point(17, 52);
this.lblHost.Location = new System.Drawing.Point(15, 106);
this.lblHost.Name = "lblHost";
this.lblHost.Size = new System.Drawing.Size(32, 13);
this.lblHost.TabIndex = 5;
@ -98,15 +98,38 @@
// lblPort
//
this.lblPort.AutoSize = true;
this.lblPort.Location = new System.Drawing.Point(20, 83);
this.lblPort.Location = new System.Drawing.Point(15, 137);
this.lblPort.Name = "lblPort";
this.lblPort.Size = new System.Drawing.Size(29, 13);
this.lblPort.TabIndex = 6;
this.lblPort.Text = "Port:";
//
// errErrorProvider
// lblInstanceName
//
this.errErrorProvider.ContainerControl = this;
this.lblInstanceName.AutoSize = true;
this.lblInstanceName.Location = new System.Drawing.Point(15, 41);
this.lblInstanceName.Name = "lblInstanceName";
this.lblInstanceName.Size = new System.Drawing.Size(82, 13);
this.lblInstanceName.TabIndex = 7;
this.lblInstanceName.Text = "Instance Name:";
//
// txtInstanceName
//
this.txtInstanceName.Location = new System.Drawing.Point(101, 37);
this.txtInstanceName.Name = "txtInstanceName";
this.txtInstanceName.Size = new System.Drawing.Size(251, 20);
this.txtInstanceName.TabIndex = 0;
//
// chkConnect
//
this.chkConnect.AutoSize = true;
this.chkConnect.Location = new System.Drawing.Point(18, 73);
this.chkConnect.Name = "chkConnect";
this.chkConnect.Size = new System.Drawing.Size(141, 17);
this.chkConnect.TabIndex = 1;
this.chkConnect.Text = "Connect to this endpoint";
this.chkConnect.UseVisualStyleBackColor = true;
this.chkConnect.CheckedChanged += new System.EventHandler(this.chkConnect_CheckedChanged);
//
// EndpointInputBox
//
@ -114,7 +137,10 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(326, 159);
this.ClientSize = new System.Drawing.Size(360, 202);
this.Controls.Add(this.chkConnect);
this.Controls.Add(this.txtInstanceName);
this.Controls.Add(this.lblInstanceName);
this.Controls.Add(this.lblPort);
this.Controls.Add(this.lblHost);
this.Controls.Add(this.label1);
@ -130,7 +156,6 @@
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Add Endpoint";
((System.ComponentModel.ISupportInitialize)(this.errErrorProvider)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -145,6 +170,8 @@
private System.Windows.Forms.Label lblPort;
public System.Windows.Forms.TextBox txtHost;
public System.Windows.Forms.TextBox txtPort;
private System.Windows.Forms.ErrorProvider errErrorProvider;
public System.Windows.Forms.TextBox txtInstanceName;
private System.Windows.Forms.Label lblInstanceName;
public System.Windows.Forms.CheckBox chkConnect;
}
}

View File

@ -15,20 +15,38 @@ namespace Icinga
InitializeComponent();
}
private void txtHost_Validating(object sender, CancelEventArgs e)
private void Warning(string message)
{
if (txtHost.Text.Length == 0) {
e.Cancel = true;
errErrorProvider.SetError(txtHost, "Please enter a host name.");
}
MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
private void chkConnect_CheckedChanged(object sender, EventArgs e)
{
txtHost.Enabled = chkConnect.Checked;
txtPort.Enabled = chkConnect.Checked;
}
private void txtPort_Validating(object sender, CancelEventArgs e)
private void btnOK_Click(object sender, EventArgs e)
{
if (txtPort.Text.Length == 0) {
e.Cancel = true;
errErrorProvider.SetError(txtPort, "Please enter a port.");
if (txtInstanceName.Text.Length == 0) {
Warning("Please enter an instance name.");
return;
}
if (chkConnect.Checked) {
if (txtHost.Text.Length == 0) {
Warning("Please enter a host name.");
return;
}
if (txtPort.Text.Length == 0) {
Warning("Please enter a port.");
return;
}
}
DialogResult = DialogResult.OK;
Close();
}
}
}

View File

@ -117,7 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="errErrorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>22, 24</value>
</metadata>
</root>

View File

@ -60,7 +60,7 @@ void AgentSetupCommand::InitParameters(boost::program_options::options_descripti
("zone", po::value<std::string>(), "The name of the local zone")
("master_zone", po::value<std::string>(), "The name of the master zone")
("master_host", po::value<std::string>(), "The name of the master host for auto-signing the csr")
("endpoint", po::value<std::vector<std::string> >(), "Connect to remote endpoint on host,port")
("endpoint", po::value<std::vector<std::string> >(), "Connect to remote endpoint; syntax: cn,host,port")
("listen", po::value<std::string>(), "Listen on host,port")
("ticket", po::value<std::string>(), "Generated ticket number for this request")
("trustedcert", po::value<std::string>(), "Trusted master certificate file")
@ -92,13 +92,10 @@ int AgentSetupCommand::Run(const boost::program_options::variables_map& vm, cons
<< "Ignoring parameters: " << boost::algorithm::join(ap, " ");
}
if (vm.count("master")) {
if (vm.count("master"))
return SetupMaster(vm, ap);
} else {
else
return SetupAgent(vm, ap);
}
return 0;
}
int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap)
@ -209,7 +206,7 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
int AgentSetupCommand::SetupAgent(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap)
{
/* require ticket number (generated on master) */
/* require ticket number (generated on master) and at least one endpoint */
if (!vm.count("ticket")) {
Log(LogCritical, "cli")
@ -218,6 +215,11 @@ int AgentSetupCommand::SetupAgent(const boost::program_options::variables_map& v
return 1;
}
if (!vm.count("endpoint")) {
Log(LogCritical, "cli", "You need to specify at least one endpoint (--endpoint).");
return 1;
}
String ticket = vm["ticket"].as<std::string>();
Log(LogInformation, "cli")

View File

@ -280,17 +280,17 @@ int AgentUtility::GenerateAgentIcingaConfig(const std::vector<std::string>& endp
Dictionary::Ptr my_master_endpoint = make_shared<Dictionary>();
if (tokens.size() == 1 || tokens.size() == 2)
my_master_endpoint->Set("host", tokens[0]);
if (tokens.size() > 1)
my_master_endpoint->Set("host", tokens[1]);
if (tokens.size() == 2)
my_master_endpoint->Set("port", tokens[1]);
if (tokens.size() > 2)
my_master_endpoint->Set("port", tokens[2]);
my_master_endpoint->Set("__name", String(endpoint));
my_master_endpoint->Set("__name", tokens[0]);
my_master_endpoint->Set("__type", "Endpoint");
/* save endpoint in master zone */
my_master_zone_members->Add(String(endpoint)); //find a better name
my_master_zone_members->Add(tokens[0]);
my_config->Add(my_master_endpoint);
}