Mercurial > servermonitor
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:3e1a2131f897 | 1:9e92780ebc0f |
---|---|
32 public override void UpdateCheck(Check check1) | 32 public override void UpdateCheck(Check check1) |
33 { | 33 { |
34 SshCheck check = (SshCheck)check1; | 34 SshCheck check = (SshCheck)check1; |
35 check.Command = CommandTextBox.Text.Trim(); | 35 check.Command = CommandTextBox.Text.Trim(); |
36 check.CheckExitCode = ExitCodeCheckBox.Checked; | 36 check.CheckExitCode = ExitCodeCheckBox.Checked; |
37 check.ExitCode = int.Parse(ExitCodeTextBox.Text); | 37 try |
38 { | |
39 check.ExitCode = int.Parse(ExitCodeTextBox.Text); | |
40 } | |
41 catch | |
42 { | |
43 if (check.CheckExitCode) | |
44 throw new UpdateCheckException("Exit code must be an integer."); | |
45 else | |
46 check.ExitCode = 0; | |
47 } | |
38 check.CheckCommandOutput = CommandOutputCheckBox.Checked; | 48 check.CheckCommandOutput = CommandOutputCheckBox.Checked; |
39 check.CommandOutputMatchType = (MatchType)CommandOutputComboBox.SelectedIndex; | 49 check.CommandOutputMatchType = (MatchType)CommandOutputComboBox.SelectedIndex; |
50 if (check.CheckCommandOutput && check.CommandOutputMatchType.In(MatchType.GreaterThan, MatchType.LessThan) && !decimal.TryParse(CommandOutputTextBox.Text, out decimal _)) | |
51 { | |
52 throw new UpdateCheckException("Command output must be numeric if checking for greater than/less than."); | |
53 } | |
40 check.CommandOutputPattern = CommandOutputTextBox.Text; | 54 check.CommandOutputPattern = CommandOutputTextBox.Text; |
41 check.CommandOutputUseRegex = CommandOutputRegexCheckBox.Checked; | 55 check.CommandOutputUseRegex = CommandOutputRegexCheckBox.Checked; |
42 } | 56 } |
57 | |
58 private void CommandOutputComboBox_SelectedIndexChanged(object sender, EventArgs e) | |
59 { | |
60 bool numeric = ((MatchType)CommandOutputComboBox.SelectedIndex).In(MatchType.GreaterThan, MatchType.LessThan); | |
61 CommandOutputRegexCheckBox.Enabled = !numeric; | |
62 if (numeric) | |
63 CommandOutputRegexCheckBox.Checked = false; | |
64 } | |
43 } | 65 } |
44 } | 66 } |