The purpose of this package/library/types is to interpret the contents of dsinfo.json file. the dsinfo.json file consist the complete structure and contents of the support bundle. So we can utilze this file to automate our investigation process. But the contents of dsinfo.json is not directly usable because it has different files of different format. This package attempts to interpret the various contents of the dsinfo.json file with proper structure.
This package could be utilized while creating an API server or a command line tool to parse/interpret dsinfo.json file.
At first, we need to read the file and unmarshal it with the core structure. The core structure won't unmarshal the fileds with proper sturcture but it will keep most of the fileds as byte array. But when we need to interpret the contents of the specific filed we can unmarshal them with appropriate structure. We have choose this path to reduce memory footprint, as sometimes dsinfo.json file could be big as 10GB.
So initially, we can do something like the following to unmarshal the core structure,
var file = "dsinfo.json"
dsinfoJson, err := ioutil.ReadFile(file)
if err != nil {
fmt.Errorf("cannot Read File %s", err)
}
var core CoreDsinfo
err = json.Unmarshal(dsinfoJson, &core)
if err != nil {
fmt.Errorf("Cannot unmarshal %s", err)
}After that we can see the contents of the core's filed with the following ways.
To collect at Json format , easily parsable by jq
nodeInspect := NewNodeParser().GetAllJSON(&core.UcpNodesTxt)
fmt.Println(nodeInspect)To collect the data with proper structure
nodeInspect := NewNodeParser().GetAll(&core.UcpNodesTxt)
fmt.Println(nodeInspect[0].Description.Engine.EngineVersion)You can also iterate all nodes and collect the info. For details, go to ucpnodestxt.go->type UCPNodesTxtType
for k, _ := range nodeInspect {
fmt.Printf("Hostname: %s\n\tEngine Version: %s\n\tRole: %s\n", nodeInspect[k].Description.Hostname, nodeInspect[k].Description.Engine.EngineVersion, nodeInspect[k].Spec.Role)
}Here data is already in json format.
To collect at json format
fmt.Println(string(core.UcpTelemetryJson))To collect the data with proper structure. For details go to ucp_controller_config.go
data := NewUCPTelemetry().GetAll(&core.UcpTelemetryJson)
fmt.Printf("Cluster ID: %s\n\tIs Licensed: %v\n\tOS: %s\n\tKernel Version:%s\n", data.ClusterId, data.IsLicensed, data.Os, data.KernelVersion)
fmt.Println(data.Kubernetes.ManagerReservedResources)- Use
UcpAuthApiTasksTxtforucp-auth-api-tasks.txt - Use
UcpAuthWorkerTasksTxtforucp-auth-worker-tasks.txt - Use
UcpClusterAgentTasksTxtforucp-cluster-agent-tasks.txt - Use
UcpInterlockConfigTasksTxtforucp-interlock-config-tasks.txt - Use
UcpInterlockExtensionTasksTxtforucp-interlock-extension-tasks.txt - Use
UcpInterlockProxyTasksTxtforucp-interlock-proxy-tasks.txt - Use
UcpInterlockTasksTxtforucp-interlock-tasks.txt - Use
UcpManagerAgentTasksTxtforucp-manager-agent-tasks.txt - Use
UcpWorkerAgentWinXTasksTxtforucp-worker-agent-win-x-tasks.tx - Use
UcpWorkerAgentXTasksTxtforucp-worker-agent-x-service.txt
To collect at Json format , easily parsable by jq
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpAuthApiTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpAuthWorkerTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpClusterAgentTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpInterlockConfigTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpInterlockExtensionTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpInterlockProxyTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpInterlockTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpManagerAgentTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpWorkerAgentWinXTasksTxt))
fmt.Println(NewTasksParser().GetAllJSON(&core.UcpWorkerAgentXTasksTxt))To collect the data with proper structure
data := NewTasksParser().GetAll(&core.UcpAuthApiTasksTxt)
fmt.Println(data[0].ServiceID)You can also iterate all fields and collect the info. For details, go to task_func.go
for k, _ := range data {
fmt.Printf("Task ID: %s\nImage: %s\n", data[k].ID, data[k].Spec.ContainerSpec.Image)
}- Use
UcpAuthApiServiceTxtforucp-auth-api-service.txt - Use
UcpAuthWorkerServiceTxtforucp-auth-worker-service.txt - Use
UcpClusterAgentServiceTxtforucp-cluster-agent-service.txt - Use
UcpInterlockServiceTxtforucp-interlock-service.txt - Use
UcpManagerAgentServiceTxtforucp-manager-agent-service.txt - Use
UcpWorkerAgentWinXServiceTxtforucp-worker-agent-win-x-service.txt - Use
UcpWorkerAgentXServiceTxtforucp-worker-agent-x-service.txt
To collect at json format
fmt.Println(string(core.UcpAuthApiServiceTxt))
fmt.Println(string(core.UcpAuthWorkerServiceTxt))
fmt.Println(string(core.UcpClusterAgentServiceTxt))
fmt.Println(string(core.UcpInterlockServiceTxt))
fmt.Println(string(core.UcpManagerAgentServiceTxt))
fmt.Println(string(core.UcpWorkerAgentWinXServiceTxt))
fmt.Println(string(core.UcpWorkerAgentXServiceTxt))To collect the data with proper structure. For details go to service_func.go
data := NewServiceParser().GetAll(&core.UcpAuthApiServiceTxt)
fmt.Printf("Name: %s\nID: %s\nImage: %s\n", data.Spec.Name, data.ID, data.Spec.TaskTemplate.ContainerSpec.Image)Here data is already in json format
To collect at json format
fmt.Println(string(core.MirantisLic))To collect the data with proper structure. For details go to mirantis_lic.go
data := NewLicenseType().GetAll(&core.MirantisLic)
fmt.Printf("Max Engine: %d\nExpiration Date: %s\n", data.Details.MaxEngines, data.Details.Expiration)Here data is already in json format
To collect at json format
fmt.Println(string(core.UcpControllerConfigJson))To collect the data with proper structure. For details go to ucp_controller_config.go
data := NewUCPControllerConfigType().GetAll(&core.UcpControllerConfigJson)
fmt.Println(data.IngressController.Enabled)
fmt.Println(data.Kubernetes.ManagerReservedResources)Following files are not in specific format,
- Use
UcpLicenseIdTxtforucp-license-id.txt - Use
TasksCountTxtfortasks-count.txt - Use
IngressDescribeAllTxtforingress-describe-all.txt - Use
IngressDescribeIngressTxtforingress-describe-ingress.txt - Use
IngressGetAllTxtforingress-get-all.txt - Use
IngressGetIngressTxtforingress-get-ingress.txt - Use
IngressNginxConfigTxtforingress-nginx-config.txt - Use
IngressNginxControllerTxtforingress-nginx-controller.txt - Use
KubeDescribeAllTxtforkube-describe-all.txt - Use
KubeDescribeNodesTxtforkube-describe-nodes.txt
To just print the string conents [some might require type assertion with string],
fmt.Println(core.UcpLicenseIdTxt)
fmt.Println(core.TasksCountTxt)
fmt.Println(core.IngressDescribeAllTxt)
fmt.Println(core.IngressDescribeIngressTxt)
fmt.Println(core.IngressGetAllTxt)
fmt.Println(core.IngressGetIngressTxt)
fmt.Println(core.IngressNginxControllerTxt)
fmt.Println(core.IngressNginxControllerTxt)
fmt.Println(core.KubeDescribeNodesTxt)
fmt.Println(core.KubeDescribeAllTxt)var file = "/home/arif/Documents/github/powerplug/dsinfo.json"
dsinfoJson, err := ioutil.ReadFile(file)
if err != nil {
fmt.Errorf("cannot Read File %s", err)
}
var nestedDsinfo = make(map[string]json.RawMessage)
err = json.Unmarshal(dsinfoJson, &nestedDsinfo)
if err != nil {
fmt.Errorf("Cannot unmarshal %s", err)
}
var nodeDsinfoStruct dsinfoSlashDsinfoDotJson
err = json.Unmarshal(nestedDsinfo["node01"], &nodeDsinfoStruct)
if err != nil {
fmt.Errorf("Cannot unmarshal nesteddsinfo")
}
var NodeContents NestedDsinfo
err = json.Unmarshal(nodeDsinfoStruct.DsinfoContents, &NodeContents)
//following will return the df command's output of "node01"
fmt.Println(string(NodeContents.Df))