Skip to content

Commit

Permalink
Simplify prompts for the syslog and other log integrations (#1177)
Browse files Browse the repository at this point in the history
* Stop prompting for --message-format, --verify-tls and --facility.
* Make --syslog-host and --syslog-port required and remove the defaults.
* Prompt for the protocol before the host and port.
* Prompt for the auth mode before the auth token.
  • Loading branch information
pjcdawkins authored Oct 30, 2022
1 parent a3131c9 commit da51fd2
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/Command/Integration/IntegrationCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ protected function postProcessValues(array $values, Integration $integration = n
}
}

// Process syslog integer values.
foreach (['facility', 'port'] as $key) {
if (isset($values[$key])) {
$values[$key] = (int) $values[$key];
}
}

return $values;
}

Expand Down Expand Up @@ -497,48 +504,42 @@ private function getFields()
'description' => 'The Splunk event source type',
'required' => false,
]),
'protocol' => new OptionsField('Protocol', [
'conditions' => ['type' => ['syslog']],
'description' => 'Syslog transport protocol',
'required' => false,
'default' => 'tls',
'options' => ['tcp', 'udp', 'tls'],
]),
'host' => new Field('Host', [
'optionName' => 'syslog-host',
// N.B. syslog is an actual PHP function name so this is wrapped in extra array brackets, to avoid is_callable() passing
'conditions' => ['type' => ['syslog']],
'description' => 'Syslog relay/collector host',
'default' => 'localhost',
'required' => false,
'autoCompleterValues' => ['localhost'],
]),
'port' => new Field('Port', [
'optionName' => 'syslog-port',
'conditions' => ['type' => ['syslog']],
'description' => 'Syslog relay/collector port',
'default' => 514,
'required' => false,
'normalizer' => 'intval',
]),
'protocol' => new OptionsField('Protocol', [
'conditions' => ['type' => ['syslog']],
'description' => 'Syslog transport protocol',
'default' => 'udp',
'required' => false,
'options' => ['tcp', 'udp', 'tls'],
'autoCompleterValues' => ['6514'],
'validator' => function ($value) { return is_numeric($value) && $value >= 0 && $value <= 65535 ? true : "Invalid port number: $value"; },
]),
'facility' => new Field('Facility', [
'conditions' => ['type' => ['syslog']],
'description' => 'Syslog facility',
'default' => 1,
'required' => false,
'normalizer' => 'intval',
'avoidQuestion' => true,
'validator' => function ($value) { return is_numeric($value) && $value >= 0 && $value <= 23 ? true : "Invalid syslog facility code: $value"; },
]),
'message_format' => new OptionsField('Message format', [
'conditions' => ['type' => ['syslog']],
'description' => 'Syslog message format',
'options' => ['rfc3164' => 'RFC 3164', 'rfc5424' => 'RFC 5424'],
'default' => 'rfc5424',
'required' => false,
]),
'auth_token' => new Field('Authentication token', [
'conditions' => ['type' => ['syslog']],
'optionName' => 'auth-token',
'required' => false,
'avoidQuestion' => true,
]),
'auth_mode' => new OptionsField('Authentication mode', [
'conditions' => ['type' => ['syslog']],
Expand All @@ -547,6 +548,11 @@ private function getFields()
'options' => ['prefix', 'structured_data'],
'default' => 'prefix',
]),
'auth_token' => new Field('Authentication token', [
'conditions' => ['type' => ['syslog']],
'optionName' => 'auth-token',
'required' => false,
]),
'tls_verify' => new BooleanField('Verify TLS', [
'conditions' => ['type' => [
'newrelic',
Expand All @@ -558,6 +564,7 @@ private function getFields()
'questionLine' => 'Should HTTPS certificate verification be enabled (recommended)',
'default' => true,
'required' => false,
'avoidQuestion' => true,
]),
];
}
Expand Down

0 comments on commit da51fd2

Please sign in to comment.