Mercurial > servermonitor
annotate ServerMonitor/Controls/SshCheckControl.cs @ 11:75ca86e0862c
Add setting to hide to notification area.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Mon, 15 Apr 2019 19:24:25 -0400 |
parents | 7127d5b5ac75 |
children |
rev | line source |
---|---|
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
1 using System; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
2 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
3 namespace ServerMonitorApp |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
4 { |
9 | 5 /// <summary>Control for editing an SSH space check.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
6 [CheckType(typeof(SshCheck))] |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
7 public partial class SshCheckControl : CheckControl |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
8 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
9 public SshCheckControl() |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
10 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
11 InitializeComponent(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
12 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
13 |
9 | 14 /// <summary>Sets the values of the controls from a check's properties.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
15 public override void LoadCheck(Check check1) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
16 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
17 SshCheck check = (SshCheck)check1; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
18 CommandTextBox.Text = check.Command; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
19 ExitCodeCheckBox.Checked = check.CheckExitCode; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
20 ExitCodeTextBox.Text = check.ExitCode.ToString(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
21 CommandOutputCheckBox.Checked = check.CheckCommandOutput; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
22 CommandOutputComboBox.SelectedIndex = (int)check.CommandOutputMatchType; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
23 CommandOutputTextBox.Text = check.CommandOutputPattern; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
24 CommandOutputRegexCheckBox.Checked = check.CommandOutputUseRegex; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
25 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
26 |
9 | 27 /// <summary>Updates the properties of a check from user input.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
28 public override void UpdateCheck(Check check1) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
29 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
30 SshCheck check = (SshCheck)check1; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
31 check.Command = CommandTextBox.Text.Trim(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
32 check.CheckExitCode = ExitCodeCheckBox.Checked; |
1
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
33 try |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
34 { |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
35 check.ExitCode = int.Parse(ExitCodeTextBox.Text); |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
36 } |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
37 catch |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
38 { |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
39 if (check.CheckExitCode) |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
40 throw new UpdateCheckException("Exit code must be an integer."); |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
41 else |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
42 check.ExitCode = 0; |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
43 } |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
44 check.CheckCommandOutput = CommandOutputCheckBox.Checked; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
45 check.CommandOutputMatchType = (MatchType)CommandOutputComboBox.SelectedIndex; |
1
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
46 if (check.CheckCommandOutput && check.CommandOutputMatchType.In(MatchType.GreaterThan, MatchType.LessThan) && !decimal.TryParse(CommandOutputTextBox.Text, out decimal _)) |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
47 { |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
48 throw new UpdateCheckException("Command output must be numeric if checking for greater than/less than."); |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
49 } |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
50 check.CommandOutputPattern = CommandOutputTextBox.Text; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
51 check.CommandOutputUseRegex = CommandOutputRegexCheckBox.Checked; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
52 } |
1
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
53 |
9 | 54 /// <summary>Disables the regex checkbox if a numeric comparison is selected.</summary> |
1
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
55 private void CommandOutputComboBox_SelectedIndexChanged(object sender, EventArgs e) |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
56 { |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
57 bool numeric = ((MatchType)CommandOutputComboBox.SelectedIndex).In(MatchType.GreaterThan, MatchType.LessThan); |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
58 CommandOutputRegexCheckBox.Enabled = !numeric; |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
59 if (numeric) |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
60 CommandOutputRegexCheckBox.Checked = false; |
9e92780ebc0f
Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents:
0
diff
changeset
|
61 } |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
62 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
63 } |