Name
global.FindLogicalDataCenterByS3Arn
Description
No description available
Script
var FindLogicalDataCenterByS3Arn = Class.create();
FindLogicalDataCenterByS3Arn.prototype = {
initialize: function() {
this.discoveryHostUtils = new DiscoveryHostUtils();
},
getHostForEndpoint: function(endpointGr) {
// If the endpoint class extends cmdb_ci_endpoint_arn, use the ARN field on the endpoint
if (!GlideDBObjectManager.get().isInstanceOf(endpointGr.getTableName(), 'cmdb_ci_endpoint_arn'))
return null;
if (!endpointGr.arn)
return null;
var rx = /(arn:)?aws:([^:]*):([^:]*):([^:]*):([^:/]+)/;
var groups = rx.exec(endpointGr.arn);
//groups[2] must be 's3', group[5] is bucket
if (groups && groups[2] && groups[5] && ('s3' === groups[2])) {
var cloudObjStorageGr = new GlideRecord('cmdb_ci_cloud_object_storage');
if (!cloudObjStorageGr.isValid())
return null;
gs.debug("FindLogicalDataCenterByS3Arn: Searching cmdb_ci_cloud_object_storage for object_id = {0}", endpointGr.arn);
cloudObjStorageGr.addQuery('object_id', endpointGr.arn);
cloudObjStorageGr.query();
while (cloudObjStorageGr.next()) {
//verify the host is active (has valid OperationalStatus && InstallStatus && DiscoverySource)
if (this.checkIsValidGr(cloudObjStorageGr)) {
gs.debug("FindLogicalDataCenterByS3Arn: Following Hosted on relations from {0}", cloudObjStorageGr.getUniqueValue());
var relGr = new GlideRecord('cmdb_rel_ci');
relGr.addQuery('parent', cloudObjStorageGr.getUniqueValue());
relGr.addQuery('type', '5f985e0ec0a8010e00a9714f2a172815'); //Hosted on::Hosts
relGr.query();
while (relGr.next()) {
var childSysId = relGr.getValue('child');
gs.debug("FindLogicalDataCenterByS3Arn: Found {0}, verifying if it is in cmdb_ci_aws_datacenter", childSysId);
var awsLdc = new GlideRecord('cmdb_ci_aws_datacenter');
//verify the host is active (has valid OperationalStatus && InstallStatus && DiscoverySource)
if (awsLdc.get(childSysId) && this.checkIsValidGr(awsLdc))
return childSysId;
}
}
}
}
return null;
},
checkIsValidGr: function(gr) {
return global.JSUtil.toBoolean(gs.getProperty("sa_find_host_scripts.check_host_active.enabled", "true")) ? this.discoveryHostUtils.isHostActive(gr) : true;
},
type: 'FindLogicalDataCenterByS3Arn'
};
Sys ID
f86796eef3ea1300449dae4716612b04