Skip to content

Commit

Permalink
Combine the processing of the string to Grafana dashboards.
Browse files Browse the repository at this point in the history
  • Loading branch information
KeesCBakker committed Apr 23, 2024
1 parent d8eb15e commit af150e7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/service/GrafanaService.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ class GrafanaService {
this.logger = client.logger;
}

/**
* Processes the given string and returns an array of screenshot URLs for the requested dashboards.
*
* @param {string} str - The string to be processed.
* @param {number} maxReturnDashboards - The maximum number of dashboard screenshots to return.
* @returns {Array<DashboardResponse>|null} An array of DashboardResponse objects containing the screenshot URLs.
*/
async process(str, maxReturnDashboards){
const request = this.parseToGrafanaDashboardRequest(str);
if (!request) {
return null;
}

const dashboard = await this.getDashboard(request.uid);
if (!dashboard) {
return null;
}

const responses = await this.getScreenshotUrls(request, dashboard, maxReturnDashboards);
return responses;
}

/**
* Parses a string into a GrafanaDashboardRequest object.
* @param {string} str - The string to parse.
Expand Down Expand Up @@ -109,7 +131,7 @@ class GrafanaService {
* @param {GrafanaDashboardRequest} req - The request object.
* @param {GrafanaDashboardResponse.Response} dashboardResponse - The dashboard response object.
* @param {number} maxReturnDashboards - The maximum number of dashboards to return.
* @returns {Array<DashboardResponse>} An array of DashboardResponse objects containing the screenshot URLs.
* @returns {Array<DashboardResponse>|null} An array of DashboardResponse objects containing the screenshot URLs.
*/
async getScreenshotUrls(req, dashboardResponse, maxReturnDashboards) {
if (!dashboardResponse || dashboardResponse.message) return null;
Expand Down

0 comments on commit af150e7

Please sign in to comment.