/
searchCtrl.go
1264 lines (1166 loc) · 40.5 KB
/
searchCtrl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*************************************************************************
* Copyright 2021 Gravwell, Inc. All rights reserved.
* Contact: <legal@gravwell.io>
*
* This software may be modified and distributed under the terms of the
* BSD 2-clause license. See the LICENSE file for details.
**************************************************************************/
package client
import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"time"
"github.com/gravwell/gravwell/v3/client/types"
"github.com/gravwell/gravwell/v3/client/websocketRouter"
"github.com/gravwell/gravwell/v3/ingest/entry"
)
const (
SEARCH_HISTORY_USER = `user`
importFormGID = `GID`
importFormFile = `file`
importFormBatchName = `BatchName`
importFormBatchInfo = `BatchInfo`
)
var (
ErrSearchNotAttached = errors.New("search not attached")
)
// DeleteSearch will request that a search is deleted by search ID
func (c *Client) DeleteSearch(sid string) error {
return c.deleteStaticURL(searchCtrlIdUrl(sid), nil)
}
// SearchStatus requests the status of a given search ID
func (c *Client) SearchStatus(sid string) (types.SearchCtrlStatus, error) {
var si types.SearchCtrlStatus
if err := c.getStaticURL(searchCtrlIdUrl(sid), &si); err != nil {
return si, err
}
return si, nil
}
// SearchInfo requests the search info for a given search ID
func (c *Client) SearchInfo(sid string) (types.SearchInfo, error) {
var si types.SearchInfo
if err := c.getStaticURL(searchCtrlDetailsUrl(sid), &si); err != nil {
return si, err
}
return si, nil
}
// SaveSearch will request that a search is saved by ID, an optional SaveSearchPatch can be sent
// to modify the expiration or search name and notes
func (c *Client) SaveSearch(sid string, ssp ...types.SaveSearchPatch) error {
var arg interface{}
if len(ssp) == 1 {
arg = ssp[0]
}
return c.patchStaticURL(searchCtrlSaveUrl(sid), arg)
}
// BackgroundSearch will request that a search is backgrounded by ID
func (c *Client) BackgroundSearch(sid string) error {
return c.patchStaticURL(searchCtrlBackgroundUrl(sid), nil)
}
// SetGroup will set the GID of the group which can read the search.
// Setting it to 0 will disable group access.
func (c *Client) SetGroup(sid string, gid int32) error {
request := struct{ GID int32 }{gid}
return c.putStaticURL(searchCtrlGroupUrl(sid), request)
}
// ListSearchStatuses returns a list of all searches the current user has access to
// and their current status.
func (c *Client) ListSearchStatuses() ([]types.SearchCtrlStatus, error) {
var scs []types.SearchCtrlStatus
if err := c.getStaticURL(SEARCH_CTRL_LIST_URL, &scs); err != nil {
return nil, err
}
return scs, nil
}
// ListAllSearchStatuses returns a list of all searches on the system. Only admin
// users can use this function.
func (c *Client) ListAllSearchStatuses() ([]types.SearchCtrlStatus, error) {
var scs []types.SearchCtrlStatus
if err := c.getStaticURL(SEARCH_CTRL_LIST_ALL_URL, &scs); err != nil {
return nil, err
}
return scs, nil
}
// ListSearchDetails returns details for all searches the current user has access to
// and their current status. If the admin flag is set (by calling SetAdminMode())
// this will return info for all searches on the system.
func (c *Client) ListSearchDetails() ([]types.SearchInfo, error) {
var details []types.SearchInfo
err := c.getStaticURL(searchCtrlListDetailsUrl(), &details)
return details, err
}
// GetSearchHistory retrieves the current search history for the currently logged
// in user. It only pulls back searches invoked by the individual user.
func (c *Client) GetSearchHistory() ([]types.SearchLog, error) {
var sl []types.SearchLog
if err := c.getStaticURL(searchHistoryUrl(SEARCH_HISTORY_USER, c.userDetails.UID), &sl); err != nil {
return nil, err
}
return sl, nil
}
// GetRefinedSearchHistory retrieves the current search history for the
// currently logged in user narrowed to searches containing the substring s. It
// only pulls back searches invoked by the individual user.
func (c *Client) GetRefinedSearchHistory(s string) ([]types.SearchLog, error) {
var sl []types.SearchLog
params := map[string]string{
"refine": s,
}
pth := searchHistoryUrl(SEARCH_HISTORY_USER, c.userDetails.UID)
if err := c.methodStaticParamURL(http.MethodGet, pth, params, &sl); err != nil {
return nil, err
}
return sl, nil
}
// GetUserSearchHistory retrieves the current search history for the specified user.
// Only admins may request search history for users besides themselves.
func (c *Client) GetUserSearchHistory(uid int32) ([]types.SearchLog, error) {
var sl []types.SearchLog
if err := c.getStaticURL(searchHistoryUrl(SEARCH_HISTORY_USER, uid), &sl); err != nil {
return nil, err
}
return sl, nil
}
// GetSearchHistoryRange retrieves paginated search history for the currently logged
// in user. The start and end parameters are indexes into the search history, with
// 0 representing the most recent search.
func (c *Client) GetSearchHistoryRange(start, end int) ([]types.SearchLog, error) {
params := map[string]string{
"start": fmt.Sprintf("%d", start),
"end": fmt.Sprintf("%d", end),
}
pth := searchHistoryUrl(SEARCH_HISTORY_USER, c.userDetails.UID)
var sl []types.SearchLog
if err := c.methodStaticParamURL(http.MethodGet, pth, params, &sl); err != nil {
return nil, err
}
return sl, nil
}
// Search represents an search on the Gravwell system.
type Search struct {
ID string
RenderMod string
searchSockets *SearchSockets
searchOutput *websocketRouter.SubProtoConn
types.StartSearchRequest
}
func (s *Search) Exchange(req, resp interface{}) (err error) {
if s.searchSockets == nil || s.searchOutput == nil {
err = ErrSearchNotAttached
return
} else if req == nil {
err = errors.New("invalid request")
return
} else if err = s.searchOutput.WriteJSON(req); err != nil {
return
}
if resp != nil {
err = s.searchOutput.ReadJSON(resp)
}
return
}
// Ping sends a message via the search's websockets (if present)
// to keep the sockets open. If you intend to run a search and then
// wait a long time before interacting with it further, you
// should periodically call Ping() to keep the connection alive.
func (s *Search) Ping() error {
if s.searchSockets != nil && s.searchSockets.Pong != nil {
var preq types.PingReq
if err := s.searchSockets.Pong.WriteJSON(preq); err != nil {
return err
}
if err := s.searchSockets.Pong.ReadJSON(&preq); err != nil {
return err
}
} else {
return ErrSearchNotAttached
}
return nil
}
// ParseSearch validates a search query. Gravwell will return an error if the query
// is not valid.
func (c *Client) ParseSearch(query string) (err error) {
_, err = c.ParseSearchWithResponse(query, []types.FilterRequest{})
return
}
// ParseSearchWithResponse behaves as ParseSearch, but it returns the ParseSearchResponse
// which contains detailed information about how Gravwell parsed out the search.
func (c *Client) ParseSearchWithResponse(query string, filters []types.FilterRequest) (psr types.ParseSearchResponse, err error) {
ssr := types.ParseSearchRequest{
SearchString: query,
Sequence: 0x1337,
Filters: filters,
}
if err = c.postStaticURL(PARSE_URL, ssr, &psr); err != nil {
return
}
//check that what we got back was good
if psr.ParseError != `` {
err = fmt.Errorf("Parse error: %s", psr.ParseError)
} else if psr.RawQuery != query {
err = fmt.Errorf("RawQuery response is invalid: %q != %q", psr.RawQuery, query)
}
return
}
// StartBackgroundSearch launches a backgrounded search with the given query
// and the specified start and end times. If "nohistory" is set, the search will
// be hidden in the user's search history; if false, it will be visible.
func (c *Client) StartBackgroundSearch(query string, start, end time.Time, nohistory bool) (s Search, err error) {
sr := types.StartSearchRequest{
SearchString: query,
SearchStart: start.Format(time.RFC3339Nano),
SearchEnd: end.Format(time.RFC3339Nano),
NoHistory: nohistory,
Background: true,
}
s, err = c.StartSearchEx(sr)
return
}
// StartSearch launches a foregrounded search with the given query and start/end.
// If "nohistory" is set, the search will
// be hidden in the user's search history; if false, it will be visible.
func (c *Client) StartSearch(query string, start, end time.Time, nohistory bool) (s Search, err error) {
sr := types.StartSearchRequest{
SearchString: query,
SearchStart: start.Format(time.RFC3339Nano),
SearchEnd: end.Format(time.RFC3339Nano),
NoHistory: nohistory,
}
s, err = c.StartSearchEx(sr)
return
}
// StartSearchExtended launches a search using a StartSearchRequest object
// This function grants the maximum amount of control over the search starting process
func (c *Client) StartSearchEx(sr types.StartSearchRequest) (s Search, err error) {
//grab subprotocol connection and subproto parent
s.searchSockets, err = c.GetSearchSockets()
if err != nil {
return
}
searchSubProto := s.searchSockets.Search
// we get a new set of sockets on each GetSearchSocket.
// So we can close the main search suproto when done
// The main protocols for the search will be left open
defer searchSubProto.Close()
if err = searchSubProto.WriteJSON(sr); err != nil {
return
}
ssresp := types.StartSearchResponse{}
if err = searchSubProto.ReadJSON(&ssresp); err != nil {
return
}
if ssresp.Error != "" {
err = fmt.Errorf("Search request error: %s", ssresp.Error)
return
}
if ssresp.OutputSearchSubproto != `` {
if err = s.searchSockets.Client.AddSubProtocol(ssresp.OutputSearchSubproto); err != nil {
return
}
if s.searchOutput, err = s.searchSockets.Client.GetSubProtoConn(ssresp.OutputSearchSubproto); err != nil {
return
}
}
sAck := types.StartSearchAck{
Ok: true,
OutputSearchSubproto: ssresp.OutputSearchSubproto,
}
if err = searchSubProto.WriteJSON(sAck); err != nil {
err = fmt.Errorf("Failed to ack the search server: %w", err)
return
}
s.ID = ssresp.SearchID
s.RenderMod = ssresp.RenderModule
s.StartSearchRequest = sr
return
}
// StopSearch asks the search to stop progressing through the underlying data.
// The renderer maintains any data it currently has and the query is entirely usable,
// The data feed is just stopped. Issuing a Stop command to a query that is done
// has no affect. Meaning that if you attached to an archived search and issue a stop
// nothing happens. Requests to stop queries that you don't own return an error
// unless the caller is an admin
func (c *Client) StopSearch(id string) (err error) {
//send request
err = c.putStaticURL(searchCtrlStopUrl(id), nil)
return
}
// StartFilteredSearch launches a foregrounded search with the given query and start/end.
// The filters parameter is an array of filters; these will be automatically inserted into the
// query during the parse phase.
// If "nohistory" is set, the search will
// be hidden in the user's search history; if false, it will be visible.
func (c *Client) StartFilteredSearch(query string, start, end time.Time, nohistory bool, filters []types.FilterRequest) (s Search, err error) {
sr := types.StartSearchRequest{
SearchString: query,
SearchStart: start.Format(time.RFC3339Nano),
SearchEnd: end.Format(time.RFC3339Nano),
NoHistory: nohistory,
Filters: filters,
}
s, err = c.StartSearchEx(sr)
return
}
// AttachSearch connects to an existing search (specified with the id parameter) and
// returns the associated Search object.
func (c *Client) AttachSearch(id string) (s Search, err error) {
//grab subprotocol connection and subproto parent
s.ID = id
s.searchSockets, err = c.GetAttachSockets()
if err != nil {
return
}
conn := s.searchSockets.Attach
//attempt to attach to it
req := types.AttachSearchRequest{
ID: id,
}
var resp types.AttachSearchResponse
if err := conn.WriteJSON(req); err != nil {
return s, err
}
if err := conn.ReadJSON(&resp); err != nil {
return s, err
}
if resp.Error != "" {
return s, errors.New(resp.Error)
}
if len(resp.Subproto) == 0 || resp.Info == nil {
return s, errors.New("Invalid search attach response")
}
//kick off our renderer
if err := s.searchSockets.Client.AddSubProtocol(resp.Subproto); err != nil {
return s, err
}
rconn, err := s.searchSockets.Client.GetSubProtoConn(resp.Subproto)
if err != nil {
return s, err
}
s.searchOutput = rconn
s.RenderMod = resp.RendererMod
return s, nil
}
// GetAvailableEntryCount returns the number of output entries for the specified
// search. The second return value is a boolean indicating if the search has finished
// or not.
func (c *Client) GetAvailableEntryCount(s Search) (uint64, bool, error) {
//send request
req := types.BaseRequest{
ID: types.REQ_ENTRY_COUNT,
}
resp := types.BaseResponse{}
if err := s.Exchange(req, &resp); err != nil {
return 0, false, err
} else if err = resp.Err(); err != nil {
return 0, false, err
} else if resp.ID != types.RESP_ENTRY_COUNT {
return 0, false, errors.New("Invalid response ID")
}
return resp.EntryCount, resp.Finished, nil
}
// WaitForSearch sleeps until the given search is complete.
// If the search fails for some reason, WaitForSearch will return an error describing
// the reason for the failure.
func (c *Client) WaitForSearch(s Search) (err error) {
var done bool
for !done {
if _, done, err = c.GetAvailableEntryCount(s); err != nil {
return
}
time.Sleep(time.Second)
}
//how ask for the search details
req := types.BaseRequest{
ID: types.REQ_SEARCH_DETAILS,
}
var resp types.BaseResponse
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
}
return
}
// GetEntries fetches results from a search. These results have the Tag field represented
// as a string rather than the numeric representation used internally.
// Note that GetEntries is really only suitable for searches using the raw, text, or hex
// renderers. Results from the table renderer will also be restructured as entries, but
// other renderers are not supported.
func (c *Client) GetEntries(s Search, start, end uint64) ([]types.StringTagEntry, error) {
if (end - start) < 0 {
return nil, fmt.Errorf("invalid entry span: start = %v, end = %v", start, end)
} else if (end - start) == 0 {
return []types.StringTagEntry{}, nil
}
switch s.RenderMod {
case types.RenderNamePcap:
fallthrough
case types.RenderNameRaw:
fallthrough
case types.RenderNameHex:
fallthrough
case types.RenderNameText:
return c.getStringTagTextEntries(s, start, end)
case types.RenderNameTable:
return c.getStringTagTableEntries(s, start, end)
}
return nil, errors.New("Unsupported render module " + s.RenderMod)
}
func (c *Client) getStringTagTextEntries(s Search, start, end uint64) (ste []types.StringTagEntry, err error) {
//send request
req := types.TextRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
}
resp := types.TextResponse{}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != types.RESP_GET_ENTRIES {
return nil, errors.New("Invalid response ID")
} else if resp.Entries == nil {
return nil, errors.New("Empty entry response")
}
// Build up a reverse map of tags
tagMap := make(map[entry.EntryTag]string)
for tagName, tagID := range resp.Tags {
tagMap[tagID] = tagName
}
var ret []types.StringTagEntry
for _, ent := range resp.Entries {
ste := types.StringTagEntry{
TS: ent.TS.StandardTime(),
SRC: ent.SRC,
Data: ent.Data,
Tag: tagMap[ent.Tag],
Enumerated: ent.Enumerated,
}
ret = append(ret, ste)
}
return ret, nil
}
func (c *Client) getStringTagTableEntries(s Search, start, end uint64) (ste []types.StringTagEntry, err error) {
//send request
req := types.TextRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
}
resp := types.TableResponse{}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
}
if resp.ID != types.RESP_GET_ENTRIES {
err = errors.New("Invalid response ID")
return
}
ste = []types.StringTagEntry{}
columns := resp.Entries.Columns
rows := resp.Entries.Rows
if len(columns) == 0 || len(rows) == 0 {
return
}
// Build up a reverse map of tags
tagMap := make(map[entry.EntryTag]string)
for tagName, tagID := range resp.Tags {
tagMap[tagID] = tagName
}
for _, row := range rows {
e := types.StringTagEntry{
TS: row.TS.StandardTime(),
}
for i, v := range row.Row {
if i >= len(columns) {
continue
}
e.Enumerated = append(e.Enumerated, types.EnumeratedPair{
Name: columns[i],
Value: v,
RawValue: types.RawEnumeratedValue{Type: 1, Data: []byte(v)},
})
}
ste = append(ste, e)
}
return
}
func (c *Client) getTextResults(s Search, req types.TextRequest) (resp types.TextResponse, err error) {
if s.RenderMod != types.RenderNameText && s.RenderMod != types.RenderNameHex && s.RenderMod != types.RenderNameRaw && s.RenderMod != types.RenderNamePcap {
err = fmt.Errorf("Search %v has invalid renderer type %v", s.ID, s.RenderMod)
return
}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != req.ID {
err = errors.New("Invalid response ID")
}
return
}
// GetTextResults queries a range of search results from the text, hex, or raw renderers. It returns
// a types.TextResponse structure containing the results (see the Entries field)
func (c *Client) GetTextResults(s Search, first, last uint64) (types.TextResponse, error) {
req := types.TextRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: first,
Last: last,
},
},
}
return c.getTextResults(s, req)
}
// GetTextTsRange queries search results for a time range from the text, hex, or raw
// renderers. It returns a types.TextResponse structure containing the results (see the Entries field)
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetTextTsRange(s Search, start, end time.Time, first, last uint64) (types.TextResponse, error) {
req := types.TextRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_TS_RANGE,
EntryRange: &types.EntryRange{
StartTS: entry.FromStandard(start),
EndTS: entry.FromStandard(end),
First: first,
Last: last,
},
},
}
return c.getTextResults(s, req)
}
// GetPcapResults queries a range of search results from the pcap renderer. It returns
// a types.TextResponse structure containing the results (see the Entries field).
func (c *Client) GetPcapResults(s Search, start, end uint64) (types.TextResponse, error) {
return c.GetTextResults(s, start, end)
}
// GetPcapTsRange queries search results for a time range from the pcap renderer. It returns
// a types.TextResponse structure containing the results (see the Entries field).
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetPcapTsRange(s Search, start, end time.Time, first, last uint64) (types.TextResponse, error) {
return c.GetTextTsRange(s, start, end, first, last)
}
// GetRawResults queries a range of search results from the raw renderer. It returns
// a types.TextResponse structure containing the results (see the Entries field).
func (c *Client) GetRawResults(s Search, start, end uint64) (types.TextResponse, error) {
req := types.TextRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_RAW_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
}
return c.getTextResults(s, req)
}
// GetRawTsRange queries search results for a time range from the raw renderer. It returns
// a types.TextResponse structure containing the results (see the Entries field).
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetRawTsRange(s Search, start, end time.Time, first, last uint64) (types.TextResponse, error) {
return c.GetTextTsRange(s, start, end, first, last)
}
// GetHexResults queries a range of search results from the hex renderer. It returns
// a types.TextResponse structure containing the results (see the Entries field)
func (c *Client) GetHexResults(s Search, start, end uint64) (types.TextResponse, error) {
return c.GetTextResults(s, start, end)
}
// GetHexTsRange queries search results for a time range from the hex renderer. It returns
// a types.TextResponse structure containing the results (see the Entries field).
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetHexTsRange(s Search, start, end time.Time, first, last uint64) (types.TextResponse, error) {
return c.GetTextTsRange(s, start, end, first, last)
}
func (c *Client) getTableResults(s Search, req types.TableRequest) (resp types.TableResponse, err error) {
if s.RenderMod != types.RenderNameTable {
err = fmt.Errorf("Search %v has invalid renderer type: expected table, saw %v", s.ID, s.RenderMod)
return
}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != req.ID {
err = errors.New("Invalid response ID")
}
return
}
// GetTableResults queries a range of search results from the table renderer. It returns
// a types.TableResponse structure containing the results (see the Entries field)
func (c *Client) GetTableResults(s Search, start, end uint64) (types.TableResponse, error) {
req := types.TableRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
}
return c.getTableResults(s, req)
}
// GetTableTsRange queries search results for a time range from the table
// renderer. It returns a types.TableResponse structure containing the results (see the Entries field)
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetTableTsRange(s Search, start, end time.Time, first, last uint64) (types.TableResponse, error) {
req := types.TableRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_TS_RANGE,
EntryRange: &types.EntryRange{
StartTS: entry.FromStandard(start),
EndTS: entry.FromStandard(end),
First: first,
Last: last,
},
},
}
return c.getTableResults(s, req)
}
func (c *Client) getGaugeResults(s Search, req types.TableRequest) (resp types.GaugeResponse, err error) {
if s.RenderMod != types.RenderNameGauge && s.RenderMod != types.RenderNameNumbercard {
err = fmt.Errorf("Search %v has invalid renderer type: expected gauge, saw %v", s.ID, s.RenderMod)
return
}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != req.ID {
err = errors.New("Invalid response ID")
}
return
}
// GetGaugeResults queries a range of search results from the gauge or numbercard renderers.
// It returns a types.GaugeResponse structure containing the results (see the Entries field).
func (c *Client) GetGaugeResults(s Search, start, end uint64) (types.GaugeResponse, error) {
req := types.TableRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
}
return c.getGaugeResults(s, req)
}
// GetGaugeTsRange queries search results for a time range from the gauge
// renderer. It returns a types.GaugeResponse structure containing the results (see the Entries field)
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetGaugeTsRange(s Search, start, end time.Time, first, last uint64) (types.GaugeResponse, error) {
req := types.TableRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_TS_RANGE,
EntryRange: &types.EntryRange{
StartTS: entry.FromStandard(start),
EndTS: entry.FromStandard(end),
First: first,
Last: last,
},
},
}
return c.getGaugeResults(s, req)
}
// GetNumbercardResults queries a range of search results from the gauge or numbercard renderers.
// It returns a types.GaugeResponse structure containing the results (see the Entries field).
func (c *Client) GetNumbercardResults(s Search, start, end uint64) (types.GaugeResponse, error) {
return c.GetGaugeResults(s, start, end)
}
// GetNumbercardTsRange queries search results for a time range from the gauge or numbercard renderers.
// It returns a types.GaugeResponse structure containing the results (see the Entries field)
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetNumbercardTsRange(s Search, start, end time.Time, first, last uint64) (types.GaugeResponse, error) {
return c.GetGaugeTsRange(s, start, end, first, last)
}
func (c *Client) getChartResults(s Search, req types.ChartRequest) (resp types.ChartResponse, err error) {
if s.RenderMod != types.RenderNameChart {
err = fmt.Errorf("Search %v has invalid renderer type: expected chart, saw %v", s.ID, s.RenderMod)
return
}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != req.ID {
err = errors.New("Invalid response ID")
}
return
}
// GetChartResults queries a range of search results from the chart renderer.
// It returns a types.ChartResponse structure containing the results (see the Entries field).
func (c *Client) GetChartResults(s Search, start, end uint64) (resp types.ChartResponse, err error) {
req := types.ChartRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
}
return c.getChartResults(s, req)
}
// GetChartTsRange queries search results for a time range from the chart
// renderer. It returns a types.ChartResponse structure containing the results (see the Entries field)
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetChartTsRange(s Search, start, end time.Time, first, last uint64) (types.ChartResponse, error) {
req := types.ChartRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_TS_RANGE,
EntryRange: &types.EntryRange{
StartTS: entry.FromStandard(start),
EndTS: entry.FromStandard(end),
First: first,
Last: last,
},
},
}
return c.getChartResults(s, req)
}
func (c *Client) getFdgResults(s Search, req types.FdgRequest) (resp types.FdgResponse, err error) {
if s.RenderMod != types.RenderNameFdg {
err = fmt.Errorf("Search %v has invalid renderer type: expected fdg, saw %v", s.ID, s.RenderMod)
return
}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != req.ID {
err = errors.New("Invalid response ID")
}
return
}
// GetFdgResults queries a range of search results from the FDG renderer.
// It returns a types.FdgResponse structure containing the results (see the Entries field).
func (c *Client) GetFdgResults(s Search, start, end uint64) (types.FdgResponse, error) {
req := types.FdgRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
}
return c.getFdgResults(s, req)
}
// GetFdgTsRange queries search results for a time range from the fdg
// renderer. It returns a types.FdgResponse structure containing the results (see the Entries field)
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetFdgTsRange(s Search, start, end time.Time, first, last uint64) (types.FdgResponse, error) {
req := types.FdgRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_TS_RANGE,
EntryRange: &types.EntryRange{
StartTS: entry.FromStandard(start),
EndTS: entry.FromStandard(end),
First: first,
Last: last,
},
},
}
return c.getFdgResults(s, req)
}
func (c *Client) getStackGraphResults(s Search, req types.StackGraphRequest) (resp types.StackGraphResponse, err error) {
if s.RenderMod != types.RenderNameStackGraph {
err = fmt.Errorf("Search %v has invalid renderer type: expected stackgraph, saw %v", s.ID, s.RenderMod)
return
}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != req.ID {
err = errors.New("Invalid response ID")
}
return
}
// GetStackGraphResults queries a range of search results from the stackgraph renderer.
// It returns a types.StackGraphResponse structure containing the results (see the Entries field).
func (c *Client) GetStackGraphResults(s Search, start, end uint64) (types.StackGraphResponse, error) {
req := types.StackGraphRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
}
return c.getStackGraphResults(s, req)
}
// GetStackGraphTsRange queries search results for a time range from the stackgraph
// renderer. It returns a types.StackGraphResponse structure containing the results (see the Entries field)
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
func (c *Client) GetStackGraphTsRange(s Search, start, end time.Time, first, last uint64) (types.StackGraphResponse, error) {
req := types.StackGraphRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_TS_RANGE,
EntryRange: &types.EntryRange{
StartTS: entry.FromStandard(start),
EndTS: entry.FromStandard(end),
First: first,
Last: last,
},
},
}
return c.getStackGraphResults(s, req)
}
func (c *Client) getPointmapResults(s Search, req types.PointmapRequest) (resp types.PointmapResponse, err error) {
if s.RenderMod != types.RenderNamePointmap {
err = fmt.Errorf("Search %v has invalid renderer type: expected pointmap, saw %v", s.ID, s.RenderMod)
return
}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != req.ID {
err = errors.New("Invalid response ID")
}
return
}
// GetPointmapResults queries a range of search results from the pointmap renderer.
// It returns a types.PointmapResponse structure containing the results (see the Entries field).
// The fence parameter is an option geofence to apply to the results.
func (c *Client) GetPointmapResults(s Search, start, end uint64, fence types.Geofence) (types.PointmapResponse, error) {
req := types.PointmapRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
Fence: fence,
}
return c.getPointmapResults(s, req)
}
// GetPointmapTsRange queries search results for a time range from the pointmap
// renderer. It returns a types.PointmapResponse structure containing the results (see the Entries field)
// The 'first' and 'last' parameters specify indexes of entries to fetch within the timespan
// specified.
// The fence parameter is an option geofence to apply to the results.
func (c *Client) GetPointmapTsRange(s Search, start, end time.Time, first, last uint64, fence types.Geofence) (types.PointmapResponse, error) {
req := types.PointmapRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_TS_RANGE,
EntryRange: &types.EntryRange{
StartTS: entry.FromStandard(start),
EndTS: entry.FromStandard(end),
First: first,
Last: last,
},
},
Fence: fence,
}
return c.getPointmapResults(s, req)
}
func (c *Client) getHeatmapResults(s Search, req types.HeatmapRequest) (resp types.HeatmapResponse, err error) {
if s.RenderMod != types.RenderNameHeatmap {
err = fmt.Errorf("Search %v has invalid renderer type: expected heatmap, saw %v", s.ID, s.RenderMod)
return
}
if err = s.Exchange(req, &resp); err != nil {
return
} else if err = resp.Err(); err != nil {
return
} else if resp.ID != req.ID {
err = errors.New("Invalid response ID")
}
return
}
// GetHeatmapResults queries a range of search results from the heatmap renderer.
// It returns a types.HeatmapResponse structure containing the results (see the Entries field).
// The fence parameter is an option geofence to apply to the results.
func (c *Client) GetHeatmapResults(s Search, start, end uint64, fence types.Geofence) (types.HeatmapResponse, error) {
req := types.HeatmapRequest{
BaseRequest: types.BaseRequest{
ID: types.REQ_GET_ENTRIES,
EntryRange: &types.EntryRange{
First: start,
Last: end,
},
},
Fence: fence,
}
return c.getHeatmapResults(s, req)
}
// GetHeatmapTsRange queries search results for a time range from the heatmap