Pradyumna Das
Tera Expert

 

                                                        Servicenow Azure Cloud Discovery Setup

                                                           Version: Quebec Patch-4 Hotfix-2

 

Step-0: Install Required Plugin

    0.1: Install Cloud Management plugin(Option if using patterns)

    0.2: Varify that Discovery and Service Mapping Plugin(version should be greater than 1.0.80)

    0.3: Migrate CAG/CAPI to Patterns(Maximum 5mins will take)

    

Step-1: Create Azure Principle Credetinal(Using Client secrete, Client ID, TenantID).

  1.1- Create an application in AZURE

  1.2- Give read access to this application

  1.3-  Get Client secret,ClientID, TenantID

 

Step-2: Hit Get subscription UI action in the credential setup page

 

Step-3: Verify in the azure_subscription table that all subscriptions ID and Name are available in this table or not.

 

Step-4: Verify all the subscriptions automatically sync with the cmdb_ci_cloud_service_account table.If not then make sure the glide.discovery.cdu.auto_refresh_sub_accounts_and_ldcs property value should true.

 

Step-5: Create Azure schedules with the above-grabbed subscriptions. (There is no automation or master stuff to discover all the subscriptions. Have to create schedules for each discovery)

 

Additional Feature:

 

     1- Create a scheduled job to get all the subscriptions details and insert them into the azure_subscription table

listSubscriptions();
var credential = '3ae5f4071b11b4500b14fe261a4bcb1f';

function listSubscriptions() {
    var discoverStatus = new GlideRecord('discovery_status');
    discoverStatus.initialize();
    var discoveryStatusId = discoverStatus.insert();
    var resource = "Azure Datacenter";
    var order = {
        'resource': resource,
        'entityType': 'Resource',
        'operationName': 'Discovery Interface.ListSubscriptions',
        orderFormData: {
            'Credential': credential.toString(),
            'DiscoveryStatusId': discoveryStatusId + ''
        }
    };
    var orderScript = new sn_cmp_api.OrderServiceScript();
    orderScript.submitOrder(new global.JSON().encode(order));
    var mapping = new GlideRecord('sn_cmp_sp_dstatus_mapping');
    mapping.initialize();
    mapping.setValue('discovery_credentials', credential.toString());
    mapping.setValue('discovery_status', discoveryStatusId);
    mapping.insert();
}

 

 2- Create a Notification if any new subscription will be added someone has to notify and create a schedule

3- Create a Scripted Rest API which will accept the subscription ID and will trigger the respective schedules on-demand(Note: If the given subscription doesn’t have any schedules in the discovery scheduled table then it will throw an exception and will not trigger the discovery ).

 

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var result = {};
    var id = request.queryParams.SubscriptionId.toString(); //Create Query Parameter as SubscriptionId and pass this value while calling
    result.subsriptionID = id.toString();

    function getSubscriptionName(sub_id) {
        var sub = new GlideRecord('azure_subscription');
        sub.addQuery('id', sub_id);
        sub.query();
        if (sub.next()) {
            result.subsriptionName = sub.name.toString();
            return sub.name.toString();
        } else {
            result.subsriptionName = null;
            result.status = 'fail';
            result.reason = 'Given SubscriptionID is not present in the ServiceNow Database.Please connect with Servicenow Developer.';
        }
    }

    function getDiscoveryStatus(sysID) {
        var status = new GlideRecord('discovery_status');
        status.addQuery('sys_id', sysID);
        status.query();
        if (status.next()) {
            result.status = 'success';
            result.discovery = {
                number: status.number.toString(),
                discover: status.discover.getDisplayValue(),
                dscheduler: status.dscheduler,
				created: status.sys_created_on
            };
        } else {
            result.status = 'fail';
            result.reason = 'Something went wrong.Discovery not triggered.Please connect with servicenow Developer';
        }
    }

    function getSchedule(name) {
        var subscriptionName = getSubscriptionName(id);
        if (subscriptionName != '' && subscriptionName != null && subscriptionName != undefined) {
            var sch = new GlideRecord('discovery_schedule');
            sch.addQuery('name', subscriptionName);
            sch.addQuery('active', true);
            sch.query();
            var count = sch.getRowCount();
            if (count == 0) {
                result.status = 'fail';
                result.reason = 'No active schedules present for this given subscription';
            } else if (count == 1) {
                if (sch.next()) {
                    var disco = new Discovery();
                    getDiscoveryStatus(disco.discoverNow(sch)); //triggerDiscovery
                }
            } else {
                result.status = 'fail';
                result.reason = 'Multiple schedules found on this name. Please connect with Servicenow Developer';
            }
        }

    }
    if (id == '' || id==null || id==undefined) {
		result.subsriptionName = null;
        result.status = 'fail';
        result.reason = 'Please enter a valid SubscriptionID';
    } else {
        getSchedule(getSubscriptionName(id));
    }
    return result;

})(request, response);

 

 Please mark it helpful if it helps you in any manner.

 

Thank You,

Pradyumna Das

 

 

Comments
anitha0887
Tera Contributor

Hi @Pradyumna Das ,

 

During Azure discovery, iam expecting there to be Windows Server (cmdb_ci_win_server) and IIS Virtual Directory (cmdb_ci_iisdirectory) records created/updated. iam noticing that although the Windows Server records have Software Installations (cmdb_sam_sw_install records) associated with them were updated  in cmdb_sam_sw_install (software installations)under window server(cmdb_ci_win_server), but iam  not seeing Software Installations associated with IIS Virtual Directory records.please refer screenshot for details.

anitha0887_0-1713708097421.png


 
Updating Media

 

Version history
Last update:
‎04-16-2023 10:37 PM
Updated by:
Contributors