diff --git a/agent/windows-setup-agent/Icinga2SetupAgent.csproj b/agent/windows-setup-agent/Icinga2SetupAgent.csproj
index 4229f0183..e4f55e40d 100644
--- a/agent/windows-setup-agent/Icinga2SetupAgent.csproj
+++ b/agent/windows-setup-agent/Icinga2SetupAgent.csproj
@@ -80,6 +80,12 @@
+
+ Form
+
+
+ ServiceStatus.cs
+
Form
@@ -94,6 +100,9 @@
+
+ ServiceStatus.cs
+
SetupWizard.cs
diff --git a/agent/windows-setup-agent/Program.cs b/agent/windows-setup-agent/Program.cs
index e0f23e401..dea5a0f28 100644
--- a/agent/windows-setup-agent/Program.cs
+++ b/agent/windows-setup-agent/Program.cs
@@ -1,10 +1,32 @@
using System;
+using System.IO;
using System.Windows.Forms;
+using Microsoft.Win32;
namespace Icinga
{
static class Program
{
+
+ public static string Icinga2InstallDir
+ {
+ get
+ {
+ RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Icinga Development Team\\ICINGA2");
+
+ if (rk == null)
+ return "";
+
+ return (string)rk.GetValue("");
+ }
+ }
+
+ public static void FatalError(Form owner, string message)
+ {
+ MessageBox.Show(owner, message, owner.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ Application.Exit();
+ }
+
///
/// The main entry point for the application.
///
@@ -13,7 +35,20 @@ namespace Icinga
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new SetupWizard());
+
+ string installDir = Program.Icinga2InstallDir;
+
+ if (installDir == "")
+ FatalError(null, "Icinga 2 does not seem to be installed properly.");
+
+ Form form;
+
+ if (File.Exists(installDir + "\\etc\\icinga2\\features-enabled\\api.conf"))
+ form = new ServiceStatus();
+ else
+ form = new SetupWizard();
+
+ Application.Run(form);
}
}
}
diff --git a/agent/windows-setup-agent/ServiceStatus.Designer.cs b/agent/windows-setup-agent/ServiceStatus.Designer.cs
new file mode 100644
index 000000000..23973d500
--- /dev/null
+++ b/agent/windows-setup-agent/ServiceStatus.Designer.cs
@@ -0,0 +1,118 @@
+namespace Icinga
+{
+ partial class ServiceStatus
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServiceStatus));
+ this.picBanner = new System.Windows.Forms.PictureBox();
+ this.lblStatus = new System.Windows.Forms.Label();
+ this.txtStatus = new System.Windows.Forms.TextBox();
+ this.btnReconfigure = new System.Windows.Forms.Button();
+ this.btnOK = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.picBanner)).BeginInit();
+ this.SuspendLayout();
+ //
+ // picBanner
+ //
+ this.picBanner.Image = global::Icinga.Properties.Resources.icinga_banner;
+ this.picBanner.Location = new System.Drawing.Point(0, 0);
+ this.picBanner.Name = "picBanner";
+ this.picBanner.Size = new System.Drawing.Size(625, 77);
+ this.picBanner.TabIndex = 2;
+ this.picBanner.TabStop = false;
+ //
+ // lblStatus
+ //
+ this.lblStatus.AutoSize = true;
+ this.lblStatus.Location = new System.Drawing.Point(12, 105);
+ this.lblStatus.Name = "lblStatus";
+ this.lblStatus.Size = new System.Drawing.Size(79, 13);
+ this.lblStatus.TabIndex = 3;
+ this.lblStatus.Text = "Service Status:";
+ //
+ // txtStatus
+ //
+ this.txtStatus.Location = new System.Drawing.Point(97, 102);
+ this.txtStatus.Name = "txtStatus";
+ this.txtStatus.ReadOnly = true;
+ this.txtStatus.Size = new System.Drawing.Size(278, 20);
+ this.txtStatus.TabIndex = 2;
+ //
+ // btnReconfigure
+ //
+ this.btnReconfigure.Location = new System.Drawing.Point(219, 143);
+ this.btnReconfigure.Name = "btnReconfigure";
+ this.btnReconfigure.Size = new System.Drawing.Size(75, 23);
+ this.btnReconfigure.TabIndex = 1;
+ this.btnReconfigure.Text = "Reconfigure";
+ this.btnReconfigure.UseVisualStyleBackColor = true;
+ this.btnReconfigure.Click += new System.EventHandler(this.btnReconfigure_Click);
+ //
+ // btnOK
+ //
+ this.btnOK.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.btnOK.Location = new System.Drawing.Point(300, 143);
+ this.btnOK.Name = "btnOK";
+ this.btnOK.Size = new System.Drawing.Size(75, 23);
+ this.btnOK.TabIndex = 0;
+ this.btnOK.Text = "OK";
+ this.btnOK.UseVisualStyleBackColor = true;
+ this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
+ //
+ // ServiceStatus
+ //
+ this.AcceptButton = this.btnOK;
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.CancelButton = this.btnOK;
+ this.ClientSize = new System.Drawing.Size(391, 186);
+ this.Controls.Add(this.btnOK);
+ this.Controls.Add(this.btnReconfigure);
+ this.Controls.Add(this.txtStatus);
+ this.Controls.Add(this.lblStatus);
+ this.Controls.Add(this.picBanner);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+ this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+ this.MaximizeBox = false;
+ this.Name = "ServiceStatus";
+ this.Text = "Icinga 2 Service Status";
+ ((System.ComponentModel.ISupportInitialize)(this.picBanner)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PictureBox picBanner;
+ private System.Windows.Forms.Label lblStatus;
+ private System.Windows.Forms.TextBox txtStatus;
+ private System.Windows.Forms.Button btnReconfigure;
+ private System.Windows.Forms.Button btnOK;
+ }
+}
\ No newline at end of file
diff --git a/agent/windows-setup-agent/ServiceStatus.cs b/agent/windows-setup-agent/ServiceStatus.cs
new file mode 100644
index 000000000..3f9ae1ada
--- /dev/null
+++ b/agent/windows-setup-agent/ServiceStatus.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Text;
+using System.Windows.Forms;
+using System.ServiceProcess;
+
+namespace Icinga
+{
+ public partial class ServiceStatus : Form
+ {
+ public ServiceStatus()
+ {
+ InitializeComponent();
+
+ try {
+ ServiceController sc = new ServiceController("icinga2");
+
+ txtStatus.Text = sc.Status.ToString();
+ } catch (InvalidOperationException) {
+ txtStatus.Text = "Not Available";
+ }
+ }
+
+ private void btnReconfigure_Click(object sender, EventArgs e)
+ {
+ new SetupWizard().ShowDialog(this);
+ }
+
+ private void btnOK_Click(object sender, EventArgs e)
+ {
+ Close();
+ }
+ }
+}
diff --git a/agent/windows-setup-agent/ServiceStatus.resx b/agent/windows-setup-agent/ServiceStatus.resx
new file mode 100644
index 000000000..724f4a292
--- /dev/null
+++ b/agent/windows-setup-agent/ServiceStatus.resx
@@ -0,0 +1,138 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+
+
+ AAABAAEAICAQAAAABADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAAAIAAAAAAAAAAAAAEAAAABAA
+ AAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAgICAAMDAwAAAAP8AAP8AAAD//wD/AAAA/wD/AP//
+ AAD///8AAAAAAAAAAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAAcAAAcAB3AAAAAAAAAAAAAAcABwB///cA
+ AAAAAAAAAAAAcAAA////AAAAAAAAAAAAAAAAAP///3AAAAAAAAAAAAAAAAD///9wAAAAAAAAAAAAAAAA
+ j//4AAAAB3AAAAAAAAAAAAj/jwAAAA/4AAAAAAAAAAAAAAiAAAAP9wAAAAAAAAAAAAAH9wAAf3AAAAAA
+ AAAAAAAAAH93d/cAAAAAAAAAAAAAAAB////3AAAAAAAAAAAAAAAA/////wAAAAAAAAAAAAAAB/////9w
+ AAAAAAAAAAAAAAf/////gAAAAAAAAAAAAAAH//////h3AAAAAAAAAAAAB/////+I//h3eHAAAAAAAAD/
+ ////AAB3j//3AAAAAAB4////9wAAAAf/+AAAAAf/+AB4iPAAAAAAj/cAAAAH//AAAAD3AAAAAAcAAAAA
+ B/+AAAAAjwAAAAAAAAAAAAB3AAAAAA9wAAAAAAAAAAAAAAAAAAAIh3AAAAAAAAAAAAAAAAAAD//wAAAA
+ AAAAAAAAAAAAAH//9wAAAAAAAAAAAAAAAAB///cAAAAAAAcAAAAAAAAACP+AAAAAAHAAcAAAAAAAAAB3
+ AAAAAAcAAAcAAAAAAAAAAAAAAABwAAAAAAAAAAAAAAAAAAAAAAD/////4AAAB8AAAAOAAAABgAAAAYAA
+ AAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABgAAAAYAA
+ AAGAAAABgAAAAYAAAAGAAAABgAAAAYAAAAGAAAABgAAAAcAAAAPgAAAH/////w==
+
+
+
\ No newline at end of file
diff --git a/agent/windows-setup-agent/SetupWizard.cs b/agent/windows-setup-agent/SetupWizard.cs
index 771015cd5..6186f3311 100644
--- a/agent/windows-setup-agent/SetupWizard.cs
+++ b/agent/windows-setup-agent/SetupWizard.cs
@@ -8,7 +8,6 @@ using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Net.NetworkInformation;
-using Microsoft.Win32;
using System.IO.Compression;
using System.Diagnostics;
using System.ServiceProcess;
@@ -27,30 +26,11 @@ namespace Icinga
txtInstanceName.Text = Icinga2InstanceName;
}
- private void FatalError(string message)
- {
- MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
- Application.Exit();
- }
-
private void Warning(string message)
{
MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
- private string Icinga2InstallDir
- {
- get
- {
- RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Icinga Development Team\\ICINGA2");
-
- if (rk == null)
- return "";
-
- return (string)rk.GetValue("");
- }
- }
-
private string Icinga2InstanceName
{
get
@@ -85,7 +65,7 @@ namespace Icinga
{
FileStream fp = null;
try {
- fp = File.Open(Icinga2InstallDir + String.Format("\\etc\\icinga2\\features-enabled\\{0}.conf", feature), FileMode.Create);
+ fp = File.Open(Program.Icinga2InstallDir + String.Format("\\etc\\icinga2\\features-enabled\\{0}.conf", feature), FileMode.Create);
using (StreamWriter sw = new StreamWriter(fp, Encoding.ASCII)) {
fp = null;
sw.Write(String.Format("include \"../features-available/{0}.conf\"\n", feature));
@@ -164,12 +144,12 @@ namespace Icinga
{
SetRetrievalStatus(25);
- string pathPrefix = Icinga2InstallDir + "\\etc\\icinga2\\pki\\" + txtInstanceName.Text;
+ string pathPrefix = Program.Icinga2InstallDir + "\\etc\\icinga2\\pki\\" + txtInstanceName.Text;
string output;
if (!File.Exists(pathPrefix + ".crt")) {
- if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
+ if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
"pki new-cert --cn \"" + txtInstanceName.Text + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\"",
out output)) {
ShowErrorText(output);
@@ -181,7 +161,7 @@ namespace Icinga
_TrustedFile = Path.GetTempFileName();
- if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
+ if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
"pki save-cert --host \"" + host + "\" --port \"" + port + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\" --trustedcert \"" + _TrustedFile + "\"",
out output)) {
ShowErrorText(output);
@@ -233,7 +213,7 @@ namespace Icinga
args += " --cn " + txtInstanceName.Text;
args += " --zone " + txtInstanceName.Text;
- if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
+ if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
"node setup" + args,
out output)) {
ShowErrorText(output);
@@ -241,7 +221,7 @@ namespace Icinga
}
SetConfigureStatus(50, "Setting ACLs for the Icinga 2 directory...");
- DirectoryInfo di = new DirectoryInfo(Icinga2InstallDir);
+ DirectoryInfo di = new DirectoryInfo(Program.Icinga2InstallDir);
DirectorySecurity ds = di.GetAccessControl();
FileSystemAccessRule rule = new FileSystemAccessRule("NT AUTHORITY\\NetworkService",
FileSystemRights.Modify,
@@ -251,18 +231,18 @@ namespace Icinga
SetConfigureStatus(75, "Installing the Icinga 2 service...");
- RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
+ RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
"--scm-uninstall",
out output);
- if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
+ if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
"daemon --validate",
out output)) {
ShowErrorText(output);
return;
}
- if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
+ if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
"--scm-install daemon",
out output)) {
ShowErrorText(output);
@@ -297,10 +277,7 @@ namespace Icinga
private void AgentWizard_Shown(object sender, EventArgs e)
{
- string installDir = Icinga2InstallDir;
-
- if (installDir == "")
- FatalError("Icinga 2 does not seem to be installed properly.");
+ string installDir = Program.Icinga2InstallDir;
/* TODO: This is something the NSIS installer should do */
Directory.CreateDirectory(installDir + "\\etc\\icinga2\\pki");