functions.asciidoc 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[eql-function-ref]]
  4. == EQL function reference
  5. ++++
  6. <titleabbrev>Function reference</titleabbrev>
  7. ++++
  8. beta::[]
  9. {es} supports the following <<eql-functions,EQL functions>>. Most EQL functions
  10. are case-sensitive by default.
  11. [discrete]
  12. [[eql-fn-add]]
  13. === `add`
  14. Returns the sum of two provided addends.
  15. *Example*
  16. [source,eql]
  17. ----
  18. add(4, 5) // returns 9
  19. add(4, 0.5) // returns 4.5
  20. add(0.5, 0.25) // returns 0.75
  21. add(4, -2) // returns 2
  22. add(-2, -2) // returns -4
  23. // process.args_count = 4
  24. add(process.args_count, 5) // returns 9
  25. add(process.args_count, 0.5) // returns 4.5
  26. // process.parent.args_count = 2
  27. add(process.args_count, process.parent.args_count) // returns 6
  28. // null handling
  29. add(null, 4) // returns null
  30. add(4. null) // returns null
  31. add(null, process.args_count) // returns null
  32. add(process.args_count null) // returns null
  33. ----
  34. *Syntax*
  35. [source,txt]
  36. ----
  37. add(<addend>, <addend>)
  38. ----
  39. *Parameters:*
  40. `<addend>`::
  41. (Required, integer or float or `null`)
  42. Addend to add. If `null`, the function returns `null`.
  43. +
  44. Two addends are required. No more than two addends can be provided.
  45. +
  46. If using a field as the argument, this parameter supports only
  47. <<number,`numeric`>> field data types.
  48. *Returns:* integer, float, or `null`
  49. [discrete]
  50. [[eql-fn-between]]
  51. === `between`
  52. Extracts a substring that's between a provided `left` and `right` text in a
  53. source string. Matching is case-sensitive.
  54. *Example*
  55. [source,eql]
  56. ----
  57. // file.path = "C:\\Windows\\System32\\cmd.exe"
  58. between(file.path, "system32\\\\", ".exe") // returns "cmd"
  59. between(file.path, "workspace\\\\", ".exe") // returns ""
  60. // Greedy matching defaults to false.
  61. between(file.path, "\\\\", "\\\\", false) // returns "Windows"
  62. // Sets greedy matching to true
  63. between(file.path, "\\\\", "\\\\", true) // returns "Windows\\System32"
  64. // empty source string
  65. between("", "system32\\\\", ".exe") // returns ""
  66. between("", "", "") // returns ""
  67. // null handling
  68. between(null, "system32\\\\", ".exe") // returns null
  69. ----
  70. *Syntax*
  71. [source,txt]
  72. ----
  73. between(<source>, <left>, <right>[, <greedy_matching>])
  74. ----
  75. *Parameters*
  76. `<source>`::
  77. +
  78. --
  79. (Required, string or `null`)
  80. Source string. Empty strings return an empty string (`""`), regardless of the
  81. `<left>` or `<right>` parameters. If `null`, the function returns `null`.
  82. If using a field as the argument, this parameter supports only the following
  83. field data types:
  84. * A type in the <<keyword,`keyword`>> family
  85. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  86. --
  87. `<left>`::
  88. +
  89. --
  90. (Required, string)
  91. Text to the left of the substring to extract. This text should include
  92. whitespace.
  93. If using a field as the argument, this parameter supports only the following
  94. field data types:
  95. * A type in the <<keyword,`keyword`>> family
  96. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  97. --
  98. `<right>`::
  99. +
  100. --
  101. (Required, string)
  102. Text to the right of the substring to extract. This text should include
  103. whitespace.
  104. If using a field as the argument, this parameter supports only the following
  105. field data types:
  106. * A type in the <<keyword,`keyword`>> family
  107. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  108. --
  109. `<greedy_matching>`::
  110. (Optional, Boolean)
  111. If `true`, match the longest possible substring, similar to `.*` in regular
  112. expressions. If `false`, match the shortest possible substring, similar to `.*?`
  113. in regular expressions. Defaults to `false`.
  114. *Returns:* string or `null`
  115. [discrete]
  116. [[eql-fn-cidrmatch]]
  117. === `cidrMatch`
  118. Returns `true` if an IP address is contained in one or more provided
  119. {wikipedia}/Classless_Inter-Domain_Routing[CIDR] blocks.
  120. *Example*
  121. [source,eql]
  122. ----
  123. // source.address = "192.168.152.12"
  124. cidrMatch(source.address, "192.168.0.0/16") // returns true
  125. cidrMatch(source.address, "192.168.0.0/16", "10.0.0.0/8") // returns true
  126. cidrMatch(source.address, "10.0.0.0/8") // returns false
  127. cidrMatch(source.address, "10.0.0.0/8", "10.128.0.0/9") // returns false
  128. // null handling
  129. cidrMatch(null, "10.0.0.0/8") // returns null
  130. cidrMatch(source.address, null) // returns null
  131. ----
  132. *Syntax*
  133. [source,txt]
  134. ----
  135. `cidrMatch(<ip_address>, <cidr_block>[, ...])`
  136. ----
  137. *Parameters*
  138. `<ip_address>`::
  139. (Required, string or `null`)
  140. IP address. Supports
  141. {wikipedia}/IPv4[IPv4] and
  142. {wikipedia}/IPv6[IPv6] addresses. If `null`, the function
  143. returns `null`.
  144. +
  145. If using a field as the argument, this parameter supports only the <<ip,`ip`>>
  146. field data type.
  147. `<cidr_block>`::
  148. (Required{multi-arg}, string or `null`)
  149. CIDR block you wish to search. If `null`, the function returns `null`.
  150. *Returns:* boolean or `null`
  151. [discrete]
  152. [[eql-fn-concat]]
  153. === `concat`
  154. Returns a concatenated string of provided values.
  155. *Example*
  156. [source,eql]
  157. ----
  158. concat("process is ", "regsvr32.exe") // returns "process is regsvr32.exe"
  159. concat("regsvr32.exe", " ", 42) // returns "regsvr32.exe 42"
  160. concat("regsvr32.exe", " ", 42.5) // returns "regsvr32.exe 42.5"
  161. concat("regsvr32.exe", " ", true) // returns "regsvr32.exe true"
  162. concat("regsvr32.exe") // returns "regsvr32.exe"
  163. // process.name = "regsvr32.exe"
  164. concat(process.name, " ", 42) // returns "regsvr32.exe 42"
  165. concat(process.name, " ", 42.5) // returns "regsvr32.exe 42.5"
  166. concat("process is ", process.name) // returns "process is regsvr32.exe"
  167. concat(process.name, " ", true) // returns "regsvr32.exe true"
  168. concat(process.name) // returns "regsvr32.exe"
  169. // process.arg_count = 4
  170. concat(process.name, " ", process.arg_count) // returns "regsvr32.exe 4"
  171. // null handling
  172. concat(null, "regsvr32.exe") // returns null
  173. concat(process.name, null) // returns null
  174. concat(null) // returns null
  175. ----
  176. *Syntax*
  177. [source,txt]
  178. ----
  179. concat(<value>[, <value>])
  180. ----
  181. *Parameters*
  182. `<value>`::
  183. (Required{multi-arg-ref})
  184. Value to concatenate. If any of the arguments are `null`, the function returns `null`.
  185. +
  186. If using a field as the argument, this parameter does not support the
  187. <<text,`text`>> field data type.
  188. *Returns:* string or `null`
  189. [discrete]
  190. [[eql-fn-divide]]
  191. === `divide`
  192. Returns the quotient of a provided dividend and divisor.
  193. [[eql-divide-fn-float-rounding]]
  194. [WARNING]
  195. ====
  196. If both the dividend and divisor are integers, the `divide` function _rounds
  197. down_ any returned floating point numbers to the nearest integer. To avoid
  198. rounding, convert either the dividend or divisor to a float.
  199. [%collapsible]
  200. .**Example**
  201. =====
  202. The `process.args_count` field is a <<number,`long`>> integer field containing a
  203. count of process arguments.
  204. A user might expect the following EQL query to only match events with a
  205. `process.args_count` value of `4`.
  206. [source,eql]
  207. ----
  208. process where divide(4, process.args_count) == 1
  209. ----
  210. However, the EQL query matches events with a `process.args_count` value of `3`
  211. or `4`.
  212. For events with a `process.args_count` value of `3`, the `divide` function
  213. returns a floating point number of `1.333...`, which is rounded down to `1`.
  214. To match only events with a `process.args_count` value of `4`, convert
  215. either the dividend or divisor to a float.
  216. The following EQL query changes the integer `4` to the equivalent float `4.0`.
  217. [source,eql]
  218. ----
  219. process where divide(4.0, process.args_count) == 1
  220. ----
  221. =====
  222. ====
  223. *Example*
  224. [source,eql]
  225. ----
  226. divide(4, 2) // returns 2
  227. divide(4, 3) // returns 1
  228. divide(4, 3.0) // returns 1.333...
  229. divide(4, 0.5) // returns 8
  230. divide(0.5, 4) // returns 0.125
  231. divide(0.5, 0.25) // returns 2.0
  232. divide(4, -2) // returns -2
  233. divide(-4, -2) // returns 2
  234. // process.args_count = 4
  235. divide(process.args_count, 2) // returns 2
  236. divide(process.args_count, 3) // returns 1
  237. divide(process.args_count, 3.0) // returns 1.333...
  238. divide(12, process.args_count) // returns 3
  239. divide(process.args_count, 0.5) // returns 8
  240. divide(0.5, process.args_count) // returns 0.125
  241. // process.parent.args_count = 2
  242. divide(process.args_count, process.parent.args_count) // returns 2
  243. // null handling
  244. divide(null, 4) // returns null
  245. divide(4, null) // returns null
  246. divide(null, process.args_count) // returns null
  247. divide(process.args_count, null) // returns null
  248. ----
  249. *Syntax*
  250. [source,txt]
  251. ----
  252. divide(<dividend>, <divisor>)
  253. ----
  254. *Parameters*
  255. `<dividend>`::
  256. (Required, integer or float or `null`)
  257. Dividend to divide. If `null`, the function returns `null`.
  258. +
  259. If using a field as the argument, this parameter supports only
  260. <<number,`numeric`>> field data types.
  261. `<divisor>`::
  262. (Required, integer or float or `null`)
  263. Divisor to divide by. If `null`, the function returns `null`. This value cannot
  264. be zero (`0`).
  265. +
  266. If using a field as the argument, this parameter supports only
  267. <<number,`numeric`>> field data types.
  268. *Returns:* integer, float, or null
  269. [discrete]
  270. [[eql-fn-endswith]]
  271. === `endsWith`
  272. Returns `true` if a source string ends with a provided substring. Matching is
  273. case-sensitive.
  274. *Example*
  275. [source,eql]
  276. ----
  277. endsWith("regsvr32.exe", ".exe") // returns true
  278. endsWith("regsvr32.exe", ".dll") // returns false
  279. endsWith("", "") // returns true
  280. // file.name = "regsvr32.exe"
  281. endsWith(file.name, ".exe") // returns true
  282. endsWith(file.name, ".dll") // returns false
  283. // file.extension = ".exe"
  284. endsWith("regsvr32.exe", file.extension) // returns true
  285. endsWith("ntdll.dll", file.name) // returns false
  286. // null handling
  287. endsWith("regsvr32.exe", null) // returns null
  288. endsWith("", null) // returns null
  289. endsWith(null, ".exe") // returns null
  290. endsWith(null, null) // returns null
  291. ----
  292. *Syntax*
  293. [source,txt]
  294. ----
  295. endsWith(<source>, <substring>)
  296. ----
  297. *Parameters*
  298. `<source>`::
  299. +
  300. --
  301. (Required, string or `null`)
  302. Source string. If `null`, the function returns `null`.
  303. If using a field as the argument, this parameter supports only the following
  304. field data types:
  305. * A type in the <<keyword,`keyword`>> family
  306. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  307. --
  308. `<substring>`::
  309. +
  310. --
  311. (Required, string or `null`)
  312. Substring to search for. If `null`, the function returns `null`.
  313. If using a field as the argument, this parameter supports only the following
  314. field data types:
  315. * A type in the <<keyword,`keyword`>> family
  316. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  317. --
  318. *Returns:* boolean or `null`
  319. [discrete]
  320. [[eql-fn-indexof]]
  321. === `indexOf`
  322. Returns the first position of a provided substring in a source string. Matching
  323. is case-sensitive.
  324. If an optional start position is provided, this function returns the first
  325. occurrence of the substring at or after the start position.
  326. *Example*
  327. [source,eql]
  328. ----
  329. // url.domain = "subdomain.example.com"
  330. indexOf(url.domain, ".") // returns 9
  331. indexOf(url.domain, ".", 9) // returns 9
  332. indexOf(url.domain, ".", 10) // returns 17
  333. indexOf(url.domain, ".", -6) // returns 9
  334. // empty strings
  335. indexOf("", "") // returns 0
  336. indexOf(url.domain, "") // returns 0
  337. indexOf(url.domain, "", 9) // returns 9
  338. indexOf(url.domain, "", 10) // returns 10
  339. indexOf(url.domain, "", -6) // returns 0
  340. // missing substrings
  341. indexOf(url.domain, "z") // returns null
  342. indexOf(url.domain, "z", 9) // returns null
  343. // start position is higher than string length
  344. indexOf(url.domain, ".", 30) // returns null
  345. // null handling
  346. indexOf(null, ".", 9) // returns null
  347. indexOf(url.domain, null, 9) // returns null
  348. indexOf(url.domain, ".", null) // returns null
  349. ----
  350. *Syntax*
  351. [source,txt]
  352. ----
  353. indexOf(<source>, <substring>[, <start_pos>])
  354. ----
  355. *Parameters*
  356. `<source>`::
  357. +
  358. --
  359. (Required, string or `null`)
  360. Source string. If `null`, the function returns `null`.
  361. If using a field as the argument, this parameter supports only the following
  362. field data types:
  363. * A type in the <<keyword,`keyword`>> family
  364. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  365. --
  366. `<substring>`::
  367. +
  368. --
  369. (Required, string or `null`)
  370. Substring to search for.
  371. If this argument is `null` or the `<source>` string does not contain this
  372. substring, the function returns `null`.
  373. If the `<start_pos>` is positive, empty strings (`""`) return the `<start_pos>`.
  374. Otherwise, empty strings return `0`.
  375. If using a field as the argument, this parameter supports only the following
  376. field data types:
  377. * A type in the <<keyword,`keyword`>> family
  378. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  379. --
  380. `<start_pos>`::
  381. +
  382. --
  383. (Optional, integer or `null`)
  384. Starting position for matching. The function will not return positions before
  385. this one. Defaults to `0`.
  386. Positions are zero-indexed. Negative offsets are treated as `0`.
  387. If this argument is `null` or higher than the length of the `<source>` string,
  388. the function returns `null`.
  389. If using a field as the argument, this parameter supports only the following
  390. <<number,numeric>> field data types:
  391. * `long`
  392. * `integer`
  393. * `short`
  394. * `byte`
  395. --
  396. *Returns:* integer or `null`
  397. [discrete]
  398. [[eql-fn-length]]
  399. === `length`
  400. Returns the character length of a provided string, including whitespace and
  401. punctuation.
  402. *Example*
  403. [source,eql]
  404. ----
  405. length("explorer.exe") // returns 12
  406. length("start explorer.exe") // returns 18
  407. length("") // returns 0
  408. length(null) // returns null
  409. // process.name = "regsvr32.exe"
  410. length(process.name) // returns 12
  411. ----
  412. *Syntax*
  413. [source,txt]
  414. ----
  415. length(<string>)
  416. ----
  417. *Parameters*
  418. `<string>`::
  419. +
  420. --
  421. (Required, string or `null`)
  422. String for which to return the character length. If `null`, the function returns
  423. `null`. Empty strings return `0`.
  424. If using a field as the argument, this parameter supports only the following
  425. field data types:
  426. * A type in the <<keyword,`keyword`>> family
  427. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  428. --
  429. *Returns:* integer or `null`
  430. [discrete]
  431. [[eql-fn-modulo]]
  432. === `modulo`
  433. Returns the remainder of the division of a provided dividend and divisor.
  434. *Example*
  435. [source,eql]
  436. ----
  437. modulo(10, 6) // returns 4
  438. modulo(10, 5) // returns 0
  439. modulo(10, 0.5) // returns 0
  440. modulo(10, -6) // returns 4
  441. modulo(-10, -6) // returns -4
  442. // process.args_count = 10
  443. modulo(process.args_count, 6) // returns 4
  444. modulo(process.args_count, 5) // returns 0
  445. modulo(106, process.args_count) // returns 6
  446. modulo(process.args_count, -6) // returns 4
  447. modulo(process.args_count, 0.5) // returns 0
  448. // process.parent.args_count = 6
  449. add(process.args_count, process.parent.args_count) // returns 4
  450. // null handling
  451. modulo(null, 5) // returns null
  452. modulo(7, null) // returns null
  453. modulo(null, process.args_count) // returns null
  454. modulo(process.args_count, null) // returns null
  455. ----
  456. *Syntax*
  457. [source,txt]
  458. ----
  459. modulo(<dividend>, <divisor>)
  460. ----
  461. *Parameters*
  462. `<dividend>`::
  463. (Required, integer or float or `null`)
  464. Dividend to divide. If `null`, the function returns `null`. Floating point
  465. numbers return `0`.
  466. +
  467. If using a field as the argument, this parameter supports only
  468. <<number,`numeric`>> field data types.
  469. `<divisor>`::
  470. (Required, integer or float or `null`)
  471. Divisor to divide by. If `null`, the function returns `null`. Floating point
  472. numbers return `0`. This value cannot be zero (`0`).
  473. +
  474. If using a field as the argument, this parameter supports only
  475. <<number,`numeric`>> field data types.
  476. *Returns:* integer, float, or `null`
  477. [discrete]
  478. [[eql-fn-multiply]]
  479. === `multiply`
  480. Returns the product of two provided factors.
  481. *Example*
  482. [source,eql]
  483. ----
  484. multiply(2, 2) // returns 4
  485. multiply(0.5, 2) // returns 1
  486. multiply(0.25, 2) // returns 0.5
  487. multiply(-2, 2) // returns -4
  488. multiply(-2, -2) // returns 4
  489. // process.args_count = 2
  490. multiply(process.args_count, 2) // returns 4
  491. multiply(0.5, process.args_count) // returns 1
  492. multiply(0.25, process.args_count) // returns 0.5
  493. // process.parent.args_count = 3
  494. multiply(process.args_count, process.parent.args_count) // returns 6
  495. // null handling
  496. multiply(null, 2) // returns null
  497. multiply(2, null) // returns null
  498. ----
  499. *Syntax*
  500. [source,txt]
  501. ----
  502. multiply(<factor, <factor>)
  503. ----
  504. *Parameters*
  505. `<factor>`::
  506. +
  507. --
  508. (Required, integer or float or `null`)
  509. Factor to multiply. If `null`, the function returns `null`.
  510. Two factors are required. No more than two factors can be provided.
  511. If using a field as the argument, this parameter supports only
  512. <<number,`numeric`>> field data types.
  513. --
  514. *Returns:* integer, float, or `null`
  515. [discrete]
  516. [[eql-fn-number]]
  517. === `number`
  518. Converts a string to the corresponding integer or float.
  519. *Example*
  520. [source,eql]
  521. ----
  522. number("1337") // returns 1337
  523. number("42.5") // returns 42.5
  524. number("deadbeef", 16) // returns 3735928559
  525. // integer literals beginning with "0x" are auto-detected as hexadecimal
  526. number("0xdeadbeef") // returns 3735928559
  527. number("0xdeadbeef", 16) // returns 3735928559
  528. // "+" and "-" are supported
  529. number("+1337") // returns 1337
  530. number("-1337") // returns -1337
  531. // surrounding whitespace is ignored
  532. number(" 1337 ") // returns 1337
  533. // process.pid = "1337"
  534. number(process.pid) // returns 1337
  535. // null handling
  536. number(null) // returns null
  537. number(null, 16) // returns null
  538. // strings beginning with "0x" are treated as hexadecimal (base 16),
  539. // even if the <base_num> is explicitly null.
  540. number("0xdeadbeef", null) // returns 3735928559
  541. // otherwise, strings are treated as decimal (base 10)
  542. // if the <base_num> is explicitly null.
  543. number("1337", null) // returns 1337
  544. ----
  545. *Syntax*
  546. [source,txt]
  547. ----
  548. number(<string>[, <base_num>])
  549. ----
  550. *Parameters*
  551. `<string>`::
  552. +
  553. --
  554. (Required, string or `null`)
  555. String to convert to an integer or float. If this value is a string, it must be
  556. one of the following:
  557. * A string representation of an integer (e.g., `"42"`)
  558. * A string representation of a float (e.g., `"9.5"`)
  559. * If the `<base_num>` parameter is specified, a string containing an integer
  560. literal in the base notation (e.g., `"0xDECAFBAD"` in hexadecimal or base
  561. `16`)
  562. Strings that begin with `0x` are auto-detected as hexadecimal and use a default
  563. `<base_num>` of `16`.
  564. `-` and `+` are supported with no space between. Surrounding whitespace is
  565. ignored. Empty strings (`""`) are not supported.
  566. If using a field as the argument, this parameter supports only the following
  567. field data types:
  568. * A type in the <<keyword,`keyword`>> family
  569. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  570. If this argument is `null`, the function returns `null`.
  571. --
  572. `<base_num>`::
  573. +
  574. --
  575. (Optional, integer or `null`)
  576. Radix or base used to convert the string. If the `<string>` begins with `0x`,
  577. this parameter defaults to `16` (hexadecimal). Otherwise, it defaults to base
  578. `10`.
  579. If this argument is explicitly `null`, the default value is used.
  580. Fields are not supported as arguments.
  581. --
  582. *Returns:* integer or float or `null`
  583. [discrete]
  584. [[eql-fn-startswith]]
  585. === `startsWith`
  586. Returns `true` if a source string begins with a provided substring. Matching is
  587. case-sensitive.
  588. *Example*
  589. [source,eql]
  590. ----
  591. startsWith("regsvr32.exe", "regsvr32") // returns true
  592. startsWith("regsvr32.exe", "explorer") // returns false
  593. startsWith("", "") // returns true
  594. // process.name = "regsvr32.exe"
  595. startsWith(process.name, "regsvr32") // returns true
  596. startsWith(process.name, "explorer") // returns false
  597. // process.name = "regsvr32"
  598. startsWith("regsvr32.exe", process.name) // returns true
  599. startsWith("explorer.exe", process.name) // returns false
  600. // null handling
  601. startsWith("regsvr32.exe", null) // returns null
  602. startsWith("", null) // returns null
  603. startsWith(null, "regsvr32") // returns null
  604. startsWith(null, null) // returns null
  605. ----
  606. *Syntax*
  607. [source,txt]
  608. ----
  609. startsWith(<source>, <substring>)
  610. ----
  611. *Parameters*
  612. `<source>`::
  613. +
  614. --
  615. (Required, string or `null`)
  616. Source string. If `null`, the function returns `null`.
  617. If using a field as the argument, this parameter supports only the following
  618. field data types:
  619. * A type in the <<keyword,`keyword`>> family
  620. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  621. --
  622. `<substring>`::
  623. +
  624. --
  625. (Required, string or `null`)
  626. Substring to search for. If `null`, the function returns `null`.
  627. If using a field as the argument, this parameter supports only the following
  628. field data types:
  629. * A type in the <<keyword,`keyword`>> family
  630. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  631. --
  632. *Returns:* boolean or `null`
  633. [discrete]
  634. [[eql-fn-string]]
  635. === `string`
  636. Converts a value to a string.
  637. *Example*
  638. [source,eql]
  639. ----
  640. string(42) // returns "42"
  641. string(42.5) // returns "42.5"
  642. string("regsvr32.exe") // returns "regsvr32.exe"
  643. string(true) // returns "true"
  644. // null handling
  645. string(null) // returns null
  646. ----
  647. *Syntax*
  648. [source,txt]
  649. ----
  650. string(<value>)
  651. ----
  652. *Parameters*
  653. `<value>`::
  654. (Required)
  655. Value to convert to a string. If `null`, the function returns `null`.
  656. +
  657. If using a field as the argument, this parameter does not support the
  658. <<text,`text`>> field data type.
  659. *Returns:* string or `null`
  660. [discrete]
  661. [[eql-fn-stringcontains]]
  662. === `stringContains`
  663. Returns `true` if a source string contains a provided substring. Matching is
  664. case-sensitive.
  665. *Example*
  666. [source,eql]
  667. ----
  668. // process.command_line = "start regsvr32.exe"
  669. stringContains(process.command_line, "regsvr32") // returns true
  670. stringContains(process.command_line, "start ") // returns true
  671. stringContains(process.command_line, "explorer") // returns false
  672. // process.name = "regsvr32.exe"
  673. stringContains(command_line, process.name) // returns true
  674. // empty strings
  675. stringContains("", "") // returns false
  676. stringContains(process.command_line, "") // returns false
  677. // null handling
  678. stringContains(null, "regsvr32") // returns null
  679. stringContains(process.command_line, null) // returns null
  680. ----
  681. *Syntax*
  682. [source,txt]
  683. ----
  684. stringContains(<source>, <substring>)
  685. ----
  686. *Parameters*
  687. `<source>`::
  688. (Required, string or `null`)
  689. Source string to search. If `null`, the function returns `null`.
  690. If using a field as the argument, this parameter supports only the following
  691. field data types:
  692. * A type in the <<keyword,`keyword`>> family
  693. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  694. `<substring>`::
  695. (Required, string or `null`)
  696. Substring to search for. If `null`, the function returns `null`.
  697. If using a field as the argument, this parameter supports only the following
  698. field data types:
  699. * A type in the <<keyword,`keyword`>> family
  700. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  701. *Returns:* boolean or `null`
  702. [discrete]
  703. [[eql-fn-substring]]
  704. === `substring`
  705. Extracts a substring from a source string at provided start and end positions.
  706. If no end position is provided, the function extracts the remaining string.
  707. *Example*
  708. [source,eql]
  709. ----
  710. substring("start regsvr32.exe", 6) // returns "regsvr32.exe"
  711. substring("start regsvr32.exe", 0, 5) // returns "start"
  712. substring("start regsvr32.exe", 6, 14) // returns "regsvr32"
  713. substring("start regsvr32.exe", -4) // returns ".exe"
  714. substring("start regsvr32.exe", -4, -1) // returns ".ex"
  715. ----
  716. *Syntax*
  717. [source,txt]
  718. ----
  719. substring(<source>, <start_pos>[, <end_pos>])
  720. ----
  721. *Parameters*
  722. `<source>`::
  723. (Required, string)
  724. Source string.
  725. `<start_pos>`::
  726. +
  727. --
  728. (Required, integer)
  729. Starting position for extraction.
  730. If this position is higher than the `<end_pos>` position or the length of the
  731. `<source>` string, the function returns an empty string.
  732. Positions are zero-indexed. Negative offsets are supported.
  733. --
  734. `<end_pos>`::
  735. (Optional, integer)
  736. Exclusive end position for extraction. If this position is not provided, the
  737. function returns the remaining string.
  738. +
  739. Positions are zero-indexed. Negative offsets are supported.
  740. *Returns:* string
  741. [discrete]
  742. [[eql-fn-subtract]]
  743. === `subtract`
  744. Returns the difference between a provided minuend and subtrahend.
  745. *Example*
  746. [source,eql]
  747. ----
  748. subtract(10, 2) // returns 8
  749. subtract(10.5, 0.5) // returns 10
  750. subtract(1, 0.2) // returns 0.8
  751. subtract(-2, 4) // returns -8
  752. subtract(-2, -4) // returns 8
  753. // process.args_count = 10
  754. subtract(process.args_count, 6) // returns 4
  755. subtract(process.args_count, 5) // returns 5
  756. subtract(15, process.args_count) // returns 5
  757. subtract(process.args_count, 0.5) // returns 9.5
  758. // process.parent.args_count = 6
  759. subtract(process.args_count, process.parent.args_count) // returns 4
  760. // null handling
  761. subtract(null, 2) // returns null
  762. subtract(2, null) // returns null
  763. ----
  764. *Syntax*
  765. [source,txt]
  766. ----
  767. subtract(<minuend>, <subtrahend>)
  768. ----
  769. *Parameters*
  770. `<minuend>`::
  771. (Required, integer or float or `null`)
  772. Minuend to subtract from.
  773. +
  774. If using a field as the argument, this parameter supports only
  775. <<number,`numeric`>> field data types.
  776. `<subtrahend>`::
  777. (Optional, integer or float or `null`)
  778. Subtrahend to subtract. If `null`, the function returns `null`.
  779. +
  780. If using a field as the argument, this parameter supports only
  781. <<number,`numeric`>> field data types.
  782. *Returns:* integer, float, or `null`
  783. [discrete]
  784. [[eql-fn-wildcard]]
  785. === `wildcard`
  786. Returns `true` if a source string matches one or more provided wildcard
  787. expressions. Matching is case-sensitive.
  788. *Example*
  789. [source,eql]
  790. ----
  791. // The * wildcard matches zero or more characters.
  792. // process.name = "regsvr32.exe"
  793. wildcard(process.name, "*regsvr32*") // returns true
  794. wildcard(process.name, "*regsvr32*", "*explorer*") // returns true
  795. wildcard(process.name, "*explorer*") // returns false
  796. wildcard(process.name, "*explorer*", "*scrobj*") // returns false
  797. // The ? wildcard matches exactly one character.
  798. // process.name = "regsvr32.exe"
  799. wildcard(process.name, "regsvr32.e?e") // returns true
  800. wildcard(process.name, "regsvr32.e?e", "e?plorer.exe") // returns true
  801. wildcard(process.name, "regsvr32.exe?") // returns false
  802. wildcard(process.name, "e?plorer.exe") // returns false
  803. wildcard(process.name, "e?plorer.exe", "scrob?.dll") // returns false
  804. // empty strings
  805. wildcard("", "*start*") // returns false
  806. wildcard("", "*") // returns true
  807. wildcard("", "?") // returns false
  808. wildcard("", "") // returns true
  809. // null handling
  810. wildcard(null, "*regsvr32*") // returns null
  811. wildcard(process.name, null) // returns null
  812. ----
  813. *Syntax*
  814. [source,txt]
  815. ----
  816. wildcard(<source>, <wildcard_exp>[, ...])
  817. ----
  818. *Parameters*
  819. `<source>`::
  820. +
  821. --
  822. (Required, string)
  823. Source string. If `null`, the function returns `null`.
  824. If using a field as the argument, this parameter supports only the following
  825. field data types:
  826. * A type in the <<keyword,`keyword`>> family
  827. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  828. --
  829. `<wildcard_exp>`::
  830. +
  831. --
  832. (Required{multi-arg-ref}, string)
  833. Wildcard expression used to match the source string. The `*` wildcard matches
  834. zero or more characters. The `?` wildcard matches exactly one character.
  835. If `null`, the function returns `null`. Fields are not supported as arguments.
  836. --
  837. *Returns:* boolean