functions.asciidoc 30 KB

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