functions.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. [[eql-function-ref]]
  2. == EQL function reference
  3. ++++
  4. <titleabbrev>Function reference</titleabbrev>
  5. ++++
  6. experimental::[]
  7. {es} supports the following EQL functions:
  8. * <<eql-fn-between>>
  9. * <<eql-fn-endswith>>
  10. * <<eql-fn-length>>
  11. * <<eql-fn-startswith>>
  12. * <<eql-fn-substring>>
  13. * <<eql-fn-wildcard>>
  14. [discrete]
  15. [[eql-fn-between]]
  16. === `between`
  17. Extracts a substring that's between a provided `left` and `right` text in a
  18. source string.
  19. [%collapsible]
  20. ====
  21. *Example*
  22. [source,eql]
  23. ----
  24. // file.path = "C:\\Windows\\System32\\cmd.exe"
  25. between(file.path, "system32\\\\", ".exe") // returns "cmd"
  26. between(file.path, "workspace\\\\", ".exe") // returns ""
  27. // Greedy matching defaults to false.
  28. between(file.path, "\\\\", "\\\\", false) // returns "Windows"
  29. // Sets greedy matching to true
  30. between(file.path, "\\\\", "\\\\", true) // returns "Windows\\System32"
  31. // Case sensitivity defaults to false.
  32. between(file.path, "system32\\\\", ".exe", false, false) // returns "cmd"
  33. // Sets case sensitivity to true
  34. between(file.path, "system32\\\\", ".exe", false, true) // returns ""
  35. between(file.path, "System32\\\\", ".exe", false, true) // returns "cmd"
  36. // empty source string
  37. between("", "system32\\\\", ".exe") // returns ""
  38. between("", "", "") // returns ""
  39. // null handling
  40. between(null, "system32\\\\", ".exe") // returns null
  41. ----
  42. *Syntax*
  43. [source,txt]
  44. ----
  45. between(<source>, <left>, <right>[, <greedy_matching>, <case_sensitive>])
  46. ----
  47. *Parameters*
  48. `<source>`::
  49. +
  50. --
  51. (Required, string or `null`)
  52. Source string. Empty strings return an empty string (`""`), regardless of the
  53. `<left>` or `<right>` parameters. If `null`, the function returns `null`.
  54. If using a field as the argument, this parameter only supports the following
  55. field datatypes:
  56. * <<keyword,`keyword`>>
  57. * <<constant-keyword,`constant_keyword`>>
  58. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  59. <<constant-keyword,`constant_keyword`>> sub-field
  60. Fields containing <<array,array values>> use the first array item only.
  61. --
  62. `<left>`::
  63. +
  64. --
  65. (Required, string)
  66. Text to the left of the substring to extract. This text should include
  67. whitespace.
  68. If using a field as the argument, this parameter only supports the following
  69. field datatypes:
  70. * <<keyword,`keyword`>>
  71. * <<constant-keyword,`constant_keyword`>>
  72. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  73. <<constant-keyword,`constant_keyword`>> sub-field
  74. <<array,Array values>> are not supported.
  75. --
  76. `<right>`::
  77. +
  78. --
  79. (Required, string)
  80. Text to the right of the substring to extract. This text should include
  81. whitespace.
  82. If using a field as the argument, this parameter only supports the following
  83. field datatypes:
  84. * <<keyword,`keyword`>>
  85. * <<constant-keyword,`constant_keyword`>>
  86. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  87. <<constant-keyword,`constant_keyword`>> sub-field
  88. <<array,Array values>> are not supported.
  89. --
  90. `<greedy_matching>`::
  91. (Optional, boolean)
  92. If `true`, match the longest possible substring, similar to `.*` in regular
  93. expressions. If `false`, match the shortest possible substring, similar to `.*?`
  94. in regular expressions. Defaults to `false`.
  95. `<case_sensitive>`::
  96. (Optional, boolean)
  97. If `true`, matching is case-sensitive. Defaults to `false`.
  98. *Returns:* string or `null`
  99. ====
  100. [discrete]
  101. [[eql-fn-endswith]]
  102. === `endsWith`
  103. Returns `true` if a source string ends with a provided substring. Matching is
  104. case insensitive.
  105. [%collapsible]
  106. ====
  107. *Example*
  108. [source,eql]
  109. ----
  110. endsWith("regsvr32.exe", ".exe") // returns true
  111. endsWith("regsvr32.exe", ".EXE") // returns true
  112. endsWith("regsvr32.exe", ".dll") // returns false
  113. endsWith("", "") // returns true
  114. // file.name = "regsvr32.exe"
  115. endsWith(file.name, ".exe") // returns true
  116. endsWith(file.name, ".dll") // returns false
  117. // file.extension = ".exe"
  118. endsWith("regsvr32.exe", file.extension) // returns true
  119. endsWith("ntdll.dll", file.name) // returns false
  120. // file.name = [ "ntdll.dll", "regsvr32.exe" ]
  121. endsWith(file.name, ".dll") // returns true
  122. endsWith(file.name, ".exe") // returns false
  123. // null handling
  124. endsWith("regsvr32.exe", null) // returns null
  125. endsWith("", null) // returns null
  126. endsWith(null, ".exe") // returns null
  127. endsWith(null, null) // returns null
  128. ----
  129. *Syntax*
  130. [source,txt]
  131. ----
  132. endsWith(<source>, <substring>)
  133. ----
  134. *Parameters*
  135. `<source>`::
  136. +
  137. --
  138. (Required, string or `null`)
  139. Source string. If `null`, the function returns `null`.
  140. If using a field as the argument, this parameter only supports the following
  141. field datatypes:
  142. * <<keyword,`keyword`>>
  143. * <<constant-keyword,`constant_keyword`>>
  144. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  145. <<constant-keyword,`constant_keyword`>> sub-field
  146. Fields containing <<array,array values>> use the first array item only.
  147. --
  148. `<substring>`::
  149. +
  150. --
  151. (Required, string or `null`)
  152. Substring to search for. If `null`, the function returns `null`.
  153. If using a field as the argument, this parameter only supports the following
  154. field datatypes:
  155. * <<keyword,`keyword`>>
  156. * <<constant-keyword,`constant_keyword`>>
  157. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  158. <<constant-keyword,`constant_keyword`>> sub-field
  159. --
  160. *Returns:* boolean or `null`
  161. ====
  162. [discrete]
  163. [[eql-fn-length]]
  164. === `length`
  165. Returns the character length of a provided string, including whitespace and
  166. punctuation.
  167. [%collapsible]
  168. ====
  169. *Example*
  170. [source,eql]
  171. ----
  172. length("explorer.exe") // returns 12
  173. length("start explorer.exe") // returns 18
  174. length("") // returns 0
  175. length(null) // returns null
  176. // process.name = "regsvr32.exe"
  177. length(process.name) // returns 12
  178. ----
  179. *Syntax*
  180. [source,txt]
  181. ----
  182. length(<string>)
  183. ----
  184. *Parameters*
  185. `<string>`::
  186. +
  187. --
  188. (Required, string or `null`)
  189. String for which to return the character length. If `null`, the function returns
  190. `null`. Empty strings return `0`.
  191. If using a field as the argument, this parameter only supports the following
  192. field datatypes:
  193. * <<keyword,`keyword`>>
  194. * <<constant-keyword,`constant_keyword`>>
  195. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  196. <<constant-keyword,`constant_keyword`>> sub-field
  197. <<array,Array values>> are not supported.
  198. --
  199. *Returns:* integer or `null`
  200. ====
  201. [discrete]
  202. [[eql-fn-startswith]]
  203. === `startsWith`
  204. Returns `true` if a source string begins with a provided substring. Matching is
  205. case insensitive.
  206. [%collapsible]
  207. ====
  208. *Example*
  209. [source,eql]
  210. ----
  211. startsWith("regsvr32.exe", "regsvr32") // returns true
  212. startsWith("regsvr32.exe", "RegSvr32") // returns true
  213. startsWith("regsvr32.exe", "explorer") // returns false
  214. startsWith("", "") // returns true
  215. // process.name = "regsvr32.exe"
  216. startsWith(process.name, "regsvr32") // returns true
  217. startsWith(process.name, "explorer") // returns false
  218. // process.name = "regsvr32"
  219. startsWith("regsvr32.exe", process.name) // returns true
  220. startsWith("explorer.exe", process.name) // returns false
  221. // process.name = [ "explorer.exe", "regsvr32.exe" ]
  222. startsWith(process.name, "explorer") // returns true
  223. startsWith(process.name, "regsvr32") // returns false
  224. // null handling
  225. startsWith("regsvr32.exe", null) // returns null
  226. startsWith("", null) // returns null
  227. startsWith(null, "regsvr32") // returns null
  228. startsWith(null, null) // returns null
  229. ----
  230. *Syntax*
  231. [source,txt]
  232. ----
  233. startsWith(<source>, <substring>)
  234. ----
  235. *Parameters*
  236. `<source>`::
  237. +
  238. --
  239. (Required, string or `null`)
  240. Source string. If `null`, the function returns `null`.
  241. If using a field as the argument, this parameter only supports the following
  242. field datatypes:
  243. * <<keyword,`keyword`>>
  244. * <<constant-keyword,`constant_keyword`>>
  245. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  246. <<constant-keyword,`constant_keyword`>> sub-field
  247. Fields containing <<array,array values>> use the first array item only.
  248. --
  249. `<substring>`::
  250. +
  251. --
  252. (Required, string or `null`)
  253. Substring to search for. If `null`, the function returns `null`.
  254. If using a field as the argument, this parameter only supports the following
  255. field datatypes:
  256. * <<keyword,`keyword`>>
  257. * <<constant-keyword,`constant_keyword`>>
  258. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  259. <<constant-keyword,`constant_keyword`>> sub-field
  260. --
  261. *Returns:* boolean or `null`
  262. ====
  263. [discrete]
  264. [[eql-fn-substring]]
  265. === `substring`
  266. Extracts a substring from a source string at provided start and end positions.
  267. If no end position is provided, the function extracts the remaining string.
  268. [%collapsible]
  269. ====
  270. *Example*
  271. [source,eql]
  272. ----
  273. substring("start regsvr32.exe", 6) // returns "regsvr32.exe"
  274. substring("start regsvr32.exe", 0, 5) // returns "start"
  275. substring("start regsvr32.exe", 6, 14) // returns "regsvr32"
  276. substring("start regsvr32.exe", -4) // returns ".exe"
  277. substring("start regsvr32.exe", -4, -1) // returns ".ex"
  278. ----
  279. *Syntax*
  280. [source,txt]
  281. ----
  282. substring(<source>, <start_pos>[, <end_pos>])
  283. ----
  284. *Parameters*
  285. `<source>`::
  286. (Required, string)
  287. Source string.
  288. `<start_pos>`::
  289. +
  290. --
  291. (Required, integer)
  292. Starting position for extraction.
  293. If this position is higher than the `<end_pos>` position or the length of the
  294. `<source>` string, the function returns an empty string.
  295. Positions are zero-indexed. Negative offsets are supported.
  296. --
  297. `<end_pos>`::
  298. (Optional, integer)
  299. Exclusive end position for extraction. If this position is not provided, the
  300. function returns the remaining string.
  301. +
  302. Positions are zero-indexed. Negative offsets are supported.
  303. *Returns:* string
  304. ====
  305. [discrete]
  306. [[eql-fn-wildcard]]
  307. === `wildcard`
  308. Returns `true` if a source string matches one or more provided wildcard
  309. expressions.
  310. [%collapsible]
  311. ====
  312. *Example*
  313. [source,eql]
  314. ----
  315. // The two following expressions are equivalent.
  316. process.name == "*regsvr32*" or process.name == "*explorer*"
  317. wildcard(process.name, "*regsvr32*", "*explorer*")
  318. // process.name = "regsvr32.exe"
  319. wildcard(process.name, "*regsvr32*") // returns true
  320. wildcard(process.name, "*regsvr32*", "*explorer*") // returns true
  321. wildcard(process.name, "*explorer*") // returns false
  322. wildcard(process.name, "*explorer*", "*scrobj*") // returns false
  323. // empty strings
  324. wildcard("", "*start*") // returns false
  325. wildcard("", "*") // returns true
  326. wildcard("", "") // returns true
  327. // null handling
  328. wildcard(null, "*regsvr32*") // returns null
  329. wildcard(process.name, null) // returns null
  330. ----
  331. *Syntax*
  332. [source,txt]
  333. ----
  334. wildcard(<source>, <wildcard_exp>[, ...])
  335. ----
  336. *Parameters*
  337. `<source>`::
  338. +
  339. --
  340. (Required, string)
  341. Source string. If `null`, the function returns `null`.
  342. If using a field as the argument, this parameter only supports the following
  343. field datatypes:
  344. * <<keyword,`keyword`>>
  345. * <<constant-keyword,`constant_keyword`>>
  346. * <<text,`text`>> field with a <<keyword,`keyword`>> or
  347. <<constant-keyword,`constant_keyword`>> sub-field
  348. --
  349. `<wildcard_exp>`::
  350. +
  351. --
  352. (Required{multi-arg}, string)
  353. Wildcard expression used to match the source string. If `null`, the function
  354. returns `null`. Fields are not supported as arguments.
  355. --
  356. *Returns:* boolean
  357. ====