functions.asciidoc 32 KB

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