functions.asciidoc 28 KB

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