forked from ECSTeam/cf_get_events
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcf_bcr.go
703 lines (632 loc) · 19.8 KB
/
cf_bcr.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
// Copyright (c) 2016 ECS Team, Inc. - All Rights Reserved
// https://github.com/ECSTeam/cloudfoundry-top-plugin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"regexp"
"sort"
"strconv"
"strings"
"time"
"code.cloudfoundry.org/cli/plugin"
"github.com/olekukonko/tablewriter"
"github.com/simonleung8/flags"
)
// Events represents Buildpack Usage CLI interface
type Events struct{}
// Metadata is the data retrived from the response json
type Metadata struct {
GUID string `json:"guid"`
}
// /v2/info response json
type CCInfo struct {
Name string `json:"name"`
Build string `json:"build"`
}
// Inputs represent the parsed input args
type Inputs struct {
fromDate time.Time
toDate time.Time
isCsv bool
isJson bool
AI bool
SI bool
monthly bool
labelSpace string // "" if not used
}
type Total struct {
org int
space int
app int
appUser int
appStarted int
appUserStarted int
AI int
AIStarted int
AIUser int
AIUserStarted int
mem int
memStarted int
memUser int
memUserStarted int
si int
siMySQL int
siRabbitMQ int
siRedis int
siOther int
}
// GetMetadata provides the Cloud Foundry CLI with metadata to provide user about how to use `bcr` command
func (c *Events) GetMetadata() plugin.PluginMetadata {
return plugin.PluginMetadata{
Name: "bcr",
Version: plugin.VersionType{
Major: 2,
Minor: 5,
Build: 0,
},
Commands: []plugin.Command{
{
Name: "bcr",
HelpText: "Get Apps and Services consumption details",
UsageDetails: plugin.Usage{
Usage: UsageText(),
},
},
{
Name: "label-space",
HelpText: "Manage space level labels metadata",
UsageDetails: plugin.Usage{
Usage: UsageTextLabelSpace(),
},
},
},
}
}
func main() {
plugin.Start(new(Events))
}
// Run is what is executed by the Cloud Foundry CLI when the bcr command is specified
func (c Events) Run(cli plugin.CliConnection, args []string) {
var ins Inputs
switch args[0] {
case "bcr":
if len(args) >= 2 {
ins = c.buildClientOptions(args)
// continue below
} else {
Usage(1)
}
case "label-space":
if len(args) == 1 {
c.GetLabelSpace(cli)
os.Exit(0)
} else if len(args) == 3 {
command := args[1]
arg := args[2]
switch command {
case "--write":
c.WriteLabelSpace(arg, cli)
c.GetLabelSpace(cli)
case "--delete":
c.DeleteLabelSpace(arg, cli)
c.GetLabelSpace(cli)
case "--search":
c.SearchLabelSpace(arg, cli)
default:
Usage(1)
}
os.Exit(0)
}
Usage(1)
default:
Usage(0)
}
// main BCR routine starts here
// cf api endpoint
api, _ := cli.ApiEndpoint()
fmt.Printf("%s\n", api)
// always reports PAS version
var tRes CCInfo
output, _ := cli.CliCommandWithoutTerminalOutput("curl", "/v2/info")
json.Unmarshal([]byte(strings.Join(output, "")), &tRes)
fmt.Printf("%s (%s)\n", tRes.Build, tRes.Name)
// reports label if used
if ins.labelSpace != "" {
fmt.Printf("Filtering spaces with label selector: %s\n", ins.labelSpace)
}
fmt.Printf("\n")
if ins.monthly {
month := c.GetMonthlyUsage(cli)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Year", "Month", "AI avg", "AI max", "Task concurrent", "Task total runs"})
for _, m := range month {
table.Append([]string{
strconv.Itoa(m.Year), strconv.Itoa(m.Month),
fmt.Sprintf("%.0f", m.Avg), strconv.Itoa(m.Max),
strconv.Itoa(m.TaskMaxConcurrent), strconv.Itoa(m.TaskTotalRun)})
}
table.Render()
}
// reports space label_selector if any
//TODO
orgs := c.GetOrgs(cli)
spaces := c.GetSearchSpacesv3(ins.labelSpace, cli) // optional label_selector search
// clean orgs from label_selector spaces
// TODO O(nxn) optimize for large scale
for oguid, _ := range orgs {
ofound := false
for _, space := range spaces {
if space.OrgGUID() == oguid {
ofound = true
break
}
}
if !ofound {
delete(orgs, oguid)
}
}
var total Total
total.org = len(orgs)
total.space = len(spaces)
var services map[string]ServiceSearchEntity
var plans map[string]ServicePlanSearchEntity
var serviceInstances map[string]ServiceInstanceSearchEntity
var apps AppSearchResults
// Data loading
if ins.SI {
services = c.GetServices(cli)
plans = c.GetServicePlans(cli)
serviceInstances = c.GetServiceInstances(cli)
// filter for label_selector spaces
for siguid, si := range serviceInstances {
if _, afound := spaces[si.SpaceGuid]; afound {
} else {
delete(serviceInstances, siguid)
}
}
}
if ins.AI {
apps = c.GetAppData(cli)
// filter for label_selector spaces
filterapps := make([]AppSearchResources, 0)
for _, app := range apps.Resources {
if _, afound := spaces[app.Entity.SpaceGUID]; afound {
// app is in a space that we want to keep with label_selector
filterapps = append(filterapps, app)
}
}
apps.Resources = filterapps
apps.TotalResults = len(filterapps)
}
// services instances -- DEBUG only
if ins.SI && false {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Org", "Space", "Service Instance"})
//TODO loop on org, space id
for _, si := range serviceInstances {
table.Append([]string{orgs[spaces[si.SpaceGuid].OrgGUID()].Name, spaces[si.SpaceGuid].Name, si.Name})
}
table.Render()
}
// sort orgs by org Name
i := 0
sortedOrgs := make([]string, len(orgs))
for k := range orgs {
sortedOrgs[i] = k
i++
}
sort.Slice(sortedOrgs, func(i, j int) bool {
switch strings.Compare(strings.ToLower(orgs[sortedOrgs[i]].Name), strings.ToLower(orgs[sortedOrgs[j]].Name)) {
case -1:
return true
case 1:
return false
}
return true
})
//TODO sort space by Name and use it below
//TODO for some reasons space is at least grouped?
// *** SI table
if ins.SI {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Org", "Space", "SI", "Pivotal MySQL", "Pivotal RabbitMQ", "Pivotal Redis", "Other Services"})
//TODO - BROKERAGE, other?
for _, oguid := range sortedOrgs {
for sguid, space := range spaces {
if space.OrgGUID() == oguid {
siSpace := 0
siList := make(map[string]int)
for _, si := range serviceInstances {
if si.SpaceGuid == sguid && si.Type == "managed_service_instance" {
siSpace++
siList[services[plans[si.ServicePlanGuid].ServiceGuid].Label /*+":"+plans[si.ServicePlanGuid].Name*/] += 1
}
}
flat := []string{}
siMySQL := 0
siRabbitMQ := 0
siRedis := 0
siOther := 0
for n, c := range siList {
total.si += c
switch n {
case "p-mysql":
siMySQL += c
total.siMySQL += c
case "p.mysql":
siMySQL += c
total.siMySQL += c
case "p-rabbitmq":
siRabbitMQ += c
total.siRabbitMQ += c
case "p.rabbitmq":
siRabbitMQ += c
total.siRabbitMQ += c
case "p-redis":
siRedis += c
total.siRedis += c
case "p.redis":
siRedis += c
total.siRedis += c
default:
// special case for RabbitMQ tile replicator and naming convention
if strings.HasPrefix(n, "p-rabbitmq-") {
siRabbitMQ += c
total.siRabbitMQ += c
} else {
siOther += c
total.siOther += c
flat = append(flat, n+":"+strconv.Itoa(c))
}
}
//flat = append(flat, n+":"+strconv.Itoa(c))
}
siMySQLstring := ""
if siMySQL > 0 {
siMySQLstring = strconv.Itoa(siMySQL)
}
siRabbitMQstring := ""
if siRabbitMQ > 0 {
siRabbitMQstring = strconv.Itoa(siRabbitMQ)
}
siRedisstring := ""
if siRedis > 0 {
siRedisstring = strconv.Itoa(siRedis)
}
table.Append([]string{orgs[oguid].Name, spaces[sguid].Name, strconv.Itoa(siSpace),
siMySQLstring, siRabbitMQstring, siRedisstring,
strings.Join(flat, ",")})
}
}
}
//TODO total SI and Pivotal SI
table.SetFooter([]string{"-", "-", strconv.Itoa(total.si), strconv.Itoa(total.siMySQL), strconv.Itoa(total.siRabbitMQ), strconv.Itoa(total.siRedis), strconv.Itoa(total.siOther) + " (Pivotal: " + strconv.Itoa(total.si-total.siOther) + ")"})
table.Render()
}
// *** SI summary
// sort service by service Label
i = 0
sortedServices := make([]string, len(services))
for k := range services {
sortedServices[i] = k
i++
}
sort.Slice(sortedServices, func(i, j int) bool {
switch strings.Compare(strings.ToLower(services[sortedServices[i]].Label), strings.ToLower(services[sortedServices[j]].Label)) {
case -1:
return true
case 1:
return false
}
return true
})
if ins.SI {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Service", "Plan", "Service Instances"})
for _, guid := range sortedServices {
for planGuid, plan := range plans {
if plan.ServiceGuid == guid {
var count = 0
for _, si := range serviceInstances {
if si.ServicePlanGuid == planGuid {
count++
}
}
//if label_selector is used, then display only if not 0
if ins.labelSpace != "" && count == 0 {
} else {
table.Append([]string{services[plan.ServiceGuid].Label, plan.Name, strconv.Itoa(count)})
}
}
}
}
table.Render()
}
// *** APP table
if ins.AI {
total.app = len(apps.Resources)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Org", "Space", "App", "AI", "Memory", "State", "Memory usage"})
// order by Orgs, then by Space, then by State
for _, oguid := range sortedOrgs {
for sguid, space := range spaces {
if space.OrgGUID() == oguid {
// count non system only
if orgs[oguid].Name != "system" { //&& orgs[oguid] != "p-spring-cloud-services" {
for _, val := range apps.Resources {
if val.Entity.SpaceGUID == sguid {
total.appUser++
total.AIUser += val.Entity.Instances
total.memUser += val.Entity.Instances * val.Entity.Memory
if val.Entity.State == "STARTED" {
total.AIUserStarted += val.Entity.Instances
total.appUserStarted++
total.memUserStarted += val.Entity.Instances * val.Entity.Memory
}
}
}
}
// STARTED first
for _, val := range apps.Resources {
if val.Entity.SpaceGUID == sguid && val.Entity.State == "STARTED" {
total.AI += val.Entity.Instances
total.mem += val.Entity.Instances * val.Entity.Memory
total.AIStarted += val.Entity.Instances
total.memStarted += val.Entity.Instances * val.Entity.Memory
total.appStarted++
memUsage := val.Entity.Instances * val.Entity.Memory
table.Append([]string{orgs[spaces[val.Entity.SpaceGUID].OrgGUID()].Name, spaces[val.Entity.SpaceGUID].Name, val.Entity.Name,
strconv.Itoa(val.Entity.Instances), strconv.Itoa(val.Entity.Memory), val.Entity.State, strconv.Itoa(memUsage)})
//fmt.Printf("%s,%s,%s,%d,%d,%s\n",
// orgs[spaces[val.Entity.SpaceGUID].OrgGUID()], spaces[val.Entity.SpaceGUID].Name, val.Entity.Name,
// val.Entity.Instances, val.Entity.Memory, val.Entity.State)
}
}
// any other state then
for _, val := range apps.Resources {
if val.Entity.SpaceGUID == sguid && val.Entity.State != "STARTED" {
total.AI += val.Entity.Instances
total.mem += val.Entity.Instances * val.Entity.Memory
table.Append([]string{orgs[spaces[val.Entity.SpaceGUID].OrgGUID()].Name, spaces[val.Entity.SpaceGUID].Name, val.Entity.Name,
strconv.Itoa(val.Entity.Instances), strconv.Itoa(val.Entity.Memory), val.Entity.State, ""})
//fmt.Printf("%s,%s,%s,%d,%d,%s\n",
// orgs[spaces[val.Entity.SpaceGUID].OrgGUID()], spaces[val.Entity.SpaceGUID].Name, val.Entity.Name,
// val.Entity.Instances, val.Entity.Memory, val.Entity.State)
}
}
}
}
}
table.SetFooter([]string{strconv.Itoa(total.org), strconv.Itoa(total.space), strconv.Itoa(total.app), strconv.Itoa(total.AI), strconv.Itoa(total.mem), strconv.Itoa(total.appStarted) + " (started)", strconv.Itoa(total.memStarted)})
table.SetFooter([]string{"-", "-", "-", "-", "-", "-"})
table.Render()
// org mem usage and AI running per org
table = tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Org", "Memory Limit", "Memory Usage", "Usage %", "AI (started)"})
var orgsSummary = c.GetOrgsSummary(cli)
for _, oguid := range sortedOrgs {
val := orgsSummary[oguid]
aicount := 0
for spaceGuid, space := range spaces {
if space.OrgGUID() == oguid {
for _, app := range apps.Resources {
if app.Entity.SpaceGUID == spaceGuid && app.Entity.State == "STARTED" {
aicount += app.Entity.Instances
}
}
}
}
table.Append([]string{val.Name, strconv.Itoa(val.MemoryLimitOrgQuota), strconv.Itoa(val.Memory), strconv.Itoa(val.MemoryUsage), strconv.Itoa(aicount)})
}
table.Render()
// summary table
table = tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Category", "App", "AI", "Memory"})
table.Append([]string{"Total", strconv.Itoa(total.app), strconv.Itoa(total.AI), strconv.Itoa(total.mem)})
table.Append([]string{"Total (excl system)", strconv.Itoa(total.appUser), strconv.Itoa(total.AIUser), strconv.Itoa(total.memUser)})
table.Append([]string{"STARTED", strconv.Itoa(total.appStarted), strconv.Itoa(total.AIStarted), strconv.Itoa(total.memStarted)})
table.Append([]string{"STARTED (excl system)", strconv.Itoa(total.appUserStarted), strconv.Itoa(total.AIUserStarted), strconv.Itoa(total.memUserStarted)})
table.Render()
}
if false {
//events := c.GetEventsData(cli, ins)
//c.FilterResults(cli, ins, orgs, spaces, apps, events)
//results := c.FilterResults(cli, ins, orgs, spaces, apps, events)
/*
if ins.isCsv {
c.EventsInCSVFormat(results)
} else {
c.EventsInJsonFormat(results)
}
*/
}
}
func Usage(code int) {
fmt.Println("\nUsage: ", UsageText())
fmt.Println("\nUsage: ", UsageTextLabelSpace())
os.Exit(code)
}
func UsageText() string {
usage := "cf bcr [options]" +
"\n --monthly" +
"\n --ai" +
"\n --si" +
"\n --label-space <label_selector> (optional)"
return usage
}
func UsageTextLabelSpace() string {
usage := "cf label-space [options]" +
"\n (no argument) shows labels for current space" +
"\n --write com.test/key=value write label for current space" +
"\n --delete com.test/key delete label for current space" +
"\n --search <label_selector> search across all orgs & spaces"
return usage
}
func GetStartOfDay(today time.Time) time.Time {
var now = fmt.Sprintf("%s", today.Format("2006-01-02"))
t, _ := time.Parse(time.RFC3339, now+"T00:00:00Z")
return t
}
func GetEndOfDay(today time.Time) time.Time {
var now = fmt.Sprintf("%s", today.Format("2006-01-02"))
t, _ := time.Parse(time.RFC3339, now+"T23:59:59Z")
return t
}
// sanitize data by replacing \r, and \n with ';'
func sanitize(data string) string {
var re = regexp.MustCompile(`\r?\n`)
var str = re.ReplaceAllString(data, ";")
str = strings.Replace(str, ";;", ";", 1)
return str
}
// read arguments passed for the plugin
func (c *Events) buildClientOptions(args []string) Inputs {
fc := flags.New()
/*
fc.NewBoolFlag("all", "all", " get all events (defaults to last 90 days)")
fc.NewBoolFlag("today", "today", "get all events for today (till now)")
fc.NewBoolFlag("yesterday", "yest", "get events from yesterday only")
fc.NewBoolFlag("yesterday-on", "yon", "get events for yesterday onwards (till now)")
fc.NewStringFlag("from", "fr", "get events from given date [+ time] onwards (till now)")
fc.NewStringFlag("to", "to", "get events till given date [+ time]")
fc.NewBoolFlag("json", "js", "list output in json format (default is csv)")
*/
// for AI SI
fc.NewBoolFlag("ai", "ai", "Application instances")
fc.NewBoolFlag("si", "si", "Service instances")
fc.NewBoolFlag("monthly", "monthly", "Monthly usage report, last 7 months")
fc.NewStringFlagWithDefault("label-space", "label-space", "(optional) label selector for spaces", "")
err := fc.Parse(args[1:]...)
if err != nil {
fmt.Println("\n Receive error reading arguments ... ", err)
Usage(1)
}
today := time.Now()
var ins Inputs
ins.isCsv = true
ins.isJson = false
ins.fromDate = GetStartOfDay(today)
ins.toDate = time.Now()
if fc.IsSet("ai") {
ins.AI = true
}
if fc.IsSet("si") {
ins.SI = true
}
if fc.IsSet("monthly") {
ins.monthly = true
}
if fc.IsSet("label-space") {
ins.labelSpace = fc.String("label-space")
}
/*
if fc.IsSet("all") {
nintyDays := time.Hour * -(24 * 90)
ins.fromDate = today.Add(nintyDays) // today - 90 days
}
if fc.IsSet("today") {
ins.fromDate = GetStartOfDay(today)
}
if fc.IsSet("yesterday") {
oneDay := time.Hour * -24
ins.fromDate = GetStartOfDay(today.Add(oneDay)) // today - 1 day
ins.toDate = GetEndOfDay(ins.fromDate)
}
if fc.IsSet("yesterday-on") {
oneDay := time.Hour * -24
ins.fromDate = GetStartOfDay(today.Add(oneDay)) // today - 1 day
}
if fc.IsSet("from") {
var value = fc.String("from")
var layout string
switch len(value) {
case 8:
layout = "20060102" // yyyymmdd
case 14:
layout = "20060102150405" // yyyymmddhhmmss
default:
fmt.Println("Error: Failed to parse `from` date - ", value)
fmt.Println(err)
Usage(1)
}
t, err := time.Parse(layout, value)
// fmt.Println("-------> (1) filter date - ", t, filterDate, err)
if err != nil {
fmt.Println("Error: Failed to parse `from` date - ", value)
fmt.Println(err)
Usage(1)
} else {
ins.fromDate = t
}
}
if fc.IsSet("to") {
var value = fc.String("to")
const layout = "20060102150405" // yyyymmdd
switch len(value) {
case 8:
value = value + "235959"
case 14:
default:
fmt.Println("Error: Failed to parse `from` date - ", value)
fmt.Println(err)
Usage(1)
}
t, err := time.Parse(layout, value)
// fmt.Println("-------> (1) filter date - ", t, filterDate, err)
if err != nil {
fmt.Println("Error: Failed to parse given date - ", value)
fmt.Println(err)
Usage(1)
} else {
// filterDate = fmt.Sprintf("%s", t.Format("2006-01-02"))
ins.toDate = t
}
}
if fc.IsSet("json") {
ins.isJson = true
ins.isCsv = false
}
// fmt.Println("-------> (1) ins - ", ins.fromDate, ins.toDate)
*/
return ins
}
// prints the results as a csv text to console
func (c Events) EventsInCSVFormat(results OutputResults) {
fmt.Println("")
fmt.Printf(results.Comment)
// "20161212", "dr", "lab", "app", "pcf-status", "pcf-status", "app.crash", "crashed", "2 error(s) occurred:\n\n* 2 error(s) occurred:\n\n* Exited with status 255 (out of memory)\n* cancelled\n* 1 error(s) occurred:\n\n* cancelled"
// "2016-12-09T21:44:46Z", "demo", "sandbox", "app", "test-nodejs", "admin", "app.update", "stopped", ""
fmt.Printf("%s,%s,%s,%s,%s,%s,%s,%s\n", "DATE", "ORG", "SPACE", "ACTEE-TYPE", "ACTEE-NAME", "ACTOR", "EVENT TYPE", "DETAILS")
for _, val := range results.Resources {
var mdata = sanitize(fmt.Sprintf("%+v", val.Entity.Metadata))
fmt.Printf("%s,%s,%s,%s,%s,%s,%s,%s\n",
val.Entity.Timestamp, val.Entity.Org, val.Entity.Space,
val.Entity.ActeeType, val.Entity.ActeeName, val.Entity.ActorName, val.Entity.Type, mdata)
}
}
// prints the results as a json text to console
func (c Events) EventsInJsonFormat(results OutputResults) {
var out bytes.Buffer
b, _ := json.Marshal(results)
err := json.Indent(&out, b, "", "\t")
if err != nil {
fmt.Println(" Recevied error formatting json output.")
} else {
fmt.Println(out.String())
}
}