1
0

functions.asciidoc 28 KB

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