(db string, table string, orgID string)
| 111 | } |
| 112 | |
| 113 | func GetDatasources(db string, table string, orgID string) ([]string, error) { |
| 114 | var datasources []string |
| 115 | switch db { |
| 116 | case "flow_metrics", DB_NAME_PROFILE, DB_NAME_EVENT: |
| 117 | var tsdbType string |
| 118 | if table == "network" || table == "network_map" { |
| 119 | tsdbType = "network" |
| 120 | } else if table == "application" || table == "application_map" { |
| 121 | tsdbType = "application" |
| 122 | } else if table == TABLE_NAME_VTAP_ACL { |
| 123 | tsdbType = TABLE_NAME_VTAP_ACL |
| 124 | } else if table == TABLE_NAME_IN_PROCESS_METRICS { |
| 125 | tsdbType = TABLE_NAME_IN_PROCESS_METRICS |
| 126 | } else if table == TABLE_NAME_FILE_EVENT_METRICS { |
| 127 | tsdbType = TABLE_NAME_FILE_EVENT_METRICS |
| 128 | } else { |
| 129 | return datasources, nil |
| 130 | } |
| 131 | client := &http.Client{} |
| 132 | url := fmt.Sprintf("http://localhost:%d/v1/data-sources/?type=%s", config.ControllerCfg.ListenPort, tsdbType) |
| 133 | request, err := http.NewRequest("GET", url, nil) |
| 134 | if err != nil { |
| 135 | return datasources, err |
| 136 | } |
| 137 | request.Header.Set("X-Org-Id", orgID) |
| 138 | response, err := client.Do(request) |
| 139 | if err != nil { |
| 140 | return datasources, err |
| 141 | } |
| 142 | defer response.Body.Close() |
| 143 | if response.StatusCode != 200 { |
| 144 | return datasources, errors.New(fmt.Sprintf("get datasource error, url: %s, code '%d'", url, response.StatusCode)) |
| 145 | } |
| 146 | body, err := ParseResponse(response) |
| 147 | if err != nil { |
| 148 | return datasources, err |
| 149 | } |
| 150 | if body["DATA"] == nil || len(body["DATA"].([]interface{})) < 1 { |
| 151 | return datasources, errors.New(fmt.Sprintf("get datasources error, url: %s, response: '%v'", url, body)) |
| 152 | } |
| 153 | for _, datasource := range body["DATA"].([]interface{}) { |
| 154 | datasources = append(datasources, datasource.(map[string]interface{})["NAME"].(string)) |
| 155 | } |
| 156 | default: |
| 157 | return datasources, nil |
| 158 | } |
| 159 | return datasources, nil |
| 160 | } |
| 161 | |
| 162 | func GetDatasourceInterval(db string, table string, name string, orgID string) (int, error) { |
| 163 | var tsdbType string |
no test coverage detected