functions.asciidoc 30 KB

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