mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Fleet] fixed undefined error when missing policy vars in template (#124215)
* fixed undefined error when missing policy vars in template * added validation error if input has no vars * fixed checks * added unit test * fixed checks * fixed checks * fixed checks * moved validation error to validatePackagePolicyConfig
This commit is contained in:
parent
f3ff2291f5
commit
67430f91ce
2 changed files with 136 additions and 5 deletions
|
@ -606,6 +606,132 @@ describe('Fleet - validatePackagePolicy()', () => {
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns package policy validation error if input var does not exist', () => {
|
||||
expect(
|
||||
validatePackagePolicy(
|
||||
{
|
||||
description: 'Linux Metrics',
|
||||
enabled: true,
|
||||
inputs: [
|
||||
{
|
||||
enabled: true,
|
||||
streams: [
|
||||
{
|
||||
data_stream: {
|
||||
dataset: 'linux.memory',
|
||||
type: 'metrics',
|
||||
},
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
type: 'linux/metrics',
|
||||
vars: {
|
||||
period: {
|
||||
type: 'string',
|
||||
value: '1s',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
name: 'linux-3d13ada6-a9ae-46df-8e57-ff5050f4b671',
|
||||
namespace: 'default',
|
||||
output_id: '',
|
||||
package: {
|
||||
name: 'linux',
|
||||
title: 'Linux Metrics',
|
||||
version: '0.6.2',
|
||||
},
|
||||
policy_id: 'b25cb6e0-8347-11ec-96f9-6590c25bacf9',
|
||||
},
|
||||
{
|
||||
...mockPackage,
|
||||
name: 'linux',
|
||||
policy_templates: [
|
||||
{
|
||||
name: 'system',
|
||||
title: 'Linux kernel metrics',
|
||||
description: 'Collect system metrics from Linux operating systems',
|
||||
inputs: [
|
||||
{
|
||||
title: 'Collect system metrics from Linux instances',
|
||||
vars: [
|
||||
{
|
||||
name: 'system.hostfs',
|
||||
type: 'text',
|
||||
title: 'Proc Filesystem Directory',
|
||||
multi: false,
|
||||
required: false,
|
||||
show_user: true,
|
||||
description: 'The proc filesystem base directory.',
|
||||
},
|
||||
],
|
||||
type: 'system/metrics',
|
||||
description:
|
||||
'Collecting Linux entropy, Network Summary, RAID, service, socket, and users metrics',
|
||||
},
|
||||
{
|
||||
title: 'Collect low-level system metrics from Linux instances',
|
||||
vars: [],
|
||||
type: 'linux/metrics',
|
||||
description: 'Collecting Linux conntrack, ksm, pageinfo metrics.',
|
||||
},
|
||||
],
|
||||
multiple: true,
|
||||
},
|
||||
],
|
||||
data_streams: [
|
||||
{
|
||||
dataset: 'linux.memory',
|
||||
package: 'linux',
|
||||
path: 'memory',
|
||||
streams: [
|
||||
{
|
||||
input: 'linux/metrics',
|
||||
title: 'Linux memory metrics',
|
||||
vars: [
|
||||
{
|
||||
name: 'period',
|
||||
type: 'text',
|
||||
title: 'Period',
|
||||
multi: false,
|
||||
required: true,
|
||||
show_user: true,
|
||||
default: '10s',
|
||||
},
|
||||
],
|
||||
template_path: 'stream.yml.hbs',
|
||||
description: 'Linux paging and memory management metrics',
|
||||
},
|
||||
],
|
||||
title: 'Linux-only memory metrics',
|
||||
release: 'experimental',
|
||||
type: 'metrics',
|
||||
},
|
||||
],
|
||||
},
|
||||
safeLoad
|
||||
)
|
||||
).toEqual({
|
||||
description: null,
|
||||
inputs: {
|
||||
'linux/metrics': {
|
||||
streams: {
|
||||
'linux.memory': {
|
||||
vars: {
|
||||
period: ['Period is required'],
|
||||
},
|
||||
},
|
||||
},
|
||||
vars: {
|
||||
period: ['period var definition does not exist'],
|
||||
},
|
||||
},
|
||||
},
|
||||
name: null,
|
||||
namespace: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('works for packages with multiple policy templates (aka integrations)', () => {
|
||||
|
|
|
@ -143,7 +143,7 @@ export const validatePackagePolicy = (
|
|||
results[name] = input.enabled
|
||||
? validatePackagePolicyConfig(
|
||||
configEntry,
|
||||
inputVarDefsByPolicyTemplateAndType[inputKey][name],
|
||||
(inputVarDefsByPolicyTemplateAndType[inputKey] ?? {})[name],
|
||||
name,
|
||||
safeLoadYaml
|
||||
)
|
||||
|
@ -210,10 +210,15 @@ export const validatePackagePolicyConfig = (
|
|||
}
|
||||
|
||||
if (varDef === undefined) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.debug(`No variable definition for ${varName} found`);
|
||||
|
||||
return null;
|
||||
errors.push(
|
||||
i18n.translate('xpack.fleet.packagePolicyValidation.nonExistentVarMessage', {
|
||||
defaultMessage: '{varName} var definition does not exist',
|
||||
values: {
|
||||
varName,
|
||||
},
|
||||
})
|
||||
);
|
||||
return errors;
|
||||
}
|
||||
|
||||
if (varDef.required) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue