Skip to content

Commit 09cac46

Browse files
committed
macro Operator docs
1 parent 9e13e05 commit 09cac46

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

cid-redirects.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,7 @@
18701870
"/cid/2008": "/docs/send-data/installed-collectors/linux",
18711871
"/cid/2009": "/docs/search/logcompare",
18721872
"/cid/2010": "/docs/search/search-query-language/search-operators/if",
1873+
"/cid/2110": "/docs/search/search-query-language/search-operators/macro",
18731874
"/cid/2011": "/docs/get-started/help",
18741875
"/cid/2012": "/docs/manage/security/enable-support-account",
18751876
"/cid/2013": "/docs/send-data/installed-collectors/sources/windows-active-directory-inventory-source",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
id: macro
3+
title: macro Operator
4+
sidebar_label: macro
5+
---
6+
import useBaseUrl from '@docusaurus/useBaseUrl';
7+
8+
With `macro` operator you can reuse the portions of search query language in multiple other queries. This operator also includes arguments and also performs its respective evaluation of the arguments.
9+
10+
Use backquote (``) charater to refer macro operator in the query. Macros referred inside another macro is called **Nested macros**. Macro referred within the context of another macro query of is called **Inner Macro**. The macro where the inner macro is reffered is called the **Outer Macro**.
11+
12+
:::note
13+
- Only **Administrators** and **Users** with access to **Query Reference** will be able to run queries using macros.
14+
- Only users with **Administrator** access can create or delete the macro.
15+
:::
16+
17+
## Syntax
18+
19+
```
20+
`<macro name>`
21+
```
22+
23+
## Add a macro
24+
25+
To create a macro follow the steps below:
26+
27+
1. [**Classic UI**](/docs/get-started/sumo-logic-ui-classic). In the main Sumo Logic menu, select **Manage Data** > **Logs** > **Macros**. <br/> [**New UI**](/docs/get-started/sumo-logic-ui/). In the top menu, select **Manage Date**, and then under **Logs**, select **Macros**. You can also click the **Go To...** menu at the top of the screen and select **Macros**.
28+
1. Click **+ Add Macro**.<br/><img src={useBaseUrl('img/search/searchquerylanguage/search-operators/macro-logs-page.png')} alt="macro-logs-page" style={{border: '1px solid gray'}} width="800" />
29+
1. Or, in the log search page, select the part of search query language that needs to be reused and click on **Create Macro**.<br/><img src={useBaseUrl('img/search/searchquerylanguage/search-operators/macro-search-page.png')} alt="macro-search-page" style={{border: '1px solid gray'}} width="800" />
30+
1. **Macro Details**. Enter the name for the macro. Description is optional.
31+
1. **Macro Definition**. Enter the definition for the macro. To add arguments use the `{{Arg}}` syntax or select a part of the definition and click on **Add Argument**.
32+
1. (Optional)**Arguments**. Enter the name and select the data type for the argument selcted.
33+
1. (Optional)**Argument Validation**. Define the validation condition and enter the error message that needs to be shown when the validation expression returns false.
34+
1. **Usage**. Preview of how you use the macro in the log search.
35+
1. Click **Submit** to save the macro.
36+
37+
### Limitations
38+
39+
- You can create a maximum of 50 macros.
40+
- You can add a maximum of 5 definitions.
41+
42+
### Example
43+
44+
Consider the below query that search for the errors with timeslice of 5 minutes.
45+
46+
```
47+
_sourceCategory=error | timeslice 5m
48+
| count by _timeslice
49+
```
50+
51+
Now by creating macro for the timeslice field, the query with the `macro` operator is modified as:
52+
53+
```
54+
_sourceCategory=error | `timeslice_macro`
55+
```

sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ module.exports = {
13801380
'search/search-query-language/search-operators/lookup-classic',
13811381
'search/search-query-language/search-operators/lookupcontains',
13821382
'search/search-query-language/search-operators/luhn',
1383+
'search/search-query-language/search-operators/macro',
13831384
'search/search-query-language/search-operators/manually-cast-data-string-number',
13841385
'search/search-query-language/search-operators/matches',
13851386
'search/search-query-language/search-operators/now',
269 KB
Loading
44.9 KB
Loading

0 commit comments

Comments
 (0)