func collectDashboardFolder()

in index.go [133:185]


func collectDashboardFolder(app, path, source string) ([]Visualization, map[string]string) {
	dashboardPath := filepath.Join(path, "dashboard")
	if _, err := os.Stat(dashboardPath); os.IsNotExist(err) {
		return nil, nil
	}
	var visualizations []Visualization
	dashboards := make(map[string]string)
	files, err := os.ReadDir(dashboardPath)
	if err != nil {
		fmt.Printf("Error reading dashboards directory: %v\n", err)
		return nil, nil
	}
	for _, file := range files {
		dashboardFilePath := filepath.Join(dashboardPath, file.Name())
		contents, err := ioutil.ReadFile(dashboardFilePath)
		if err != nil {
			fmt.Printf("Error reading dashboard file: %v\n", err)
			continue
		}
		var dashboard map[string]interface{}
		if err := json.Unmarshal(contents, &dashboard); err != nil {
			continue
		}
		commit, _ := getCommitData(dashboardFilePath)
		dashboardReferences := dashboard["references"].([]interface{})
		for _, reference := range dashboardReferences {
			ref := reference.(map[string]interface{})
			dashboards[ref["id"].(string)] = dashboard["attributes"].(map[string]interface{})["title"].(string)
		}
		panels, err := kbncontent.DescribeByValueDashboardPanels(dashboard)
		if err != nil {
			fmt.Printf("Issue parsing dashboard panels for %s: %v\n", dashboardFilePath, err)
		}
		for _, panel := range panels {
			visualizations = append(visualizations, Visualization{
				Doc:       panel.Doc,
				SoType:    panel.SavedObjectType,
				Link:      panel.Link,
				VisType:   panel.Type(),
				TSVBType:  panel.TSVBType(),
				VisTitle:  panel.Title(),
				IsLegacy:  panel.IsLegacy(),
				App:       app,
				Source:    source,
				Dashboard: dashboard["attributes"].(map[string]interface{})["title"].(string),
				Path:      dashboardFilePath,
				Commit:    commit,
			})
		}

	}
	return visualizations, dashboards
}