1 | /**
|
2 | * Interface for objects that can render themselves to log patterns.
|
3 | */
|
4 | export interface IFilterPattern {
|
5 | readonly logPatternString: string;
|
6 | }
|
7 | /**
|
8 | * Base class for patterns that only match JSON log events.
|
9 | */
|
10 | export declare abstract class JsonPattern implements IFilterPattern {
|
11 | readonly jsonPatternString: string;
|
12 | constructor(jsonPatternString: string);
|
13 | get logPatternString(): string;
|
14 | }
|
15 | /**
|
16 | * A collection of static methods to generate appropriate ILogPatterns
|
17 | */
|
18 | export declare class FilterPattern {
|
19 | /**
|
20 | * Use the given string as log pattern.
|
21 | *
|
22 | * See https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
|
23 | * for information on writing log patterns.
|
24 | *
|
25 | * @param logPatternString The pattern string to use.
|
26 | */
|
27 | static literal(logPatternString: string): IFilterPattern;
|
28 | /**
|
29 | * A log pattern that matches all events.
|
30 | */
|
31 | static allEvents(): IFilterPattern;
|
32 | /**
|
33 | * A log pattern that matches if all the strings given appear in the event.
|
34 | *
|
35 | * @param terms The words to search for. All terms must match.
|
36 | */
|
37 | static allTerms(...terms: string[]): IFilterPattern;
|
38 | /**
|
39 | * A log pattern that matches if any of the strings given appear in the event.
|
40 | *
|
41 | * @param terms The words to search for. Any terms must match.
|
42 | */
|
43 | static anyTerm(...terms: string[]): IFilterPattern;
|
44 | /**
|
45 | * A log pattern that matches if any of the given term groups matches the event.
|
46 | *
|
47 | * A term group matches an event if all the terms in it appear in the event string.
|
48 | *
|
49 | * @param termGroups A list of term groups to search for. Any one of the clauses must match.
|
50 | */
|
51 | static anyTermGroup(...termGroups: string[][]): IFilterPattern;
|
52 | /**
|
53 | * A JSON log pattern that compares string values.
|
54 | *
|
55 | * This pattern only matches if the event is a JSON event, and the indicated field inside
|
56 | * compares with the string value.
|
57 | *
|
58 | * Use '$' to indicate the root of the JSON structure. The comparison operator can only
|
59 | * compare equality or inequality. The '*' wildcard may appear in the value may at the
|
60 | * start or at the end.
|
61 | *
|
62 | * For more information, see:
|
63 | *
|
64 | * https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
|
65 | *
|
66 | * @param jsonField Field inside JSON. Example: "$.myField"
|
67 | * @param comparison Comparison to carry out. Either = or !=.
|
68 | * @param value The string value to compare to. May use '*' as wildcard at start or end of string.
|
69 | */
|
70 | static stringValue(jsonField: string, comparison: string, value: string): JsonPattern;
|
71 | /**
|
72 | * A JSON log pattern that compares numerical values.
|
73 | *
|
74 | * This pattern only matches if the event is a JSON event, and the indicated field inside
|
75 | * compares with the value in the indicated way.
|
76 | *
|
77 | * Use '$' to indicate the root of the JSON structure. The comparison operator can only
|
78 | * compare equality or inequality. The '*' wildcard may appear in the value may at the
|
79 | * start or at the end.
|
80 | *
|
81 | * For more information, see:
|
82 | *
|
83 | * https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
|
84 | *
|
85 | * @param jsonField Field inside JSON. Example: "$.myField"
|
86 | * @param comparison Comparison to carry out. One of =, !=, <, <=, >, >=.
|
87 | * @param value The numerical value to compare to
|
88 | */
|
89 | static numberValue(jsonField: string, comparison: string, value: number): JsonPattern;
|
90 | /**
|
91 | * A JSON log pattern that matches if the field exists and has the special value 'null'.
|
92 | *
|
93 | * @param jsonField Field inside JSON. Example: "$.myField"
|
94 | */
|
95 | static isNull(jsonField: string): JsonPattern;
|
96 | /**
|
97 | * A JSON log pattern that matches if the field does not exist.
|
98 | *
|
99 | * @param jsonField Field inside JSON. Example: "$.myField"
|
100 | */
|
101 | static notExists(jsonField: string): JsonPattern;
|
102 | /**
|
103 | * A JSON log patter that matches if the field exists.
|
104 | *
|
105 | * This is a readable convenience wrapper over 'field = *'
|
106 | *
|
107 | * @param jsonField Field inside JSON. Example: "$.myField"
|
108 | */
|
109 | static exists(jsonField: string): JsonPattern;
|
110 | /**
|
111 | * A JSON log pattern that matches if the field exists and equals the boolean value.
|
112 | *
|
113 | * @param jsonField Field inside JSON. Example: "$.myField"
|
114 | * @param value The value to match
|
115 | */
|
116 | static booleanValue(jsonField: string, value: boolean): JsonPattern;
|
117 | /**
|
118 | * A JSON log pattern that matches if all given JSON log patterns match
|
119 | */
|
120 | static all(...patterns: JsonPattern[]): JsonPattern;
|
121 | /**
|
122 | * A JSON log pattern that matches if any of the given JSON log patterns match
|
123 | */
|
124 | static any(...patterns: JsonPattern[]): JsonPattern;
|
125 | /**
|
126 | * A space delimited log pattern matcher.
|
127 | *
|
128 | * The log event is divided into space-delimited columns (optionally
|
129 | * enclosed by "" or [] to capture spaces into column values), and names
|
130 | * are given to each column.
|
131 | *
|
132 | * '...' may be specified once to match any number of columns.
|
133 | *
|
134 | * Afterwards, conditions may be added to individual columns.
|
135 | *
|
136 | * @param columns The columns in the space-delimited log stream.
|
137 | */
|
138 | static spaceDelimited(...columns: string[]): SpaceDelimitedTextPattern;
|
139 | }
|
140 | export declare type RestrictionMap = {
|
141 | [column: string]: ColumnRestriction[];
|
142 | };
|
143 | /**
|
144 | * Space delimited text pattern
|
145 | */
|
146 | export declare class SpaceDelimitedTextPattern implements IFilterPattern {
|
147 | private readonly columns;
|
148 | private readonly restrictions;
|
149 | /**
|
150 | * Construct a new instance of a space delimited text pattern
|
151 | *
|
152 | * Since this class must be public, we can't rely on the user only creating it through
|
153 | * the `LogPattern.spaceDelimited()` factory function. We must therefore validate the
|
154 | * argument in the constructor. Since we're returning a copy on every mutation, and we
|
155 | * don't want to re-validate the same things on every construction, we provide a limited
|
156 | * set of mutator functions and only validate the new data every time.
|
157 | */
|
158 | static construct(columns: string[]): SpaceDelimitedTextPattern;
|
159 | protected constructor(columns: string[], restrictions: RestrictionMap);
|
160 | /**
|
161 | * Restrict where the pattern applies
|
162 | */
|
163 | whereString(columnName: string, comparison: string, value: string): SpaceDelimitedTextPattern;
|
164 | /**
|
165 | * Restrict where the pattern applies
|
166 | */
|
167 | whereNumber(columnName: string, comparison: string, value: number): SpaceDelimitedTextPattern;
|
168 | get logPatternString(): string;
|
169 | /**
|
170 | * Return the column expression for the given column
|
171 | */
|
172 | private columnExpression;
|
173 | /**
|
174 | * Make a copy of the current restrictions and add one
|
175 | */
|
176 | private addRestriction;
|
177 | }
|
178 | export interface ColumnRestriction {
|
179 | /**
|
180 | * Comparison operator to use
|
181 | */
|
182 | readonly comparison: string;
|
183 | /**
|
184 | * String value to compare to
|
185 | *
|
186 | * Exactly one of 'stringValue' and 'numberValue' must be set.
|
187 | */
|
188 | readonly stringValue?: string;
|
189 | /**
|
190 | * Number value to compare to
|
191 | *
|
192 | * Exactly one of 'stringValue' and 'numberValue' must be set.
|
193 | */
|
194 | readonly numberValue?: number;
|
195 | }
|