Selecting Particular MID for Cloud discovery and Provisioning.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2019 03:14 AM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2019 03:02 PM
Did this resolve your issue? If yes please mark the answer as correct so that it could benefit other community members.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2019 08:29 AM
I have the same issue. I am on London. How can I use MID Selection Override to select mid servers with only Cloud Management capability and rule out the ones with ALL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2019 11:19 AM
Hi Hardik,
I have the same kind of requirement. Cloud Management is picking up random MidServers when I perform cloud discovery. So I applied your code in the script include "CAPI MIDSELECTOR" and modified few things. Still, it's not picking the desired MidServers. Did I miss anything? Please help
Here is the code:
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-east-1') {
//locationPrefix = 'USW1';
}
}
if (service_account_id) {
if (service_account_id == '0c4cb046135be380219552722244b020') {
//accountPrefix = 'your_prefix';
}
}
if (!locationPrefix) {
return selectedMid;
}
if (!accountPrefix) {
return selectedMid;
}*/
var mid = new GlideRecord('ecc_agent');
mid.addQuery('name', 'STARTSWITH', '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'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2020 11:24 PM
https://hi.service-now.com/kb_view.do?sysparm_article=KB0749543
This knowledge article helped:
I added following code on line 59 and defined mid server in Discovery Credentials :
// Now we have everything set up - call the mid selector API to select one mid
var ServiceAccount = JSON.parse(context).service_account_id;
//gs.log("MK-Checking ServiceAccount="+ServiceAccount);
var credential='';
var gr = new GlideRecord("cmdb_ci_cloud_service_account");
gr.addQuery("account_id",ServiceAccount);
gr.query();
if(gr.next())
{
credential=gr.discovery_credentials.mid_list;
// gs.log("MK Credential is = "+credential);
}
if(credential!='')
{
return credential;
}
else
{
return midSelector.selectMid(app, null, capabilities, context);
}
},
