The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selecting Particular MID for Cloud discovery and Provisioning.

Sumeet Verma
Mega Expert

Hi there,

is there a way to use a particular MID server for my cloud discovery through service accounts.

i have multiple domain and multiple MIDs with cloud management, ALL and other capabilities added, so when i hit discovery on cloud schedules it tried all the MIDs which has the capability in it. so it success when my cloud MID is used and fails when other MID are used.

i want only my cloud MID to be used in case of cloud discovery.

i tried tweaking the CAPIs (CAPIMidSelector) by assigning could account id and particular MID to that but it doesn't work.

find_real_file.png

by default we dont have any option to assign a particular MID to a Cloud discovery schedules, they're hidden by UI policy, when i disable the ui policy and assign a particular MID to a cloud discovery schedule even though it takes all MID added with ALL or cloud management capability.

find_real_file.png

8 REPLIES 8

DaveHertel
Kilo Sage
Kilo Sage

Hi - because Cloud capabilities have to be explicitly assigned, why not just limit that assignment to the MID's you want for Cloud, and remove that capability from MID's that are not desired?  Perhaps I'm missing something -- seems like this should simply limit the alternatives down to the desired MID.   Perhaps I missed something in the question?  

Sumeet Verma
Mega Expert

Hi Dave,

i need to have multiple MIDs with cloud management and ALL capabilities added as i'm running multiple clients with multi domains.

i can't restrict other MIDs by removing their capabilities.

is there a way to assign a particular MID only for Cloud management to call CAPIs??

my need is to use a particular MID for cloud APIs call ups.

You can try something below:

var CAPIMidSelector = Class.create();

CAPIMidSelector.prototype = {
	initialize: function(parameters) {
		this.parameters = parameters;
	},

	overrideMid: function() {    
		/*
 		* The mid server selected by CAPI is available in a variable named "resolvedMid".
 		* The selection can be overriden and the name of the resolved mid should be returned
 		* The following parameters are available when this script executes
 		*     capabilities - Capabilities that need to be set on the MID to execute this API
 		*     targets - Targets that the MID should be able to reach - Optional parameter
 		*     capi_interface_name - Name of the Cloud API interface
 		*     capi_method_name - Name of the method that's being executed
 		*     capi_impl_name - Name of the Cloud API implementation
 		*     service_account_id - Account ID from the Service Account used for this API execution
 		*     location_name - Region Name/Datacenter name that's being used for this API execution - Optional parameter
 		*     resolvedMid - The MID selected for the current execution
 		*     MidServers - A list of mid servers that can be used for this request, if more than 1 is available
 		*/

		var selectedMid = '';
		var locationPrefix = '';
		var accountPrefix  = '';
		gs.log('CAPIMidSelector1 ', 'CAPIMidSelector1');
		
		
		if (location_name) {

			if (location_name == 'us-west-1') {
				locationPrefix = 'USW1';
			}
		}

		if (service_account_id) {

			if (service_account_id == '<account_id>') {
				accountPrefix = 'your_prefix';
			}
		}

		if (!locationPrefix) {
			return selectedMid;

		}
 
		if (!accountPrefix) {
			return selectedMid;
		}
		var mid = new GlideRecord('ecc_agent');
		mid.addQuery('name', 'STARTSWITH', 'CMP-AWS');
		mid.addQuery('name', 'CONTAINS', locationPrefix);
		mid.addQuery('status','Up');
		mid.addQuery('validated',true);
		mid.query();
		while (mid.next()) {
			if (capi_method_name && (capi_method_name.toLowerCase().startsWith('list') || capi_method_name.toLowerCase().startsWith('get')) && mid.getValue('host_type').toLowerCase() == 'linux') {
				selectedMid = mid.getValue('name');
				//here you can pass the name of the midserver as hardcoded value.
				break;
			} else if (capi_method_name && !(capi_method_name.toLowerCase().startsWith('list') || capi_method_name.toLowerCase().startsWith('get') ||  mid.getValue('host_type').toLowerCase() == 'windows') {
				selectedMid = mid.getValue('name');
				break;
			}
		}
		return selectedMid;
	},

	type: 'CAPIMidSelector'
};

 

Also note that CAPIMidSelector is now superseded by CloudMidSelector from London onwards. MidApis' will try to first find the most restrictive MidServer if it doesn't find that then it will go to other. 

If this doesn't work you will have to you will have to remove ALL from capabilities list atleast for the domain which is using cloud

Note: If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list."

 

Hardik Benani
Kilo Sage
Kilo Sage

You can try something below:

var CAPIMidSelector = Class.create();

CAPIMidSelector.prototype = {
	initialize: function(parameters) {
		this.parameters = parameters;
	},

	overrideMid: function() {    
		/*
 		* The mid server selected by CAPI is available in a variable named "resolvedMid".
 		* The selection can be overriden and the name of the resolved mid should be returned
 		* The following parameters are available when this script executes
 		*     capabilities - Capabilities that need to be set on the MID to execute this API
 		*     targets - Targets that the MID should be able to reach - Optional parameter
 		*     capi_interface_name - Name of the Cloud API interface
 		*     capi_method_name - Name of the method that's being executed
 		*     capi_impl_name - Name of the Cloud API implementation
 		*     service_account_id - Account ID from the Service Account used for this API execution
 		*     location_name - Region Name/Datacenter name that's being used for this API execution - Optional parameter
 		*     resolvedMid - The MID selected for the current execution
 		*     MidServers - A list of mid servers that can be used for this request, if more than 1 is available
 		*/

		var selectedMid = '';
		var locationPrefix = '';
		var accountPrefix  = '';
		gs.log('CAPIMidSelector1 ', 'CAPIMidSelector1');
		
		
		if (location_name) {

			if (location_name == 'us-west-1') {
				locationPrefix = 'USW1';
			}
		}

		if (service_account_id) {

			if (service_account_id == '<account_id>') {
				accountPrefix = 'your_prefix';
			}
		}

		if (!locationPrefix) {
			return selectedMid;

		}
 
		if (!accountPrefix) {
			return selectedMid;
		}
		var mid = new GlideRecord('ecc_agent');
		mid.addQuery('name', 'STARTSWITH', 'CMP-AWS');
		mid.addQuery('name', 'CONTAINS', locationPrefix);
		mid.addQuery('status','Up');
		mid.addQuery('validated',true);
		mid.query();
		while (mid.next()) {
			if (capi_method_name && (capi_method_name.toLowerCase().startsWith('list') || capi_method_name.toLowerCase().startsWith('get')) && mid.getValue('host_type').toLowerCase() == 'linux') {
				selectedMid = mid.getValue('name');
				//here you can pass the name of the midserver as hardcoded value.
				break;
			} else if (capi_method_name && !(capi_method_name.toLowerCase().startsWith('list') || capi_method_name.toLowerCase().startsWith('get') ||  mid.getValue('host_type').toLowerCase() == 'windows') {
				selectedMid = mid.getValue('name');
				break;
			}
		}
		return selectedMid;
	},

	type: 'CAPIMidSelector'
};

 

Also note that CAPIMidSelector is now superseded by CloudMidSelector from London onwards. MidApis' will try to first find the most restrictive MidServer if it doesn't find that then it will go to other. 

If this doesn't work you will have to you will have to remove ALL from capabilities list atleast for the domain which is using cloud

Note: If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list."