-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathdynamic-input-configuration.html
732 lines (707 loc) · 39.3 KB
/
dynamic-input-configuration.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>Variables and conditions in input configurations | Fleet and Elastic Agent Guide [8.18] | Elastic</title>
<meta class="elastic" name="content" content="Variables and conditions in input configurations | Fleet and Elastic Agent Guide [8.18]">
<link rel="home" href="index.html" title="Fleet and Elastic Agent Guide [8.18]"/>
<link rel="up" href="elastic-agent-input-configuration.html" title="Configure inputs for standalone Elastic Agents"/>
<link rel="prev" href="elastic-agent-inputs-list.html" title="Elastic Agent inputs"/>
<link rel="next" href="providers.html" title="Configure providers for standalone Elastic Agents"/>
<meta class="elastic" name="product_version" content="8.18"/>
<meta class="elastic" name="product_name" content="Fleet and Elastic Agent"/>
<meta class="elastic" name="website_area" content="documentation"/>
<meta name="DC.type" content="Learn/Docs/Fleet/Guide/Elastic Agent/8.18"/>
<meta name="DC.subject" content="Fleet and Elastic Agent"/>
<meta name="DC.identifier" content="8.18"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.optimizely.com/js/18132920325.js"></script>
<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<meta name="apple-mobile-web-app-title" content="Elastic">
<meta name="application-name" content="Elastic">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/mstile-144x144.png">
<meta name="theme-color" content="#ffffff">
<meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd" />
<meta name="yandex-verification" content="d8a47e95d0972434" />
<meta name="localized" content="true" />
<meta name="st:robots" content="follow,index" />
<meta property="og:image" content="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt280217a63b82a734/6202d3378b1f312528798412/elastic-logo.svg" />
<meta property="og:image:width" content="500" />
<meta property="og:image:height" content="172" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
<link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
<link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
<!-- Give IE8 a fighting chance -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/guide/static/styles-v1.css" />
</head>
<!--© 2015-2025 Elasticsearch B.V. -->
<!-- All Elastic documentation is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. -->
<!-- http://creativecommons.org/licenses/by-nc-nd/4.0/ -->
<body>
<!-- Google Tag Manager -->
<script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
<!-- End Google Tag Manager -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-12395217-16');
</script>
<!-- Google Tag Manager for GA4 -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-KNJMG2M');</script>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KNJMG2M" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager for GA4-->
<div id='elastic-nav' style="display:none;"></div>
<script src='https://www.elastic.co/elastic-nav.js'></script>
<div class="main-container">
<section id="content" >
<div class="content-wrapper">
<section id="guide" lang="en">
<div class="container-fluid">
<div class="row pb-3">
<div class="col-12 order-2 col-md-4 order-md-1 col-lg-3 h-almost-full-md sticky-top-md" id="left_col">
<!-- The TOC is appended here -->
</div>
<div class="col-12 order-1 col-md-8 order-md-2 col-lg-7 order-lg-2 guide-section" id="middle_col">
<!-- start body -->
<div class="navheader">
<span class="prev">
<a href="elastic-agent-inputs-list.html">« Elastic Agent inputs</a>
</span>
<span class="next">
<a href="providers.html">Configure providers for standalone Elastic Agents »</a>
</span>
</div>
<div class="book" lang="en">
<div class="titlepage">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="/guide/">Elastic Docs</a></span>
<span class="chevron-right">›</span><span class="breadcrumb-link"><a href="index.html">Fleet and Elastic Agent Guide [8.18]</a></span>
<span class="chevron-right">›</span><span class="breadcrumb-link"><a href="elastic-agent-configuration.html">Configure standalone Elastic Agents</a></span>
<span class="chevron-right">›</span><span class="breadcrumb-link"><a href="elastic-agent-input-configuration.html">Configure inputs for standalone Elastic Agents</a></span>
</div>
<div>
<div><h1 class="title"><a id="id-1"></a>Variables and conditions in input configurations</h1><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-dynamic-inputs.asciidoc">edit</a></div>
</div>
<!--EXTRA-->
</div>
<div id="content">
<div id="url-to-v3" class="version-warning">
A newer version is available. Check out the <a href="https://www.elastic.co/docs/reference/fleet/dynamic-input-configuration">latest documentation</a>.
</div>
<div class="section">
<div class="titlepage"><div><div>
<div class="position-relative"><h3 class="title"><a id="dynamic-input-configuration"></a>Variables and conditions in input configurations</h3><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-dynamic-inputs.asciidoc">edit</a></div>
</div></div></div>
<p>When running Elastic Agent in some environments, you might not know all the input
configuration details up front. To solve this problem, the input configuration
accepts variables and conditions that get evaluated at runtime using
information from the running environment. Similar to autodiscovery, these
capabilities allow you to apply configurations dynamically.</p>
<p>Let’s consider a unique agent policy that is deployed on two machines: a Linux
machine named "linux-app" and a Windows machine named "winapp". Notice that
the configuration has some variable references: <code class="literal">${host.name}</code> and
<code class="literal">${host.platform}</code>:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: unique-logfile-id
type: logfile
streams:
- paths: /var/log/${host.name}/another.log
condition: ${host.platform} == "linux"
- path: c:/service/app.log
condition: ${host.platform} == "windows"</pre>
</div>
<p>At runtime, Elastic Agent resolves variables and evaluates the conditions based
on values provided by the environment, generating two possible input
configurations.</p>
<p>On the Windows machine:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: unique-logfile-id
type: logfile
streams:
- path: c:/service/app.log</pre>
</div>
<p>On the Linux machine:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: unique-logfile-id
type: logfile
streams:
- paths: /var/log/linux-app/another.log</pre>
</div>
<p>Using variable substitution along with conditions allows you to create concise,
but flexible input configurations that adapt to their deployed environment.</p>
<div class="position-relative"><h4><a id="variable-substitution"></a>Variable substitution</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-variable-substitution.asciidoc">edit</a></div>
<p>The syntax for variable substitution is <code class="literal">${var}</code>, where <code class="literal">var</code> is the name of a
variable defined by a provider. A <em>provider</em> defines key/value pairs that are
used for variable substitution and conditions.</p>
<p>Elastic Agent supports a variety of providers, such as <code class="literal">host</code> and <code class="literal">local</code>, that
supply variables to Elastic Agent. For example, earlier you saw <code class="literal">${host.name}</code> used to
resolve the path to the host’s log file based on the <code class="literal">{host.platform}</code> value. Both of these values
were provided by the <code class="literal">host</code> provider.</p>
<p>All providers are enabled by default when Elastic Agent starts. If a provider cannot
be configured, its variables are ignored.</p>
<p>Refer to <a class="xref" href="providers.html" title="Configure providers for standalone Elastic Agents">Providers</a> for more detail.</p>
<p>The following agent policy uses a custom key named <code class="literal">foo</code> to resolve a value
defined by a local provider:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: unique-logfile-id
type: logfile
streams:
- paths: /var/log/${foo}/another.log
providers:
local:
vars:
foo: bar</pre>
</div>
<p>The policy generated by this configuration looks like this:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: unique-logfile-id
type: logfile
streams:
- paths: /var/log/bar/another.log</pre>
</div>
<p>When an input uses a variable substitution that is not present in the current
key/value mappings being evaluated, the input is removed in the result.</p>
<p>For example, this agent policy uses an unknown key:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: logfile-foo
type: logfile
path: "/var/log/foo"
- id: logfile-unknown
type: logfile
path: "${ unknown.key }"</pre>
</div>
<p>The policy generated by this configuration looks like this:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: logfile-foo
type: logfile
path: "/var/log/foo"</pre>
</div>
<div class="position-relative"><h4><a id="_alternative_variables_and_constants"></a>Alternative variables and constants</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-variable-substitution.asciidoc">edit</a></div>
<p>Variable substitution can also define alternative variables or a constant.</p>
<p>To define a constant, use either <code class="literal">'</code> or <code class="literal">"</code>. When a constant is reached during
variable evaluation, any remaining variables are ignored, so a constant should
be the last entry in the substitution.</p>
<p>To define alternatives, use <code class="literal">|</code> followed by the next variable or constant.
The power comes from allowing the input to define the preference order of the
substitution by chaining multiple variables together.</p>
<p>For example, the following agent policy chains together multiple variables to
set the log path based on information provided by the running container
environment. The constant <code class="literal">/var/log/other</code> is used to end of the path, which is
common to both providers:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: logfile-foo
type: logfile
path: "/var/log/foo"
- id: logfile-container
type: logfile
path: "${docker.paths.log|kubernetes.container.paths.log|'/var/log/other'}"</pre>
</div>
<div class="position-relative"><h4><a id="_escaping_variables"></a>Escaping variables</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-variable-substitution.asciidoc">edit</a></div>
<p>In some cases the <code class="literal">${var}</code> syntax causes an issue with using a value where the actually
wanted variable is <code class="literal">${var}</code>. In this case double <code class="literal">$$</code> can be provided for the variable.</p>
<p>The double <code class="literal">$$</code> causes the variable to be ignored and the extra <code class="literal">$</code> is removed from the beginning.</p>
<p>For example, the following agent policy uses the escaped variable so the actual value is used instead.</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: logfile-foo
type: logfile
path: "/var/log/foo"
processors:
- add_tags:
tags: [$${development}]
target: "environment"</pre>
</div>
<p>The policy generated by this configuration looks like this:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: logfile-foo
type: logfile
path: "/var/log/foo"
processors:
- add_tags:
tags: [${development}]
target: "environment"</pre>
</div>
<div class="position-relative"><h4><a id="conditions"></a>Conditions</h4><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-conditions.asciidoc">edit</a></div>
<p>A condition is a boolean expression that you can specify in your agent policy
to control whether a configuration is applied to the running Elastic Agent. You can
set a condition on inputs, streams, or even processors.</p>
<p>In this example, the input is applied if the host platform is Linux:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: unique-logfile-id
type: logfile
streams:
- paths:
- /var/log/syslog
condition: ${host.platform} == 'linux'</pre>
</div>
<p>In this example, the stream is applied if the host platform is not Windows:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: unique-system-metrics-id
type: system/metrics
streams:
- metricset: load
data_stream.dataset: system.cpu
condition: ${host.platform} != 'windows'</pre>
</div>
<p>In this example, the processor is applied if the host platform is not Windows:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">inputs:
- id: unique-system-metrics-id
type: system/metrics
streams:
- metricset: load
data_stream.dataset: system.cpu
processors:
- add_fields:
fields:
platform: ${host.platform}
to: host
condition: ${host.platform} != 'windows'</pre>
</div>
<div class="position-relative"><h5><a id="condition-syntax"></a>Condition syntax</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-conditions.asciidoc">edit</a></div>
<p>The conditions supported by Elastic Agent are based on <a href="/guide/en/elasticsearch/reference/8.18/eql-syntax.html" class="ulink" target="_top">EQL</a>'s
boolean syntax, but add support for variables from providers and functions to
manipulate the values.</p>
<p><span class="strong strong"><strong>Supported operators:</strong></span></p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Full PEMDAS math support for <code class="literal">+ - * / %</code>.
</li>
<li class="listitem">
Relational operators <code class="literal">< <= >= > == !=</code>
</li>
<li class="listitem">
Logical operators <code class="literal">and</code> and <code class="literal">or</code>
</li>
</ul>
</div>
<p><span class="strong strong"><strong>Functions:</strong></span></p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Array functions <a class="xref" href="dynamic-input-configuration.html#arrayContains-function" title="arrayContains"><code class="literal">arrayContains</code></a>
</li>
<li class="listitem">
Dict functions <a class="xref" href="dynamic-input-configuration.html#hasKey-function" title="hasKey"><code class="literal">hasKey</code></a> (not in EQL)
</li>
<li class="listitem">
Length functions <a class="xref" href="dynamic-input-configuration.html#length-function" title="length"><code class="literal">length</code></a>
</li>
<li class="listitem">
Math functions <a class="xref" href="dynamic-input-configuration.html#add-function" title="add"><code class="literal">add</code></a>, <a class="xref" href="dynamic-input-configuration.html#subtract-function" title="subtract"><code class="literal">subtract</code></a>,
<a class="xref" href="dynamic-input-configuration.html#multiply-function" title="multiply"><code class="literal">multiply</code></a>, <a class="xref" href="dynamic-input-configuration.html#divide-function" title="divide"><code class="literal">divide</code></a>, <a class="xref" href="dynamic-input-configuration.html#modulo-function" title="modulo"><code class="literal">modulo</code></a>
</li>
<li class="listitem">
String functions <a class="xref" href="dynamic-input-configuration.html#concat-function" title="concat"><code class="literal">concat</code></a>, <a class="xref" href="dynamic-input-configuration.html#endsWith-function" title="endsWith"><code class="literal">endsWith</code></a>,
<a class="xref" href="dynamic-input-configuration.html#indexOf-function" title="indexOf"><code class="literal">indexOf</code></a>, <a class="xref" href="dynamic-input-configuration.html#match-function" title="match"><code class="literal">match</code></a>, <a class="xref" href="dynamic-input-configuration.html#number-function" title="number"><code class="literal">number</code></a>,
<a class="xref" href="dynamic-input-configuration.html#startsWith-function" title="startsWith"><code class="literal">startsWith</code></a>, <a class="xref" href="dynamic-input-configuration.html#string-function" title="string"><code class="literal">string</code></a>,
<a class="xref" href="dynamic-input-configuration.html#stringContains-function" title="stringContains"><code class="literal">stringContains</code></a>
</li>
</ul>
</div>
<p><span class="strong strong"><strong>Types:</strong></span></p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Booleans <code class="literal">true</code> and <code class="literal">false</code>
</li>
</ul>
</div>
<div class="position-relative"><h5><a id="condition-examples"></a>Condition examples</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-conditions.asciidoc">edit</a></div>
<p>Run only when a specific label is included.</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">arrayContains(${docker.labels}, 'monitor')</pre>
</div>
<p>Skip on Linux platform or macOS.</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">${host.platform} != "linux" and ${host.platform} != "darwin"</pre>
</div>
<p>Run only for specific labels.</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">arrayContains(${docker.labels}, 'monitor') or arrayContains(${docker.label}, 'production')</pre>
</div>
<div class="position-relative"><h5><a id="condition-function-reference"></a>Function reference</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p>The condition syntax supports the following functions.</p>
<div class="position-relative"><h6><a id="add-function"></a><code class="literal">add</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">add(Number, Number) Number</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">add(1, 2) == 3
add(5, ${foo}) >= 5</pre>
</div>
<div class="position-relative"><h6><a id="arrayContains-function"></a><code class="literal">arrayContains</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">arrayContains(Array, String) Boolean</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">arrayContains(${docker.labels}, 'monitor')</pre>
</div>
<div class="position-relative"><h6><a id="concat-function"></a><code class="literal">concat</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">concat(String, String) String</code></p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Parameters are coerced into strings before the concatenation.</p>
</div>
</div>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">concat("foo", "bar") == "foobar"
concat(${var1}, ${var2}) != "foobar"</pre>
</div>
<div class="position-relative"><h6><a id="divide-function"></a><code class="literal">divide</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">divide(Number, Number) Number</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">divide(25, 5) > 0
divide(${var1}, ${var2}) > 7</pre>
</div>
<div class="position-relative"><h6><a id="endsWith-function"></a><code class="literal">endsWith</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">endsWith(String, String) Boolean</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">endsWith("hello world", "hello") == true
endsWith(${var1}, "hello") != true</pre>
</div>
<div class="position-relative"><h6><a id="hasKey-function"></a><code class="literal">hasKey</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">hasKey(Dictionary, String) Boolean</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">hasKey(${host}, "platform")</pre>
</div>
<div class="position-relative"><h6><a id="indexOf-function"></a><code class="literal">indexOf</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">indexOf(String, String, Number?) Number</code></p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Returns -1 if the string is not found.</p>
</div>
</div>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">indexOf("hello", "llo") == 2
indexOf(${var1}, "hello") >= 0</pre>
</div>
<div class="position-relative"><h6><a id="length-function"></a><code class="literal">length</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">length(Array|Dictionary|string)</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">length("foobar") > 2
length(${docker.labels}) > 0
length(${host}) > 2</pre>
</div>
<div class="position-relative"><h6><a id="match-function"></a><code class="literal">match</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">match(String, Regexp) boolean</code></p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p><code class="literal">Regexp</code> supports Go’s regular expression syntax. Conditions that use
regular expressions are more expensive to run. If speed is critical, consider
using <code class="literal">endWiths</code> or <code class="literal">startsWith</code>.</p>
</div>
</div>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">match("hello world", "^hello") == true
match(${var1}, "world$") == true</pre>
</div>
<div class="position-relative"><h6><a id="modulo-function"></a><code class="literal">modulo</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">modulo(number, number) Number</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">modulo(25, 5) > 0
modulo(${var1}, ${var2}) == 0</pre>
</div>
<div class="position-relative"><h6><a id="multiply-function"></a><code class="literal">multiply</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">multiply(Number, Number) Number</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">multiply(5, 5) == 25
multiple(${var1}, ${var2}) > x</pre>
</div>
<div class="position-relative"><h6><a id="number-function"></a><code class="literal">number</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">number(String) Integer</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">number("42") == 42
number(${var1}) == 42</pre>
</div>
<div class="position-relative"><h6><a id="startsWith-function"></a><code class="literal">startsWith</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">startsWith(String, String) Boolean</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">startsWith("hello world", "hello") == true
startsWith(${var1}, "hello") != true</pre>
</div>
<div class="position-relative"><h6><a id="string-function"></a><code class="literal">string</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">string(Number) String</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">string(42) == "42"
string(${var1}) == "42"</pre>
</div>
<div class="position-relative"><h6><a id="stringContains-function"></a><code class="literal">stringContains</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">stringContains(String, String) Boolean</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">stringContains("hello world", "hello") == true
stringContains(${var1}, "hello") != true</pre>
</div>
<div class="position-relative"><h6><a id="subtract-function"></a><code class="literal">subtract</code></h6><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-functions.asciidoc">edit</a></div>
<p><code class="literal">subtract(Number, Number) Number</code></p>
<p>Usage:</p>
<div class="pre_wrapper lang-eql">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-eql">subtract(5, 1) == 4
subtract(${foo}, 2) != 2</pre>
</div>
<div class="position-relative"><h5><a id="debug-configs"></a>Debugging</h5><a class="edit_me" rel="nofollow" title="Edit this page on GitHub" href="https://github.com/elastic/ingest-docs/edit/8.18/docs/en/ingest-management/elastic-agent/elastic-agent-debug-input-configs.asciidoc">edit</a></div>
<p>To debug configurations that include variable substitution and conditions, use
the <code class="literal">inspect</code> command. This command shows the configuration that’s generated
after variables are replaced and conditions are applied.</p>
<p>First run the Elastic Agent. For this example, we’ll use the following agent policy:</p>
<div class="pre_wrapper lang-yaml">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-yaml">outputs:
default:
type: elasticsearch
hosts: [127.0.0.1:9200]
apikey: <my-api-key>
providers:
local_dynamic:
items:
- vars:
key: value1
processors:
- add_fields:
fields:
custom: match1
target: dynamic
- vars:
key: value2
processors:
- add_fields:
fields:
custom: match2
target: dynamic
- vars:
key: value3
processors:
- add_fields:
fields:
custom: match3
target: dynamic
inputs:
- id: unique-logfile-id
type: logfile
enabled: true
streams:
- paths:
- /var/log/${local_dynamic.key}</pre>
</div>
<p>Then run <code class="literal">elastic-agent inspect --variables</code> to see the generated configuration. For
example:</p>
<div class="pre_wrapper lang-shell">
<div class="console_code_copy" title="Copy to clipboard"></div>
<pre class="programlisting prettyprint lang-shell">$ ./elastic-agent inspect --variables
inputs:
- enabled: true
id: unique-logfile-id-local_dynamic-0
original_id: unique-logfile-id
processors:
- add_fields:
fields:
custom: match1
target: dynamic
streams:
- paths:
- /var/log/value1
type: logfile
- enabled: true
id: unique-logfile-id-local_dynamic-1
original_id: unique-logfile-id
processors:
- add_fields:
fields:
custom: match2
target: dynamic
streams:
- paths:
- /var/log/value2
type: logfile
- enabled: true
id: unique-logfile-id-local_dynamic-2
original_id: unique-logfile-id
processors:
- add_fields:
fields:
custom: match3
target: dynamic
streams:
- paths:
- /var/log/value3
type: logfile
outputs:
default:
apikey: <my-api-key>
hosts:
- 127.0.0.1:9200
type: elasticsearch
providers:
local_dynamic:
items:
- processors:
- add_fields:
fields:
custom: match1
target: dynamic
vars:
key: value1
- processors:
- add_fields:
fields:
custom: match2
target: dynamic
vars:
key: value2
- processors:
- add_fields:
fields:
custom: match3
target: dynamic
vars:
key: value3
---</pre>
</div>
</div>
</div>
</div><div class="navfooter">
<span class="prev">
<a href="elastic-agent-inputs-list.html">« Elastic Agent inputs</a>
</span>
<span class="next">
<a href="providers.html">Configure providers for standalone Elastic Agents »</a>
</span>
</div>
<!-- end body -->
</div>
<div class="col-12 order-3 col-lg-2 order-lg-3 h-almost-full-lg sticky-top-lg" id="right_col">
<div id="sticky_content">
<!-- The OTP is appended here -->
<div class="row">
<div class="col-0 col-md-4 col-lg-0" id="bottom_left_col"></div>
<div class="col-12 col-md-8 col-lg-12">
<div id="rtpcontainer">
<div class="mktg-promo" id="most-popular">
<p class="aside-heading">Most Popular</p>
<div class="pb-2">
<p class="media-type">Video</p>
<a href="https://www.elastic.co/webinars/getting-started-elasticsearch?page=docs&placement=top-video">
<p class="mb-0">Get Started with Elasticsearch</p>
</a>
</div>
<div class="pb-2">
<p class="media-type">Video</p>
<a href="https://www.elastic.co/webinars/getting-started-kibana?page=docs&placement=top-video">
<p class="mb-0">Intro to Kibana</p>
</a>
</div>
<div class="pb-2">
<p class="media-type">Video</p>
<a href="https://www.elastic.co/webinars/introduction-elk-stack?page=docs&placement=top-video">
<p class="mb-0">ELK for Logs & Metrics</p>
</a>
</div>
</div>
</div>
<!-- Feedback widget -->
<div id="feedbackWidgetContainer"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<div id='elastic-footer'></div>
<script src='https://www.elastic.co/elastic-footer.js'></script>
<!-- Footer Section end-->
</section>
</div>
<!-- Feedback modal -->
<div id="feedbackModalContainer"></div>
<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs-v1.js"></script>
<script type="text/javascript">
window.initial_state = {}</script>
</body>
</html>