@spl2dql/core 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/README.md +58 -2
- package/dist/commands/combine.d.ts +8 -0
- package/dist/commands/combine.js +260 -0
- package/dist/commands/extract.d.ts +4 -0
- package/dist/commands/extract.js +142 -0
- package/dist/commands/fields.d.ts +24 -0
- package/dist/commands/fields.js +518 -0
- package/dist/commands/filter.d.ts +14 -0
- package/dist/commands/filter.js +221 -0
- package/dist/commands/generating.d.ts +11 -0
- package/dist/commands/generating.js +403 -0
- package/dist/commands/order.d.ts +8 -0
- package/dist/commands/order.js +250 -0
- package/dist/commands/registry.d.ts +10 -0
- package/dist/commands/registry.js +44 -0
- package/dist/commands/stats.d.ts +14 -0
- package/dist/commands/stats.js +563 -0
- package/dist/commands/types.d.ts +16 -0
- package/dist/commands/types.js +14 -0
- package/dist/dashboard/convert.d.ts +80 -0
- package/dist/dashboard/convert.js +703 -0
- package/dist/dashboard/markdown.d.ts +42 -0
- package/dist/dashboard/markdown.js +412 -0
- package/dist/dashboard/model.d.ts +78 -0
- package/dist/dashboard/model.js +8 -0
- package/dist/dashboard/simple-xml.d.ts +11 -0
- package/dist/dashboard/simple-xml.js +348 -0
- package/dist/dashboard/studio.d.ts +5 -0
- package/dist/dashboard/studio.js +285 -0
- package/dist/dashboard/tokens.d.ts +19 -0
- package/dist/dashboard/tokens.js +105 -0
- package/dist/dashboard/xml.d.ts +25 -0
- package/dist/dashboard/xml.js +209 -0
- package/dist/diagnostics/collector.d.ts +27 -0
- package/dist/diagnostics/collector.js +64 -0
- package/dist/diagnostics/registry.d.ts +14 -0
- package/dist/diagnostics/registry.js +81 -0
- package/dist/dql/ast.d.ts +152 -0
- package/dist/dql/ast.js +63 -0
- package/dist/dql/catalog.generated.d.ts +2 -0
- package/dist/dql/catalog.generated.js +268 -0
- package/dist/dql/check.d.ts +19 -0
- package/dist/dql/check.js +63 -0
- package/dist/dql/lexer.d.ts +12 -0
- package/dist/dql/lexer.js +149 -0
- package/dist/dql/parser.d.ts +34 -0
- package/dist/dql/parser.js +322 -0
- package/dist/dql/printer.d.ts +34 -0
- package/dist/dql/printer.js +269 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/io/conf.d.ts +17 -0
- package/dist/io/conf.js +76 -0
- package/dist/io/inputs.d.ts +28 -0
- package/dist/io/inputs.js +120 -0
- package/dist/io/splunk-config.d.ts +64 -0
- package/dist/io/splunk-config.js +396 -0
- package/dist/limits.d.ts +20 -0
- package/dist/limits.js +21 -0
- package/dist/lower/aggs.d.ts +46 -0
- package/dist/lower/aggs.js +247 -0
- package/dist/lower/context.d.ts +139 -0
- package/dist/lower/context.js +238 -0
- package/dist/lower/expr.d.ts +16 -0
- package/dist/lower/expr.js +556 -0
- package/dist/lower/pipeline.d.ts +25 -0
- package/dist/lower/pipeline.js +192 -0
- package/dist/lower/regex.d.ts +32 -0
- package/dist/lower/regex.js +639 -0
- package/dist/lower/search.d.ts +25 -0
- package/dist/lower/search.js +353 -0
- package/dist/lower/strftime.d.ts +8 -0
- package/dist/lower/strftime.js +63 -0
- package/dist/mapping/config.d.ts +9 -0
- package/dist/mapping/config.js +300 -0
- package/dist/needs.d.ts +21 -0
- package/dist/needs.js +76 -0
- package/dist/spl/expr.d.ts +50 -0
- package/dist/spl/expr.js +305 -0
- package/dist/spl/highlight.d.ts +11 -0
- package/dist/spl/highlight.js +100 -0
- package/dist/spl/macros.d.ts +19 -0
- package/dist/spl/macros.js +188 -0
- package/dist/spl/scanner.d.ts +72 -0
- package/dist/spl/scanner.js +234 -0
- package/dist/spl/search.d.ts +60 -0
- package/dist/spl/search.js +311 -0
- package/dist/spl/split.d.ts +23 -0
- package/dist/spl/split.js +115 -0
- package/dist/spl/time.d.ts +32 -0
- package/dist/spl/time.js +193 -0
- package/dist/translate.d.ts +30 -0
- package/dist/translate.js +328 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.js +2 -0
- package/dist/util/array.d.ts +5 -0
- package/dist/util/array.js +9 -0
- package/dist/util/dict.d.ts +6 -0
- package/dist/util/dict.js +12 -0
- package/dist/util/unique.d.ts +5 -0
- package/dist/util/unique.js +30 -0
- package/package.json +46 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
spl2dql
|
|
2
|
+
Copyright 2026 the spl2dql contributors
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
It includes, under third_party/dynatrace-for-ai/, files from Dynatrace/dynatrace-for-ai
|
|
7
|
+
(https://github.com/Dynatrace/dynatrace-for-ai), Copyright Dynatrace LLC, licensed under the
|
|
8
|
+
Apache License, Version 2.0 (see third_party/dynatrace-for-ai/LICENSE). Those files are used at
|
|
9
|
+
build time to generate packages/core/src/dql/catalog.generated.ts, and as the reference for the
|
|
10
|
+
Dynatrace dashboard format (third_party/dynatrace-for-ai/dashboards/).
|
|
11
|
+
|
|
12
|
+
The web app that ships with the command-line tool and as the hosted page bundles third-party
|
|
13
|
+
libraries and fonts. Their licences are listed in THIRD-PARTY-NOTICES.txt, which is generated when
|
|
14
|
+
the app is built and travels with it.
|
|
15
|
+
|
|
16
|
+
This project is independent. It is not affiliated with, endorsed by or supported by Splunk Inc.,
|
|
17
|
+
Cisco or Dynatrace. Splunk, SPL, Dynatrace and DQL are trademarks of their respective owners and
|
|
18
|
+
are used only to describe what this tool works with.
|
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @spl2dql/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The translation engine behind [`spl2dql`](https://www.npmjs.com/package/spl2dql): Splunk SPL in,
|
|
4
|
+
Dynatrace DQL out. No runtime dependencies, no I/O, no network — it runs in browsers, Web Workers
|
|
5
|
+
and Node.js. Deterministic: the same input always gives the same output.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { translate, parseMappingConfig } from '@spl2dql/core';
|
|
9
|
+
|
|
10
|
+
const mapping = parseMappingConfig({
|
|
11
|
+
version: 1,
|
|
12
|
+
indexes: { web: { buckets: ['web_logs'] } },
|
|
13
|
+
fields: { status: 'http.status' },
|
|
14
|
+
});
|
|
15
|
+
if (!mapping.ok) throw new Error(mapping.issues.map((i) => i.message).join('\n'));
|
|
16
|
+
|
|
17
|
+
const result = translate('index=web status>=500 | stats count by host', {
|
|
18
|
+
mapping: mapping.value,
|
|
19
|
+
timeRange: { earliest: '-24h@h' },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
result.dql; // the DQL text
|
|
23
|
+
result.confidence; // 'high' | 'review' | 'low' | 'none'
|
|
24
|
+
result.diagnostics; // notes with stable codes (SPL3001…), spans in the SPL and the DQL
|
|
25
|
+
result.stages; // per SPL stage: its status ('exact' | 'check' | 'untranslated') and the DQL it produced
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`translate()` never throws on user input; problems are reported as diagnostics.
|
|
29
|
+
|
|
30
|
+
Dashboards and Splunk configuration files are handled here too, as pure functions on text:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { convertDashboardSource, importSplunkConfig, parseSavedSearches } from '@spl2dql/core';
|
|
34
|
+
|
|
35
|
+
// macros.conf, props.conf, transforms.conf, eventtypes.conf, tags.conf → mapping-file sections
|
|
36
|
+
const { sections, skipped } = importSplunkConfig([{ name: 'macros.conf', text: macrosConf }]);
|
|
37
|
+
|
|
38
|
+
// Simple XML or Dashboard Studio → a Dynatrace dashboard document
|
|
39
|
+
const { dashboard, tiles, variables, counts } = convertDashboardSource({ name: 'web.xml', text: xml }, { mapping: mapping.value });
|
|
40
|
+
JSON.stringify(dashboard); // write this; tiles[] says which panels are live and which need manual work
|
|
41
|
+
|
|
42
|
+
// savedsearches.conf → searches with their saved time range, schedule and disabled flag
|
|
43
|
+
const searches = parseSavedSearches(savedsearchesConf, 'savedsearches.conf');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
A dashboard panel becomes a live tile only when its search translated completely; otherwise the
|
|
47
|
+
tile keeps the Splunk search and says what is missing.
|
|
48
|
+
|
|
49
|
+
Also exported: `checkDqlSyntax` (offline DQL syntax check), `translateCondition`, `listCommands`,
|
|
50
|
+
`explainDiagnostic`, `highlightSpl`, `tokenizeDql`, `parseCsvSearches`, `parseConf`,
|
|
51
|
+
`collectMappingNeeds`, `mergeMappingSections`, `readDashboard`, `convertDashboard`, `regexToDpl`.
|
|
52
|
+
|
|
53
|
+
Apache-2.0. The DQL catalogue is generated from the Apache-2.0 reference in
|
|
54
|
+
[Dynatrace/dynatrace-for-ai](https://github.com/Dynatrace/dynatrace-for-ai); see NOTICE.
|
|
55
|
+
|
|
56
|
+
spl2dql is an independent open-source project. It is not affiliated with, endorsed by or supported
|
|
57
|
+
by Splunk Inc., Cisco or Dynatrace. Splunk, SPL, Dynatrace and DQL are trademarks of their
|
|
58
|
+
respective owners and are used only to describe what this tool works with. Provided without
|
|
59
|
+
warranty; check every translated query before relying on it.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CommandDef } from './types.ts';
|
|
2
|
+
export declare const lookup: CommandDef;
|
|
3
|
+
export declare const inputlookup: CommandDef;
|
|
4
|
+
export declare const join: CommandDef;
|
|
5
|
+
export declare const append: CommandDef;
|
|
6
|
+
export declare const union: CommandDef;
|
|
7
|
+
export declare const multisearch: CommandDef;
|
|
8
|
+
export declare const combineCommands: CommandDef[];
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { assign, block, call, cmd, field, ident, named, str, sub } from '../dql/ast.js';
|
|
2
|
+
import { Untranslatable } from '../lower/context.js';
|
|
3
|
+
import { lowerLaterSearch } from '../lower/search.js';
|
|
4
|
+
import { parseSearch, SearchError } from '../spl/search.js';
|
|
5
|
+
function lookupPath(st, name, span) {
|
|
6
|
+
const m = st.mapping.lookups.get(name);
|
|
7
|
+
if (m)
|
|
8
|
+
return m;
|
|
9
|
+
st.report('SPL4005', span, {
|
|
10
|
+
subject: name,
|
|
11
|
+
detail: `Lookup "${name}" has no entry in the mapping file; a placeholder path /lookups/${safeName(name)} is used.`,
|
|
12
|
+
});
|
|
13
|
+
return { path: `/lookups/${safeName(name)}` };
|
|
14
|
+
}
|
|
15
|
+
function safeName(name) {
|
|
16
|
+
return name.replace(/\.csv$/i, '').replace(/[^A-Za-z0-9_.-]/g, '_') || 'lookup';
|
|
17
|
+
}
|
|
18
|
+
const load = (path) => cmd('load', str(path));
|
|
19
|
+
export const lookup = {
|
|
20
|
+
name: 'lookup',
|
|
21
|
+
tier: 'T2',
|
|
22
|
+
summary: 'lookup [load "<path>"], sourceField:, lookupField:, fields:{…}.',
|
|
23
|
+
lower(st) {
|
|
24
|
+
const scan = st.scanner();
|
|
25
|
+
while (scan.option()) {
|
|
26
|
+
// local=, update=, event_time_field= have no effect on the translation
|
|
27
|
+
}
|
|
28
|
+
const table = scan.word();
|
|
29
|
+
if (!table)
|
|
30
|
+
throw new Untranslatable('SPL1003', st.span, 'lookup needs a table name.');
|
|
31
|
+
const keys = [];
|
|
32
|
+
while (!scan.atEnd() && !scan.peekKeyword('output') && !scan.peekKeyword('outputnew')) {
|
|
33
|
+
if (scan.eat(','))
|
|
34
|
+
continue;
|
|
35
|
+
const f = scan.fieldName();
|
|
36
|
+
if (!f)
|
|
37
|
+
throw new Untranslatable('SPL1003', scan.here(), 'Expected a lookup field.');
|
|
38
|
+
let local = f.value;
|
|
39
|
+
if (scan.keyword('as'))
|
|
40
|
+
local = scan.fieldName()?.value ?? local;
|
|
41
|
+
keys.push({ lookupField: f.value, local, span: f.span });
|
|
42
|
+
}
|
|
43
|
+
if (keys.length === 0)
|
|
44
|
+
throw new Untranslatable('SPL1003', st.span, 'lookup needs a field to match on.');
|
|
45
|
+
const outputs = [];
|
|
46
|
+
const outputNew = scan.keyword('outputnew');
|
|
47
|
+
if (outputNew || scan.keyword('output')) {
|
|
48
|
+
while (!scan.atEnd()) {
|
|
49
|
+
if (scan.eat(','))
|
|
50
|
+
continue;
|
|
51
|
+
const c = scan.fieldName();
|
|
52
|
+
if (!c)
|
|
53
|
+
throw new Untranslatable('SPL1003', scan.here(), 'Expected an output field.');
|
|
54
|
+
let as = c.value;
|
|
55
|
+
if (scan.keyword('as'))
|
|
56
|
+
as = scan.fieldName()?.value ?? as;
|
|
57
|
+
outputs.push({ col: c.value, as });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const t = lookupPath(st, table.value, table.span);
|
|
61
|
+
st.report('SPL3013', st.span, { detail: 'If several rows match, Splunk returns all values; DQL takes one row.' });
|
|
62
|
+
if (keys.length > 1) {
|
|
63
|
+
// Several keys: a left-outer join on all of them.
|
|
64
|
+
const on = keys.map((k) => (k.local === k.lookupField ? field(st.field(k.local, k.span)) : field(st.field(k.local, k.span))));
|
|
65
|
+
const fieldsArg = outputs.length > 0 ? [named('fields', block(outputs.map((o) => (o.as === o.col ? field(o.col) : assign(o.as, field(o.col))))))] : [];
|
|
66
|
+
st.emit(cmd('join', sub([{ ...load(t.path), origin: [st.index] }]), named('on', block(on)), named('kind', ident('leftOuter')), ...fieldsArg));
|
|
67
|
+
if (outputs.length === 0)
|
|
68
|
+
st.report('SPL3016', st.span, { detail: 'Lookup columns arrive with the prefix "right.".' });
|
|
69
|
+
for (const o of outputs)
|
|
70
|
+
st.field(o.as, st.span, true);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const key = keys[0];
|
|
74
|
+
const args = [named('sourceField', field(st.field(key.local, key.span))), named('lookupField', field(t.key ?? key.lookupField))];
|
|
75
|
+
let cols = outputs;
|
|
76
|
+
if (cols.length === 0) {
|
|
77
|
+
if (t.columns)
|
|
78
|
+
cols = t.columns.filter((c) => c !== (t.key ?? key.lookupField)).map((c) => ({ col: c, as: c }));
|
|
79
|
+
else
|
|
80
|
+
st.report('SPL3016', st.span, {
|
|
81
|
+
detail: 'Without OUTPUT, lookup columns arrive as lookup.<column>; list the columns in the mapping file to keep their names.',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const tmp = (c) => `_new_${c.replace(/[^A-Za-z0-9_]/g, '_')}`;
|
|
85
|
+
if (cols.length > 0) {
|
|
86
|
+
args.push(named('fields', block(cols.map((o) => (outputNew ? assign(tmp(o.as), field(o.col)) : o.as === o.col ? field(o.col) : assign(o.as, field(o.col)))))));
|
|
87
|
+
}
|
|
88
|
+
st.emit({ name: 'lookup', args: [{ kind: 'pos', value: sub([{ ...load(t.path), origin: [st.index] }]) }, ...args] });
|
|
89
|
+
if (outputNew && cols.length > 0) {
|
|
90
|
+
st.emit(cmd('fieldsAdd', ...cols.map((o) => assign(o.as, call('coalesce', field(o.as), field(tmp(o.as)))))));
|
|
91
|
+
st.emit(cmd('fieldsRemove', ...cols.map((o) => field(tmp(o.as)))));
|
|
92
|
+
}
|
|
93
|
+
for (const o of cols)
|
|
94
|
+
st.field(o.as, st.span, true);
|
|
95
|
+
st.addFields(cols.map((c) => c.as));
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
export const inputlookup = {
|
|
99
|
+
name: 'inputlookup',
|
|
100
|
+
tier: 'T2',
|
|
101
|
+
summary: 'load "<path>" then filter.',
|
|
102
|
+
generating: true,
|
|
103
|
+
lower(st) {
|
|
104
|
+
const scan = st.scanner();
|
|
105
|
+
let append = false;
|
|
106
|
+
for (let o = scan.option(); o; o = scan.option()) {
|
|
107
|
+
if (o.name.toLowerCase() === 'append' && /^(t|true|1)$/i.test(o.value))
|
|
108
|
+
append = true;
|
|
109
|
+
else if (o.name.toLowerCase() !== 'append')
|
|
110
|
+
throw new Untranslatable('SPL2003', o.span, `inputlookup ${o.name}= cannot be translated.`);
|
|
111
|
+
}
|
|
112
|
+
const table = scan.word();
|
|
113
|
+
if (!table)
|
|
114
|
+
throw new Untranslatable('SPL1003', st.span, 'inputlookup needs a table name.');
|
|
115
|
+
const t = lookupPath(st, table.value, table.span);
|
|
116
|
+
let where;
|
|
117
|
+
if (scan.keyword('where')) {
|
|
118
|
+
const rest = scan.rest();
|
|
119
|
+
try {
|
|
120
|
+
where = parseSearch(st.tc.text, rest.start, rest.end);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
if (e instanceof SearchError)
|
|
124
|
+
throw new Untranslatable('SPL1001', e.span, e.message);
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (!scan.atEnd()) {
|
|
129
|
+
throw new Untranslatable('SPL1003', scan.here(), 'Unexpected text in inputlookup.');
|
|
130
|
+
}
|
|
131
|
+
if (append) {
|
|
132
|
+
if (where)
|
|
133
|
+
throw new Untranslatable('SPL2003', st.span, 'inputlookup append=t with where cannot be translated.');
|
|
134
|
+
st.emit(cmd('append', sub([{ ...load(t.path), origin: [st.index] }])));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
st.emit(load(t.path));
|
|
138
|
+
st.setTable(t.columns ? [...t.columns] : []);
|
|
139
|
+
st.state.schema = { kind: 'table', fields: t.columns ? [...t.columns] : [] };
|
|
140
|
+
if (where)
|
|
141
|
+
lowerLaterSearch(st, where);
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
function subsearch(st, open) {
|
|
145
|
+
const result = st.tc.lowerSub(open.inner, st);
|
|
146
|
+
if (result.incomplete)
|
|
147
|
+
throw new Untranslatable('SPL2007', open.span, 'The subsearch contains a step that could not be translated.');
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
export const join = {
|
|
151
|
+
name: 'join',
|
|
152
|
+
tier: 'T2',
|
|
153
|
+
summary: 'join [sub], on:{keys}, kind:inner|leftOuter, fields:{…}.',
|
|
154
|
+
lower(st) {
|
|
155
|
+
const scan = st.scanner();
|
|
156
|
+
let kind = 'inner';
|
|
157
|
+
const keys = [];
|
|
158
|
+
while (scan.peek() !== '[' && !scan.atEnd()) {
|
|
159
|
+
const o = scan.option();
|
|
160
|
+
if (o) {
|
|
161
|
+
const key = o.name.toLowerCase();
|
|
162
|
+
if (key === 'type') {
|
|
163
|
+
const v = o.value.toLowerCase();
|
|
164
|
+
if (v === 'inner')
|
|
165
|
+
kind = 'inner';
|
|
166
|
+
else if (v === 'left' || v === 'outer')
|
|
167
|
+
kind = 'leftOuter';
|
|
168
|
+
else
|
|
169
|
+
throw new Untranslatable('SPL2003', o.span, `join type=${o.value} cannot be translated.`);
|
|
170
|
+
}
|
|
171
|
+
else if (key === 'max' && o.value === '0') {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
else if (key === 'left' || key === 'right' || key === 'where') {
|
|
175
|
+
throw new Untranslatable('SPL2003', o.span, 'join with left=/right= aliases cannot be translated.');
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
st.report('SPL2003', o.span, { detail: `join ${o.name}= has no DQL equivalent and was ignored.` });
|
|
179
|
+
}
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (scan.eat(','))
|
|
183
|
+
continue;
|
|
184
|
+
const f = scan.fieldName();
|
|
185
|
+
if (!f)
|
|
186
|
+
throw new Untranslatable('SPL1003', scan.here(), 'Expected join fields.');
|
|
187
|
+
keys.push({ name: f.value, span: f.span });
|
|
188
|
+
}
|
|
189
|
+
const open = scan.balanced('[', ']');
|
|
190
|
+
if (!open)
|
|
191
|
+
throw new Untranslatable('SPL1003', st.span, 'join needs a subsearch in [ … ].');
|
|
192
|
+
if (keys.length === 0)
|
|
193
|
+
throw new Untranslatable('SPL2003', st.span, 'join without fields cannot be translated.');
|
|
194
|
+
const names = keys.map((k) => st.field(k.name, k.span));
|
|
195
|
+
const result = subsearch(st, open);
|
|
196
|
+
st.report('SPL3009', st.span, { detail: 'Splunk join keeps one matching row by default (max=1); DQL keeps every match.' });
|
|
197
|
+
const args = [{ kind: 'pos', value: sub(result.commands) }, named('on', block(names.map(field))), named('kind', ident(kind))];
|
|
198
|
+
const outputs = result.outputFields?.filter((f) => !names.includes(f));
|
|
199
|
+
if (outputs && outputs.length > 0) {
|
|
200
|
+
args.push(named('fields', block(outputs.map(field))));
|
|
201
|
+
for (const o of outputs)
|
|
202
|
+
st.field(o, st.span, true);
|
|
203
|
+
st.addFields(outputs);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
st.report('SPL3016', st.span, { detail: 'The subsearch fields are not known here, so they arrive with the prefix "right.".' });
|
|
207
|
+
}
|
|
208
|
+
st.emit({ name: 'join', args });
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
export const append = {
|
|
212
|
+
name: 'append',
|
|
213
|
+
tier: 'T1',
|
|
214
|
+
summary: 'append [sub].',
|
|
215
|
+
lower(st) {
|
|
216
|
+
const scan = st.scanner();
|
|
217
|
+
while (scan.option()) {
|
|
218
|
+
// extendtimerange, maxtime, maxout: not reproduced
|
|
219
|
+
}
|
|
220
|
+
const open = scan.balanced('[', ']');
|
|
221
|
+
if (!open)
|
|
222
|
+
throw new Untranslatable('SPL1003', st.span, 'append needs a subsearch in [ … ].');
|
|
223
|
+
const result = subsearch(st, open);
|
|
224
|
+
st.emit(cmd('append', sub(result.commands)));
|
|
225
|
+
if (result.outputFields)
|
|
226
|
+
st.addFields(result.outputFields);
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
function unionLike(name) {
|
|
230
|
+
return {
|
|
231
|
+
name,
|
|
232
|
+
tier: 'T2',
|
|
233
|
+
summary: 'First subsearch, then append [the others].',
|
|
234
|
+
generating: true,
|
|
235
|
+
lower(st) {
|
|
236
|
+
const scan = st.scanner();
|
|
237
|
+
while (scan.option()) {
|
|
238
|
+
// options are not reproduced
|
|
239
|
+
}
|
|
240
|
+
const subs = [];
|
|
241
|
+
for (let b = scan.balanced('[', ']'); b; b = scan.balanced('[', ']'))
|
|
242
|
+
subs.push(b);
|
|
243
|
+
if (subs.length === 0 || !scan.atEnd())
|
|
244
|
+
throw new Untranslatable('SPL1003', st.span, `${name} needs subsearches in [ … ].`);
|
|
245
|
+
st.report('SPL3004', st.span, { detail: 'Results are appended one after the other, not interleaved by time.' });
|
|
246
|
+
const parts = subs.map((s) => subsearch(st, s).commands);
|
|
247
|
+
const startsPipeline = st.first && st.upstream.length === 0;
|
|
248
|
+
const rest = startsPipeline ? parts.slice(1) : parts;
|
|
249
|
+
if (startsPipeline)
|
|
250
|
+
for (const c of parts[0] ?? [])
|
|
251
|
+
st.out.push({ ...c, origin: [st.index] });
|
|
252
|
+
for (const p of rest)
|
|
253
|
+
st.emit(cmd('append', sub(p)));
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
export const union = unionLike('union');
|
|
258
|
+
export const multisearch = unionLike('multisearch');
|
|
259
|
+
export const combineCommands = [lookup, inputlookup, join, append, union, multisearch];
|
|
260
|
+
//# sourceMappingURL=combine.js.map
|