functions.asciidoc 32 KB

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