1
0

functions.asciidoc 32 KB

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