functions.asciidoc 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  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,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.
  198. EQL queries in {es} should account for this rounding. To avoid rounding, convert
  199. either the dividend or divisor to a float.
  200. [%collapsible]
  201. .**Example**
  202. =====
  203. The `process.args_count` field is a <<number,`long`>> integer field containing a
  204. count of process arguments.
  205. A user might expect the following EQL query to only match events with a
  206. `process.args_count` value of `4`.
  207. [source,eql]
  208. ----
  209. process where divide(4, process.args_count) == 1
  210. ----
  211. However, the EQL query matches events with a `process.args_count` value of `3`
  212. or `4`.
  213. For events with a `process.args_count` value of `3`, the `divide` function
  214. returns a floating point number of `1.333...`, which is rounded down to `1`.
  215. To match only events with a `process.args_count` value of `4`, convert
  216. either the dividend or divisor to a float.
  217. The following EQL query changes the integer `4` to the equivalent float `4.0`.
  218. [source,eql]
  219. ----
  220. process where divide(4.0, process.args_count) == 1
  221. ----
  222. =====
  223. ====
  224. *Example*
  225. [source,eql]
  226. ----
  227. divide(4, 2) // returns 2
  228. divide(4, 3) // returns 1
  229. divide(4, 3.0) // returns 1.333...
  230. divide(4, 0.5) // returns 8
  231. divide(0.5, 4) // returns 0.125
  232. divide(0.5, 0.25) // returns 2.0
  233. divide(4, -2) // returns -2
  234. divide(-4, -2) // returns 2
  235. // process.args_count = 4
  236. divide(process.args_count, 2) // returns 2
  237. divide(process.args_count, 3) // returns 1
  238. divide(process.args_count, 3.0) // returns 1.333...
  239. divide(12, process.args_count) // returns 3
  240. divide(process.args_count, 0.5) // returns 8
  241. divide(0.5, process.args_count) // returns 0.125
  242. // process.parent.args_count = 2
  243. divide(process.args_count, process.parent.args_count) // returns 2
  244. // null handling
  245. divide(null, 4) // returns null
  246. divide(4, null) // returns null
  247. divide(null, process.args_count) // returns null
  248. divide(process.args_count, null) // returns null
  249. ----
  250. *Syntax*
  251. [source,txt]
  252. ----
  253. divide(<dividend>, <divisor>)
  254. ----
  255. *Parameters*
  256. `<dividend>`::
  257. (Required, integer or float or `null`)
  258. Dividend to divide. If `null`, the function returns `null`.
  259. +
  260. If using a field as the argument, this parameter supports only
  261. <<number,`numeric`>> field data types.
  262. `<divisor>`::
  263. (Required, integer or float or `null`)
  264. Divisor to divide by. If `null`, the function returns `null`. This value cannot
  265. be zero (`0`).
  266. +
  267. If using a field as the argument, this parameter supports only
  268. <<number,`numeric`>> field data types.
  269. *Returns:* integer, float, or null
  270. [discrete]
  271. [[eql-fn-endswith]]
  272. === `endsWith`
  273. Returns `true` if a source string ends with a provided substring. Matching is
  274. case-sensitive.
  275. *Example*
  276. [source,eql]
  277. ----
  278. endsWith("regsvr32.exe", ".exe") // returns true
  279. endsWith("regsvr32.exe", ".dll") // returns false
  280. endsWith("", "") // returns true
  281. // file.name = "regsvr32.exe"
  282. endsWith(file.name, ".exe") // returns true
  283. endsWith(file.name, ".dll") // returns false
  284. // file.extension = ".exe"
  285. endsWith("regsvr32.exe", file.extension) // returns true
  286. endsWith("ntdll.dll", file.name) // returns false
  287. // null handling
  288. endsWith("regsvr32.exe", null) // returns null
  289. endsWith("", null) // returns null
  290. endsWith(null, ".exe") // returns null
  291. endsWith(null, null) // returns null
  292. ----
  293. *Syntax*
  294. [source,txt]
  295. ----
  296. endsWith(<source>, <substring>)
  297. ----
  298. *Parameters*
  299. `<source>`::
  300. +
  301. --
  302. (Required, string or `null`)
  303. Source string. If `null`, the function returns `null`.
  304. If using a field as the argument, this parameter supports only the following
  305. field data types:
  306. * A type in the <<keyword,`keyword`>> family
  307. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  308. --
  309. `<substring>`::
  310. +
  311. --
  312. (Required, string or `null`)
  313. Substring to search for. If `null`, the function returns `null`.
  314. If using a field as the argument, this parameter supports only the following
  315. field data types:
  316. * A type in the <<keyword,`keyword`>> family
  317. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  318. --
  319. *Returns:* boolean or `null`
  320. [discrete]
  321. [[eql-fn-indexof]]
  322. === `indexOf`
  323. Returns the first position of a provided substring in a source string. Matching
  324. is case-sensitive.
  325. If an optional start position is provided, this function returns the first
  326. occurrence of the substring at or after the start position.
  327. *Example*
  328. [source,eql]
  329. ----
  330. // url.domain = "subdomain.example.com"
  331. indexOf(url.domain, ".") // returns 9
  332. indexOf(url.domain, ".", 9) // returns 9
  333. indexOf(url.domain, ".", 10) // returns 17
  334. indexOf(url.domain, ".", -6) // returns 9
  335. // empty strings
  336. indexOf("", "") // returns 0
  337. indexOf(url.domain, "") // returns 0
  338. indexOf(url.domain, "", 9) // returns 9
  339. indexOf(url.domain, "", 10) // returns 10
  340. indexOf(url.domain, "", -6) // returns 0
  341. // missing substrings
  342. indexOf(url.domain, "z") // returns null
  343. indexOf(url.domain, "z", 9) // returns null
  344. // start position is higher than string length
  345. indexOf(url.domain, ".", 30) // returns null
  346. // null handling
  347. indexOf(null, ".", 9) // returns null
  348. indexOf(url.domain, null, 9) // returns null
  349. indexOf(url.domain, ".", null) // returns null
  350. ----
  351. *Syntax*
  352. [source,txt]
  353. ----
  354. indexOf(<source>, <substring>[, <start_pos>])
  355. ----
  356. *Parameters*
  357. `<source>`::
  358. +
  359. --
  360. (Required, string or `null`)
  361. Source string. If `null`, the function returns `null`.
  362. If using a field as the argument, this parameter supports only the following
  363. field data types:
  364. * A type in the <<keyword,`keyword`>> family
  365. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  366. --
  367. `<substring>`::
  368. +
  369. --
  370. (Required, string or `null`)
  371. Substring to search for.
  372. If this argument is `null` or the `<source>` string does not contain this
  373. substring, the function returns `null`.
  374. If the `<start_pos>` is positive, empty strings (`""`) return the `<start_pos>`.
  375. Otherwise, empty strings return `0`.
  376. If using a field as the argument, this parameter supports only the following
  377. field data types:
  378. * A type in the <<keyword,`keyword`>> family
  379. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  380. --
  381. `<start_pos>`::
  382. +
  383. --
  384. (Optional, integer or `null`)
  385. Starting position for matching. The function will not return positions before
  386. this one. Defaults to `0`.
  387. Positions are zero-indexed. Negative offsets are treated as `0`.
  388. If this argument is `null` or higher than the length of the `<source>` string,
  389. the function returns `null`.
  390. If using a field as the argument, this parameter supports only the following
  391. <<number,numeric>> field data types:
  392. * `long`
  393. * `integer`
  394. * `short`
  395. * `byte`
  396. --
  397. *Returns:* integer or `null`
  398. [discrete]
  399. [[eql-fn-length]]
  400. === `length`
  401. Returns the character length of a provided string, including whitespace and
  402. punctuation.
  403. *Example*
  404. [source,eql]
  405. ----
  406. length("explorer.exe") // returns 12
  407. length("start explorer.exe") // returns 18
  408. length("") // returns 0
  409. length(null) // returns null
  410. // process.name = "regsvr32.exe"
  411. length(process.name) // returns 12
  412. ----
  413. *Syntax*
  414. [source,txt]
  415. ----
  416. length(<string>)
  417. ----
  418. *Parameters*
  419. `<string>`::
  420. +
  421. --
  422. (Required, string or `null`)
  423. String for which to return the character length. If `null`, the function returns
  424. `null`. Empty strings return `0`.
  425. If using a field as the argument, this parameter supports only the following
  426. field data types:
  427. * A type in the <<keyword,`keyword`>> family
  428. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  429. --
  430. *Returns:* integer or `null`
  431. [discrete]
  432. [[eql-fn-match]]
  433. === `match`
  434. Returns `true` if a source string matches one or more provided regular
  435. expressions. Matching is case-sensitive.
  436. *Example*
  437. [source,eql]
  438. ----
  439. match("explorer.exe", "[a-z]*?.exe") // returns true
  440. match("explorer.exe", "[a-z]*?.exe", "[1-9]") // returns true
  441. match("explorer.exe", "[1-9]") // returns false
  442. match("explorer.exe", "") // returns false
  443. // process.name = "explorer.exe"
  444. match(process.name, "[a-z]*?.exe") // returns true
  445. match(process.name, "[a-z]*?.exe", "[1-9]") // returns true
  446. match(process.name, "[1-9]") // returns false
  447. match(process.name, "") // returns false
  448. // null handling
  449. match(null, "[a-z]*?.exe") // returns null
  450. ----
  451. *Syntax*
  452. [source,txt]
  453. ----
  454. match(<source>, <reg_exp>[, ...])
  455. ----
  456. *Parameters*
  457. `<source>`::
  458. +
  459. --
  460. (Required, string or `null`)
  461. Source string. If `null`, the function returns `null`.
  462. If using a field as the argument, this parameter supports only the following
  463. field data types:
  464. * A type in the <<keyword,`keyword`>> family
  465. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  466. --
  467. `<reg_exp>`::
  468. +
  469. --
  470. (Required{multi-arg-ref}, string)
  471. Regular expression used to match the source string. For supported syntax, see
  472. <<regexp-syntax>>.
  473. https://docs.oracle.com/javase/tutorial/essential/regex/pre_char_classes.html[Predefined
  474. character classes] are not supported.
  475. Fields are not supported as arguments.
  476. --
  477. *Returns:* boolean or `null`
  478. [discrete]
  479. [[eql-fn-modulo]]
  480. === `modulo`
  481. Returns the remainder of the division of a provided dividend and divisor.
  482. *Example*
  483. [source,eql]
  484. ----
  485. modulo(10, 6) // returns 4
  486. modulo(10, 5) // returns 0
  487. modulo(10, 0.5) // returns 0
  488. modulo(10, -6) // returns 4
  489. modulo(-10, -6) // returns -4
  490. // process.args_count = 10
  491. modulo(process.args_count, 6) // returns 4
  492. modulo(process.args_count, 5) // returns 0
  493. modulo(106, process.args_count) // returns 6
  494. modulo(process.args_count, -6) // returns 4
  495. modulo(process.args_count, 0.5) // returns 0
  496. // process.parent.args_count = 6
  497. add(process.args_count, process.parent.args_count) // returns 4
  498. // null handling
  499. modulo(null, 5) // returns null
  500. modulo(7, null) // returns null
  501. modulo(null, process.args_count) // returns null
  502. modulo(process.args_count, null) // returns null
  503. ----
  504. *Syntax*
  505. [source,txt]
  506. ----
  507. modulo(<dividend>, <divisor>)
  508. ----
  509. *Parameters*
  510. `<dividend>`::
  511. (Required, integer or float or `null`)
  512. Dividend to divide. If `null`, the function returns `null`. Floating point
  513. numbers return `0`.
  514. +
  515. If using a field as the argument, this parameter supports only
  516. <<number,`numeric`>> field data types.
  517. `<divisor>`::
  518. (Required, integer or float or `null`)
  519. Divisor to divide by. If `null`, the function returns `null`. Floating point
  520. numbers return `0`. This value cannot be zero (`0`).
  521. +
  522. If using a field as the argument, this parameter supports only
  523. <<number,`numeric`>> field data types.
  524. *Returns:* integer, float, or `null`
  525. [discrete]
  526. [[eql-fn-multiply]]
  527. === `multiply`
  528. Returns the product of two provided factors.
  529. *Example*
  530. [source,eql]
  531. ----
  532. multiply(2, 2) // returns 4
  533. multiply(0.5, 2) // returns 1
  534. multiply(0.25, 2) // returns 0.5
  535. multiply(-2, 2) // returns -4
  536. multiply(-2, -2) // returns 4
  537. // process.args_count = 2
  538. multiply(process.args_count, 2) // returns 4
  539. multiply(0.5, process.args_count) // returns 1
  540. multiply(0.25, process.args_count) // returns 0.5
  541. // process.parent.args_count = 3
  542. multiply(process.args_count, process.parent.args_count) // returns 6
  543. // null handling
  544. multiply(null, 2) // returns null
  545. multiply(2, null) // returns null
  546. ----
  547. *Syntax*
  548. [source,txt]
  549. ----
  550. multiply(<factor, <factor>)
  551. ----
  552. *Parameters*
  553. `<factor>`::
  554. +
  555. --
  556. (Required, integer or float or `null`)
  557. Factor to multiply. If `null`, the function returns `null`.
  558. Two factors are required. No more than two factors can be provided.
  559. If using a field as the argument, this parameter supports only
  560. <<number,`numeric`>> field data types.
  561. --
  562. *Returns:* integer, float, or `null`
  563. [discrete]
  564. [[eql-fn-number]]
  565. === `number`
  566. Converts a string to the corresponding integer or float.
  567. *Example*
  568. [source,eql]
  569. ----
  570. number("1337") // returns 1337
  571. number("42.5") // returns 42.5
  572. number("deadbeef", 16) // returns 3735928559
  573. // integer literals beginning with "0x" are auto-detected as hexadecimal
  574. number("0xdeadbeef") // returns 3735928559
  575. number("0xdeadbeef", 16) // returns 3735928559
  576. // "+" and "-" are supported
  577. number("+1337") // returns 1337
  578. number("-1337") // returns -1337
  579. // surrounding whitespace is ignored
  580. number(" 1337 ") // returns 1337
  581. // process.pid = "1337"
  582. number(process.pid) // returns 1337
  583. // null handling
  584. number(null) // returns null
  585. number(null, 16) // returns null
  586. // strings beginning with "0x" are treated as hexadecimal (base 16),
  587. // even if the <base_num> is explicitly null.
  588. number("0xdeadbeef", null) // returns 3735928559
  589. // otherwise, strings are treated as decimal (base 10)
  590. // if the <base_num> is explicitly null.
  591. number("1337", null) // returns 1337
  592. ----
  593. *Syntax*
  594. [source,txt]
  595. ----
  596. number(<string>[, <base_num>])
  597. ----
  598. *Parameters*
  599. `<string>`::
  600. +
  601. --
  602. (Required, string or `null`)
  603. String to convert to an integer or float. If this value is a string, it must be
  604. one of the following:
  605. * A string representation of an integer (e.g., `"42"`)
  606. * A string representation of a float (e.g., `"9.5"`)
  607. * If the `<base_num>` parameter is specified, a string containing an integer
  608. literal in the base notation (e.g., `"0xDECAFBAD"` in hexadecimal or base
  609. `16`)
  610. Strings that begin with `0x` are auto-detected as hexadecimal and use a default
  611. `<base_num>` of `16`.
  612. `-` and `+` are supported with no space between. Surrounding whitespace is
  613. ignored. Empty strings (`""`) are not supported.
  614. If using a field as the argument, this parameter supports only the following
  615. field data types:
  616. * A type in the <<keyword,`keyword`>> family
  617. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  618. If this argument is `null`, the function returns `null`.
  619. --
  620. `<base_num>`::
  621. +
  622. --
  623. (Optional, integer or `null`)
  624. Radix or base used to convert the string. If the `<string>` begins with `0x`,
  625. this parameter defaults to `16` (hexadecimal). Otherwise, it defaults to base
  626. `10`.
  627. If this argument is explicitly `null`, the default value is used.
  628. Fields are not supported as arguments.
  629. --
  630. *Returns:* integer or float or `null`
  631. [discrete]
  632. [[eql-fn-startswith]]
  633. === `startsWith`
  634. Returns `true` if a source string begins with a provided substring. Matching is
  635. case-sensitive.
  636. *Example*
  637. [source,eql]
  638. ----
  639. startsWith("regsvr32.exe", "regsvr32") // returns true
  640. startsWith("regsvr32.exe", "explorer") // returns false
  641. startsWith("", "") // returns true
  642. // process.name = "regsvr32.exe"
  643. startsWith(process.name, "regsvr32") // returns true
  644. startsWith(process.name, "explorer") // returns false
  645. // process.name = "regsvr32"
  646. startsWith("regsvr32.exe", process.name) // returns true
  647. startsWith("explorer.exe", process.name) // returns false
  648. // null handling
  649. startsWith("regsvr32.exe", null) // returns null
  650. startsWith("", null) // returns null
  651. startsWith(null, "regsvr32") // returns null
  652. startsWith(null, null) // returns null
  653. ----
  654. *Syntax*
  655. [source,txt]
  656. ----
  657. startsWith(<source>, <substring>)
  658. ----
  659. *Parameters*
  660. `<source>`::
  661. +
  662. --
  663. (Required, string or `null`)
  664. Source string. If `null`, the function returns `null`.
  665. If using a field as the argument, this parameter supports only the following
  666. field data types:
  667. * A type in the <<keyword,`keyword`>> family
  668. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  669. --
  670. `<substring>`::
  671. +
  672. --
  673. (Required, string or `null`)
  674. Substring to search for. If `null`, the function returns `null`.
  675. If using a field as the argument, this parameter supports only the following
  676. field data types:
  677. * A type in the <<keyword,`keyword`>> family
  678. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  679. --
  680. *Returns:* boolean or `null`
  681. [discrete]
  682. [[eql-fn-string]]
  683. === `string`
  684. Converts a value to a string.
  685. *Example*
  686. [source,eql]
  687. ----
  688. string(42) // returns "42"
  689. string(42.5) // returns "42.5"
  690. string("regsvr32.exe") // returns "regsvr32.exe"
  691. string(true) // returns "true"
  692. // null handling
  693. string(null) // returns null
  694. ----
  695. *Syntax*
  696. [source,txt]
  697. ----
  698. string(<value>)
  699. ----
  700. *Parameters*
  701. `<value>`::
  702. (Required)
  703. Value to convert to a string. If `null`, the function returns `null`.
  704. +
  705. If using a field as the argument, this parameter does not support the
  706. <<text,`text`>> field data type.
  707. *Returns:* string or `null`
  708. [discrete]
  709. [[eql-fn-stringcontains]]
  710. === `stringContains`
  711. Returns `true` if a source string contains a provided substring. Matching is
  712. case-sensitive.
  713. *Example*
  714. [source,eql]
  715. ----
  716. // process.command_line = "start regsvr32.exe"
  717. stringContains(process.command_line, "regsvr32") // returns true
  718. stringContains(process.command_line, "start ") // returns true
  719. stringContains(process.command_line, "explorer") // returns false
  720. // process.name = "regsvr32.exe"
  721. stringContains(command_line, process.name) // returns true
  722. // empty strings
  723. stringContains("", "") // returns false
  724. stringContains(process.command_line, "") // returns false
  725. // null handling
  726. stringContains(null, "regsvr32") // returns null
  727. stringContains(process.command_line, null) // returns null
  728. ----
  729. *Syntax*
  730. [source,txt]
  731. ----
  732. stringContains(<source>, <substring>)
  733. ----
  734. *Parameters*
  735. `<source>`::
  736. (Required, string or `null`)
  737. Source string to search. If `null`, the function returns `null`.
  738. If using a field as the argument, this parameter supports only the following
  739. field data types:
  740. * A type in the <<keyword,`keyword`>> family
  741. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  742. `<substring>`::
  743. (Required, string or `null`)
  744. Substring to search for. If `null`, the function returns `null`.
  745. If using a field as the argument, this parameter supports only the following
  746. field data types:
  747. * A type in the <<keyword,`keyword`>> family
  748. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  749. *Returns:* boolean or `null`
  750. [discrete]
  751. [[eql-fn-substring]]
  752. === `substring`
  753. Extracts a substring from a source string at provided start and end positions.
  754. If no end position is provided, the function extracts the remaining string.
  755. *Example*
  756. [source,eql]
  757. ----
  758. substring("start regsvr32.exe", 6) // returns "regsvr32.exe"
  759. substring("start regsvr32.exe", 0, 5) // returns "start"
  760. substring("start regsvr32.exe", 6, 14) // returns "regsvr32"
  761. substring("start regsvr32.exe", -4) // returns ".exe"
  762. substring("start regsvr32.exe", -4, -1) // returns ".ex"
  763. ----
  764. *Syntax*
  765. [source,txt]
  766. ----
  767. substring(<source>, <start_pos>[, <end_pos>])
  768. ----
  769. *Parameters*
  770. `<source>`::
  771. (Required, string)
  772. Source string.
  773. `<start_pos>`::
  774. +
  775. --
  776. (Required, integer)
  777. Starting position for extraction.
  778. If this position is higher than the `<end_pos>` position or the length of the
  779. `<source>` string, the function returns an empty string.
  780. Positions are zero-indexed. Negative offsets are supported.
  781. --
  782. `<end_pos>`::
  783. (Optional, integer)
  784. Exclusive end position for extraction. If this position is not provided, the
  785. function returns the remaining string.
  786. +
  787. Positions are zero-indexed. Negative offsets are supported.
  788. *Returns:* string
  789. [discrete]
  790. [[eql-fn-subtract]]
  791. === `subtract`
  792. Returns the difference between a provided minuend and subtrahend.
  793. *Example*
  794. [source,eql]
  795. ----
  796. subtract(10, 2) // returns 8
  797. subtract(10.5, 0.5) // returns 10
  798. subtract(1, 0.2) // returns 0.8
  799. subtract(-2, 4) // returns -8
  800. subtract(-2, -4) // returns 8
  801. // process.args_count = 10
  802. subtract(process.args_count, 6) // returns 4
  803. subtract(process.args_count, 5) // returns 5
  804. subtract(15, process.args_count) // returns 5
  805. subtract(process.args_count, 0.5) // returns 9.5
  806. // process.parent.args_count = 6
  807. subtract(process.args_count, process.parent.args_count) // returns 4
  808. // null handling
  809. subtract(null, 2) // returns null
  810. subtract(2, null) // returns null
  811. ----
  812. *Syntax*
  813. [source,txt]
  814. ----
  815. subtract(<minuend>, <subtrahend>)
  816. ----
  817. *Parameters*
  818. `<minuend>`::
  819. (Required, integer or float or `null`)
  820. Minuend to subtract from.
  821. +
  822. If using a field as the argument, this parameter supports only
  823. <<number,`numeric`>> field data types.
  824. `<subtrahend>`::
  825. (Optional, integer or float or `null`)
  826. Subtrahend to subtract. If `null`, the function returns `null`.
  827. +
  828. If using a field as the argument, this parameter supports only
  829. <<number,`numeric`>> field data types.
  830. *Returns:* integer, float, or `null`
  831. [discrete]
  832. [[eql-fn-wildcard]]
  833. === `wildcard`
  834. Returns `true` if a source string matches one or more provided wildcard
  835. expressions. Matching is case-sensitive.
  836. *Example*
  837. [source,eql]
  838. ----
  839. // The two following expressions are equivalent.
  840. process.name == "*regsvr32*" or process.name == "*explorer*"
  841. wildcard(process.name, "*regsvr32*", "*explorer*")
  842. // process.name = "regsvr32.exe"
  843. wildcard(process.name, "*regsvr32*") // returns true
  844. wildcard(process.name, "*regsvr32*", "*explorer*") // returns true
  845. wildcard(process.name, "*explorer*") // returns false
  846. wildcard(process.name, "*explorer*", "*scrobj*") // returns false
  847. // empty strings
  848. wildcard("", "*start*") // returns false
  849. wildcard("", "*") // returns true
  850. wildcard("", "") // returns true
  851. // null handling
  852. wildcard(null, "*regsvr32*") // returns null
  853. wildcard(process.name, null) // returns null
  854. ----
  855. *Syntax*
  856. [source,txt]
  857. ----
  858. wildcard(<source>, <wildcard_exp>[, ...])
  859. ----
  860. *Parameters*
  861. `<source>`::
  862. +
  863. --
  864. (Required, string)
  865. Source string. If `null`, the function returns `null`.
  866. If using a field as the argument, this parameter supports only the following
  867. field data types:
  868. * A type in the <<keyword,`keyword`>> family
  869. * <<text,`text`>> field with a <<keyword,`keyword`>> sub-field
  870. --
  871. `<wildcard_exp>`::
  872. +
  873. --
  874. (Required{multi-arg-ref}, string)
  875. Wildcard expression used to match the source string. If `null`, the function
  876. returns `null`. Fields are not supported as arguments.
  877. --
  878. *Returns:* boolean