Skip to content

Commit

Permalink
Ensure we always pass this structure down to avoid any errors in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Sep 10, 2020
1 parent 78f6410 commit 6a415b2
Showing 1 changed file with 59 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,67 +119,75 @@ export async function getClustersFromRequest(
// add alerts data
if (isInCodePath(codePaths, [CODE_PATH_ALERTS])) {
const alertsClient = req.getAlertsClient();
if (alertsClient) {
for (const cluster of clusters) {
const verification = verifyMonitoringLicense(req.server);
if (!verification.enabled) {
// return metadata detailing that alerts is disabled because of the monitoring cluster license
cluster.alerts = {
alertsMeta: {
enabled: verification.enabled,
message: verification.message, // NOTE: this is only defined when the alert feature is disabled
},
list: {},
};
continue;
}

// check the license type of the production cluster for alerts feature support
const license = cluster.license || {};
const prodLicenseInfo = checkLicenseForAlerts(
license.type,
license.status === 'active',
'production'
);
if (prodLicenseInfo.clusterAlerts.enabled) {
cluster.alerts = {
list: await fetchStatus(
alertsClient,
req.server.plugins.monitoring.info,
undefined,
cluster.cluster_uuid,
start,
end,
[]
),
alertsMeta: {
enabled: true,
},
};
continue;
}
for (const cluster of clusters) {
const verification = verifyMonitoringLicense(req.server);
if (!verification.enabled) {
// return metadata detailing that alerts is disabled because of the monitoring cluster license
cluster.alerts = {
alertsMeta: {
enabled: verification.enabled,
message: verification.message, // NOTE: this is only defined when the alert feature is disabled
},
list: {},
};
continue;
}

if (!alertsClient) {
cluster.alerts = {
list: {},
alertsMeta: {
enabled: true,
},
clusterMeta: {
};
continue;
}

// check the license type of the production cluster for alerts feature support
const license = cluster.license || {};
const prodLicenseInfo = checkLicenseForAlerts(
license.type,
license.status === 'active',
'production'
);
if (prodLicenseInfo.clusterAlerts.enabled) {
cluster.alerts = {
list: await fetchStatus(
alertsClient,
req.server.plugins.monitoring.info,
undefined,
cluster.cluster_uuid,
start,
end,
[]
),
alertsMeta: {
enabled: false,
message: i18n.translate(
'xpack.monitoring.clusterAlerts.unsupportedClusterAlertsDescription',
{
defaultMessage:
'Cluster [{clusterName}] license type [{licenseType}] does not support Cluster Alerts',
values: {
clusterName: cluster.cluster_name,
licenseType: `${license.type}`,
},
}
),
},
};
continue;
}

cluster.alerts = {
list: {},
alertsMeta: {
enabled: true,
},
clusterMeta: {
enabled: false,
message: i18n.translate(
'xpack.monitoring.clusterAlerts.unsupportedClusterAlertsDescription',
{
defaultMessage:
'Cluster [{clusterName}] license type [{licenseType}] does not support Cluster Alerts',
values: {
clusterName: cluster.cluster_name,
licenseType: `${license.type}`,
},
}
),
},
};
}
}
}
Expand Down

0 comments on commit 6a415b2

Please sign in to comment.