functions.asciidoc 32 KB

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