Name

sn_itom_pattern.FindLogicalDataCenterByBucketName

Description

No description available

Script

var FindLogicalDataCenterByBucketName = Class.create();

FindLogicalDataCenterByBucketName.prototype = {
  initialize: function() {
      this.discoveryHostUtils = new global.DiscoveryHostUtils();
  },

  getHostForEndpoint: function(endpointGr) {

      //If the endpoint class extends cmdb_ci_aws_s3_endpoint, use the bucket name for pulling the LDC
      if ((endpointGr.getTableName() != 'cmdb_ci_endpoint_http') &&
          (endpointGr.getTableName() != 'cmdb_ci_aws_s3_endpoint')) {
          return null;
      }

      if ((!endpointGr.bucket_name) && (!endpointGr.url)) {
          return null;
      }

      var bucketName = "";
      if ((endpointGr.bucket_name) && (endpointGr.bucket_name != "")) {
          //Define bucket name - if bucket_name is not empty
          bucketName = endpointGr.bucket_name;
      } else {
          bucketName = GetBucketNameFromURL.parseUrl(endpointGr.url);
      }

      if (bucketName == "") {
          return null;
      }

      var cloudObjStorageGr = new GlideRecord('cmdb_ci_cloud_object_storage');
      if (!cloudObjStorageGr.isValid()) {
          return null;
      }

      cloudObjStorageGr.addQuery('name', bucketName);
      cloudObjStorageGr.query();

      if (cloudObjStorageGr.next()) {
          //verify the host is active (has valid OperationalStatus && InstallStatus && DiscoverySource)
          if (this.checkIsValidGr(cloudObjStorageGr)) {
              var relGr = new GlideRecord('cmdb_rel_ci');
              relGr.addQuery('parent', cloudObjStorageGr.getUniqueValue());
              relGr.addQuery('type', '5f985e0ec0a8010e00a9714f2a172815'); //Hosted on::Hosts
              relGr.query();
              if (relGr.next()) {
                  var childSysId = relGr.getValue('child');
                  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: 'FindLogicalDataCenterByBucketName'
};

Sys ID

8c8ce9a77322130051a5d6dcb7f6a771

Offical Documentation

Official Docs: