Mercurial > servermonitor
diff 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 |
line wrap: on
line diff
--- a/ServerMonitor/Controls/SshCheckControl.cs Mon Dec 31 18:32:14 2018 -0500 +++ b/ServerMonitor/Controls/SshCheckControl.cs Tue Jan 01 21:14:47 2019 -0500 @@ -34,11 +34,33 @@ SshCheck check = (SshCheck)check1; check.Command = CommandTextBox.Text.Trim(); check.CheckExitCode = ExitCodeCheckBox.Checked; - check.ExitCode = int.Parse(ExitCodeTextBox.Text); + try + { + check.ExitCode = int.Parse(ExitCodeTextBox.Text); + } + catch + { + if (check.CheckExitCode) + throw new UpdateCheckException("Exit code must be an integer."); + else + check.ExitCode = 0; + } check.CheckCommandOutput = CommandOutputCheckBox.Checked; check.CommandOutputMatchType = (MatchType)CommandOutputComboBox.SelectedIndex; + if (check.CheckCommandOutput && check.CommandOutputMatchType.In(MatchType.GreaterThan, MatchType.LessThan) && !decimal.TryParse(CommandOutputTextBox.Text, out decimal _)) + { + throw new UpdateCheckException("Command output must be numeric if checking for greater than/less than."); + } check.CommandOutputPattern = CommandOutputTextBox.Text; check.CommandOutputUseRegex = CommandOutputRegexCheckBox.Checked; } + + private void CommandOutputComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + bool numeric = ((MatchType)CommandOutputComboBox.SelectedIndex).In(MatchType.GreaterThan, MatchType.LessThan); + CommandOutputRegexCheckBox.Enabled = !numeric; + if (numeric) + CommandOutputRegexCheckBox.Checked = false; + } } }