annotate ServerMonitor/Controls/SshCheckControl.cs @ 1:9e92780ebc0f

Additional validation for SSH check
author Brad Greco <brad@bgreco.net>
date Tue, 01 Jan 2019 21:14:47 -0500
parents 3e1a2131f897
children 7127d5b5ac75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 using System.Collections.Generic;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 using System.ComponentModel;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4 using System.Drawing;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5 using System.Data;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 using System.Linq;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 using System.Text;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 using System.Windows.Forms;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 namespace ServerMonitorApp
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 [CheckType(typeof(SshCheck))]
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13 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
14 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 public SshCheckControl()
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 InitializeComponent();
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20 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
21 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 SshCheck check = (SshCheck)check1;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23 CommandTextBox.Text = check.Command;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24 ExitCodeCheckBox.Checked = check.CheckExitCode;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
25 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
26 CommandOutputCheckBox.Checked = check.CheckCommandOutput;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
27 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
28 CommandOutputTextBox.Text = check.CommandOutputPattern;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
29 CommandOutputRegexCheckBox.Checked = check.CommandOutputUseRegex;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
30 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
31
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
32 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
33 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
34 SshCheck check = (SshCheck)check1;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
35 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
36 check.CheckExitCode = ExitCodeCheckBox.Checked;
1
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
37 try
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 check.ExitCode = int.Parse(ExitCodeTextBox.Text);
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
40 }
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
41 catch
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
42 {
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
43 if (check.CheckExitCode)
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
44 throw new UpdateCheckException("Exit code must be an integer.");
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
45 else
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
46 check.ExitCode = 0;
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
47 }
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
48 check.CheckCommandOutput = CommandOutputCheckBox.Checked;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
49 check.CommandOutputMatchType = (MatchType)CommandOutputComboBox.SelectedIndex;
1
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
50 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
51 {
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
52 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
53 }
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
54 check.CommandOutputPattern = CommandOutputTextBox.Text;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
55 check.CommandOutputUseRegex = CommandOutputRegexCheckBox.Checked;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
56 }
1
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
57
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
58 private void CommandOutputComboBox_SelectedIndexChanged(object sender, EventArgs e)
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
59 {
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
60 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
61 CommandOutputRegexCheckBox.Enabled = !numeric;
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
62 if (numeric)
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
63 CommandOutputRegexCheckBox.Checked = false;
9e92780ebc0f Additional validation for SSH check
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
64 }
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
65 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
66 }