10
10
11
11
from grafana_wtf import __appname__ , __version__
12
12
from grafana_wtf .core import GrafanaWtf
13
- from grafana_wtf .report .data import output_results
13
+ from grafana_wtf .report .data import output_results , DataSearchReport
14
14
from grafana_wtf .report .textual import TextualSearchReport
15
15
from grafana_wtf .report .tabular import TabularSearchReport , get_table_format , TabularEditHistoryReport
16
16
from grafana_wtf .util import (
@@ -40,7 +40,7 @@ def run():
40
40
--grafana-token=<grafana-token> Grafana API Key token
41
41
--select-dashboard=<uuid> Restrict operation to dashboard by UID.
42
42
Can be a list of comma-separated dashboard UIDs.
43
- --format=<format> Output format. [default: json]
43
+ --format=<format> Output format. One of textual, tabular, json, yaml.
44
44
--cache-ttl=<cache-ttl> Time-to-live for the request cache in seconds. [default: 300]
45
45
--drop-cache Drop cache before requesting resources
46
46
--concurrency=<concurrency> Run multiple requests in parallel. [default: 5]
@@ -176,6 +176,13 @@ def run():
176
176
else :
177
177
raise
178
178
179
+ # Compute default output format.
180
+ if not options .format :
181
+ if options .find or options .replace :
182
+ options .format = "textual"
183
+ else :
184
+ options .format = "json"
185
+
179
186
# Sanity checks
180
187
if grafana_url is None :
181
188
raise DocoptExit (
@@ -195,6 +202,7 @@ def run():
195
202
output_format = options ["format" ]
196
203
197
204
if options .find or options .replace :
205
+
198
206
if options .select_dashboard :
199
207
# Restrict scan to list of dashboards.
200
208
dashboard_uids = read_list (options .select_dashboard )
@@ -206,11 +214,13 @@ def run():
206
214
207
215
result = engine .search (options .search_expression or None )
208
216
209
- if output_format .startswith ("tabular " ):
217
+ if output_format .startswith ("tab " ):
210
218
table_format = get_table_format (output_format )
211
219
generator = partial (TabularSearchReport , tblfmt = table_format )
212
- else :
220
+ elif output_format . startswith ( "text" ) :
213
221
generator = TextualSearchReport
222
+ else :
223
+ generator = partial (DataSearchReport , format = output_format )
214
224
215
225
report = generator (grafana_url , verbose = options .verbose )
216
226
report .display (options .search_expression , result )
@@ -220,6 +230,7 @@ def run():
220
230
engine .clear_cache ()
221
231
222
232
if options .log :
233
+
223
234
entries = engine .log (dashboard_uid = options .dashboard_uid )
224
235
entries = sorted (entries , key = itemgetter ("datetime" ))
225
236
@@ -237,14 +248,15 @@ def run():
237
248
if options .reverse :
238
249
entries = list (reversed (entries ))
239
250
240
- if output_format .startswith ("tabular " ):
251
+ if output_format .startswith ("tab " ):
241
252
report = TabularEditHistoryReport (data = entries )
242
253
output = report .render (output_format )
243
254
print (output )
244
255
else :
245
256
output_results (output_format , entries )
246
257
247
258
if options .explore and options .datasources :
259
+
248
260
results = engine .explore_datasources ()
249
261
250
262
unused_count = len (results ["unused" ])
0 commit comments