functions.asciidoc 29 KB

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