diff --git a/README.md b/README.md index b21a856..bd10428 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,9 @@ cf usage-report -o voyager cf usage-report -o voyager -o tenzing [-o orgName...] # report using different formats -cf usage-report -o voyager -o tenzing --format string cf usage-report -o voyager -o tenzing --format table +cf usage-report -o voyager -o tenzing --format string +cf usage-report -o voyager -o tenzing --format json ``` `--format table`: @@ -61,6 +62,14 @@ org tenzing is consuming 0 MB of 83968 MB across 2 org(s), you have 45 billable AIs, 37 are canonical AIs (30 running, 7 stopped), 8 are SCS instances ``` +`--format json`: + +This example is going to be a bit cluttered, so it's recommended using `jq` to parse the output. Then it could be used for parsing and interacting with other systems, like `cf-mgmt`: + +```json +{"SummaryReport":{"OrgReports":[{"AppInstancesCount":37,"AppsCount":28,"BillableAppInstancesCount":40,"BillableServicesCount":13,"MemoryQuota":83968,"MemoryUsage":60416,"Name":"voyager","RunningAppInstancesCount":30,"RunningAppsCount":21,"ServicesCount":16,"ServicesSuiteForPivotalPlatformCount":7,"SpringCloudServicesCount":3,"StoppedAppInstancesCount":7,"StoppedAppsCount":7,"SpaceReports":[{"AppInstancesCount":18,"AppsCount":16,"BillableAppInstancesCount":20,"BillableServicesCount":7,"MemoryQuota":-1,"MemoryUsage":25600,"Name":"dev","RunningAppInstancesCount":13,"RunningAppsCount":11,"ServicesCount":9,"ServicesSuiteForPivotalPlatformCount":4,"SpringCloudServicesCount":2,"StoppedAppInstancesCount":5,"StoppedAppsCount":5},{"AppInstancesCount":19,"AppsCount":12,"BillableAppInstancesCount":20,"BillableServicesCount":6,"MemoryQuota":-1,"MemoryUsage":34816,"Name":"test","RunningAppInstancesCount":17,"RunningAppsCount":10,"ServicesCount":7,"ServicesSuiteForPivotalPlatformCount":3,"SpringCloudServicesCount":1,"StoppedAppInstancesCount":2,"StoppedAppsCount":2}]},{"AppInstancesCount":0,"AppsCount":21,"BillableAppInstancesCount":5,"BillableServicesCount":18,"MemoryQuota":83968,"MemoryUsage":0,"Name":"tenzing","RunningAppInstancesCount":0,"RunningAppsCount":0,"ServicesCount":23,"ServicesSuiteForPivotalPlatformCount":9,"SpringCloudServicesCount":5,"StoppedAppInstancesCount":0,"StoppedAppsCount":21,"SpaceReports":[{"AppInstancesCount":0,"AppsCount":8,"BillableAppInstancesCount":2,"BillableServicesCount":6,"MemoryQuota":-1,"MemoryUsage":0,"Name":"dev","RunningAppInstancesCount":0,"RunningAppsCount":0,"ServicesCount":8,"ServicesSuiteForPivotalPlatformCount":3,"SpringCloudServicesCount":2,"StoppedAppInstancesCount":0,"StoppedAppsCount":8},{"AppInstancesCount":0,"AppsCount":9,"BillableAppInstancesCount":2,"BillableServicesCount":6,"MemoryQuota":-1,"MemoryUsage":0,"Name":"test","RunningAppInstancesCount":0,"RunningAppsCount":0,"ServicesCount":8,"ServicesSuiteForPivotalPlatformCount":3,"SpringCloudServicesCount":2,"StoppedAppInstancesCount":0,"StoppedAppsCount":9},{"AppInstancesCount":0,"AppsCount":4,"BillableAppInstancesCount":1,"BillableServicesCount":6,"MemoryQuota":-1,"MemoryUsage":0,"Name":"integration","RunningAppInstancesCount":0,"RunningAppsCount":0,"ServicesCount":7,"ServicesSuiteForPivotalPlatformCount":3,"SpringCloudServicesCount":1,"StoppedAppInstancesCount":0,"StoppedAppsCount":4}]}],"AppInstancesCount":37,"AppsCount":49,"BillableAppInstancesCount":45,"BillableServicesCount":31,"MemoryQuota":167936,"MemoryUsage":60416,"Name":"voyagertenzing","RunningAppInstancesCount":30,"RunningAppsCount":21,"ServicesCount":39,"ServicesSuiteForPivotalPlatformCount":16,"SpringCloudServicesCount":8,"StoppedAppInstancesCount":7,"StoppedAppsCount":28},"Format":"json"} +``` + ## use in pivotal licensing This plugin's usefulness for reporting things Pivotal's licensing on AI/SI packs and such is definitely a work in progress diff --git a/Taskfile.yml b/Taskfile.yml index 059f10c..b2c4aab 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -22,3 +22,4 @@ tasks: # TODO wasteful; maybe ability to specify multiple formats on a single run...? - cf usage-report -o voyager -o tenzing --format string - cf usage-report -o voyager -o tenzing --format table + - cf usage-report -o voyager -o tenzing --format json diff --git a/main.go b/main.go index ee7f414..888008e 100644 --- a/main.go +++ b/main.go @@ -35,8 +35,8 @@ func (cmd *UsageReportCmd) GetMetadata() plugin.PluginMetadata { Name: "cf-usage-report-plugin", Version: plugin.VersionType{ Major: 2, - Minor: 9, - Build: 2, + Minor: 10, + Build: 0, }, Commands: []plugin.Command{ { diff --git a/models/report.go b/models/report.go index 9683114..49e39c2 100644 --- a/models/report.go +++ b/models/report.go @@ -1,6 +1,9 @@ package models -// Report - +// Report should be present in all reports at all levels, +// e.g. summary level, org level, space level, etc. +// this allows us to calculate common data at discrete layers and be +// confident it'll be available when presenting the data type Report struct { AppInstancesCount int AppsCount int diff --git a/models/summary_report.go b/models/summary_report.go index ee76f85..e9f4b13 100644 --- a/models/summary_report.go +++ b/models/summary_report.go @@ -3,9 +3,10 @@ package models import "bytes" // SummaryReport holds an aggregated view of multiple OrgReports +// It effectively serves as the entrypoint into aggregating the data +// in preparation for it being presented type SummaryReport struct { OrgReports []OrgReport - orgsRef []Org Report } @@ -17,7 +18,6 @@ func NewSummaryReport(orgs []Org) *SummaryReport { } self := &SummaryReport{ - orgsRef: orgs, OrgReports: orgReports, } diff --git a/presenters/json_presenter.go b/presenters/json_presenter.go index ce91321..27d08a7 100644 --- a/presenters/json_presenter.go +++ b/presenters/json_presenter.go @@ -1,9 +1,18 @@ package presenters import ( + "encoding/json" + "fmt" + log "github.com/sirupsen/logrus" ) func (p *Presenter) asJSON() { - log.Fatalln("uhhh... TODO. You probably shouldn't have used interfaces for the reporters, you should 've used structs. But it made sense at the time.") + j, err := json.Marshal(p) + if err != nil { + log.Fatalln(err) + } + + // TODO maybe there's a cleaner way of outputting this than just a println + fmt.Println(string(j)) }