Armis integration not happening

Ashupakasma
Tera Expert

Hello Experts,

 

I am doing Armis integration with ServiceNow but after providing the Armis URL and secret key, In the next step when I try to load the test 20 record option, it throws an error:

 

ConversionError: The undefined value has no properties. (sys_script_include.eadb60b61b615810993e0feddc4bcbeb.script; line 62)

 

I do not understand how to tackle this, where I can check this error, and how I can remediate this. Help pls..

5 REPLIES 5

Prabu Velayutha
Mega Sage
Mega Sage

Hi @Ashupakasma

 

As mentioned in the error open the script include table by typing  sys_script_include.list in the navigation search box and filter the Script Include with Sys_ID eadb60b61b615810993e0feddc4bcbeb and check the Line 62 or you can share the Script so that we can troubleshoot.

 

Thanks,

Prabu Velayutham

Hello @Prabu Velayutha ,

 

Thank you so much for your response. As I have added the sys id and also find that script include.

 

Posting it here:

 

var ArmisImportController = Class.create();
ArmisImportController.prototype = {
    initialize: function() {
        this.apiHelper = new ArmisAPIHelper();
        this.aql = gs.getProperty('x_armis_cmdb.aql');
        this.import_type = gs.getProperty('x_armis_cmdb.import_type');
        this.pageLength = gs.getProperty('x_armis_cmdb.api_page_length');
        this.return_fields = gs.getProperty('x_armis_cmdb.import_fields');
        this.import_timeout = gs.getProperty('x_armis_cmdb.armis_import_timeout');
    },
 
    importArmis: function(import_set_table) {
        try {
            this.initializeColumns(import_set_table);
            var inputs = {};
            inputs['page_limit'] = this.pageLength; // String 
            inputs['import_type'] = this.import_type; // String 
            inputs['return_fields'] = this.return_fields; // String 
 
            // Execute Data Stream Action. 
            var result = sn_fd.FlowAPI.getRunner().datastream('x_armis_cmdb.import_armis_devices').withInputs(inputs).timeout(this.import_timeout).run();
            var stream = result.getDataStream();
            var tempObj = {};
            var helper = new ArmisTypeDictionary();
            var override = new ArmisTypeDictOverride().customerTypes;
            var importSites = gs.getProperty('x_armis_cmdb.import_armis_sites') == 'true';
            var dict = helper.types;
            var mergedObj = helper.mergeObjects(dict, override);
            var exCount = 0;
            // Process each item in the data stream
            while (stream.hasNext()) {
                exCount++;
                var item = stream.next();
                item.rowType = 'device';
                tempObj[item.type] = true;
                var ignored = helper.isTypeIgnored(item.type, mergedObj);
                if (!ignored) {
                    if (item.site_name) {
                        item = this._insertSite(item.site_name, item, importSites);
                    }
                    if (!item.site_map_type) {
                        item.site_map_type = 'IT';
                    }
                    import_set_table.insert(item);
                    if (item.plcModuleJSON) {
                        this._insertPLCModules(item, import_set_table);
                    }
                    if (item.networkInterfaceJSON) {
                        this._insertNetworkInterface(item, import_set_table);
                    }
 
                }
            }
        } catch (ex) {
            var message = ex.getMessage();
            //throw message;
            if (message.indexOf('Could not successfuly retreive armis token') > -1) {
                throw message;
            }
            gs.error(message);
        } finally {
            stream.close();
        }
        var tempArray = [];
        for (var key in tempObj) {
            tempArray.push(key);
        }
        gs.setProperty('x_armis_cmdb.import_type', '');
        gs.info('Armis completed loading of all devices. Beginning Robust Transform Engine Now...');
        gs.info('Armis: Discovered device types: ' + tempArray);
    },
 
    importArmisSites: function(import_set_table) {
        gs.info('Armis Site Import Started...');
        var inputs = {
            page_limit: this.pageLength
        };
        var stream = sn_fd.FlowAPI.executeDataStreamAction('x_armis_cmdb.get_armis_sites', inputs, this.import_timeout);
 
        var tempArray = [];
        while (stream.hasNext()) {
            var item = stream.next();
            if (tempArray.indexOf(item.site_name) == -1) {
                tempArray.push(item.site_name);
                this._insertSite(item.site_name, item, true);
            }
        }
 
        gs.info('Armis completed loading of all sites.');
    },
 
    importArmisUsers: function(import_set_table, maxRow) {
import_set_table.addColumn("deviceIds", 40);
import_set_table.addColumn("lastUsedDevice", 40);
import_set_table.addColumn("lastSeen", 41);
import_set_table.addColumn("phone", 40);
import_set_table.addColumn("displayName", 40);
import_set_table.addColumn("firstSeen", 41);
import_set_table.addColumn("name", 40);
import_set_table.addColumn("id", 40);
import_set_table.addColumn("dataSources", 2000);
import_set_table.addColumn("email", 40);
import_set_table.addColumn("properties", 40);
import_set_table.addColumn("username", 40);
        try {
            var inputs = {};
            inputs['page_limit'] = this.pageLength; // String 
            inputs['aql'] = gs.getProperty('x_armis_cmdb.user_import_aql') || 'in:users';// String 
            var result = sn_fd.FlowAPI.getRunner().datastream('x_armis_cmdb.get_armis_users').withInputs(inputs).run();
            var stream = result.getDataStream();
var exCount = 0;
            while (stream.hasNext()) {
exCount++;
                var user = stream.next();
import_set_table.insert(user);
if(maxRow > -1 && exCount >= maxRow){
break;
}
            }
        } catch (ex) {
            var message = ex.getMessage();
            gs.error(message);
        } finally {
            stream.close();
        }
    },
 
    _siteMetaDataList: {
        "location": '',
        "approval_group": '',
        "company": '',
        "managed_by": '',
        "managed_by_group": '',
        "support_group": '',
        "owned_by": '',
        "change_group": '',
        "assigned_to": '',
        "supported_by": '',
        "equipment_model_entity": ''
    },
 
    _insertSite: function(site_name, item, importSites) {
        var siteType = '';
        //var equipmentModelEntityID = '';
        var metaDataToInherit = this._siteMetaDataList;
        var siteMapGR = new GlideRecord('x_armis_cmdb_armis_site_map');
        if (siteMapGR.get('armis_site', site_name)) {
            siteType = siteMapGR.site_type + '';
            //equipmentModelEntityID = siteMapGR.equipment_model_entity + '';
            item = this._inheritSiteMetaData(siteMapGR, metaDataToInherit, item);
        } else {
            if (importSites) {
                siteMapGR.initialize();
                siteMapGR.armis_site = site_name;
                siteMapGR.site_type = 'IT';
                siteMapGR.insert();
            }
 
        }
        item.site_map_type = siteType;
 
        return item;
    },
 
    _getSiteMapType: function(site_name) {
        var siteMapGR = new GlideRecord('x_armis_cmdb_armis_site_map');
        if (siteMapGR.get('armis_site', site_name)) {
            return siteMapGR.site_type;
        }
    },
 
    _inheritSiteMetaData: function(siteMapGR, metaDataToInherit, item) {
        var importMetaData = JSON.parse(gs.getProperty('x_armis_cmdb.armis_site_map_fields'));
        for (var field in importMetaData) {
            if (importMetaData[field] == true) {
                var siteValue = siteMapGR[field] + '';
                metaDataToInherit[field] = siteValue;
            }
        }
 
        item.site_location = metaDataToInherit.location;
        item.site_approval_group = metaDataToInherit.approval_group;
        item.site_company = metaDataToInherit.company;
        item.site_managed_by = metaDataToInherit.managed_by;
        item.site_managed_by_group = metaDataToInherit.managed_by_group;
        item.site_support_group = metaDataToInherit.support_group;
        item.site_owned_by = metaDataToInherit.owned_by;
        item.site_change_group = metaDataToInherit.change_group;
        item.site_assigned_to = metaDataToInherit.assigned_to;
        item.site_supported_by = metaDataToInherit.supported_by;
        item.site_equipment_model = metaDataToInherit.equipment_model_entity;
        item.site_map_type = '';
 
        return item;
        //return JSON.stringify(metaDataToInherit);
    },
 
    checkIfImportRunning: function() {
        var running = false;
        var JobSysId = '01b8d2a01b865810993e0feddc4bcb8e';
        var sysTriggerGa = new GlideAggregate('sys_trigger');
        sysTriggerGa.addQuery('state', '!=', '0');
        sysTriggerGa.addQuery('document_key', JobSysId);
        sysTriggerGa.addAggregate('COUNT');
        sysTriggerGa.query();
        if (sysTriggerGa.next()) {
            var count = sysTriggerGa.getAggregate('COUNT');
            gs.debug("SG-Armis: Total Jobs Currently Running: " + count);
            if (count > 1) {
                running = true;
            }
        }
        return running;
    },
 
    checkIntegrationStatus: function() {
        //check if import is already running
        var importActive = (gs.getProperty('x_armis_cmdb.import_active') == 'true');
        if (importActive) {
            gs.info('Armis Import already running according to the property "x_armis_cmdb.import_active"; aborting redundant import to protect system performance. You can manually set the property to false if you believe it is incorrect.');
            return false;
        } else {
            gs.setProperty('x_armis_cmdb.import_active', true);
            return true;
        }
    },
 
    canDailyImportRun: function() {
        var scheduledJobGr = new GlideRecord('sys_trigger');
        scheduledJobGr.addEncodedQuery("document_keySTARTSWITH01b8d2a01b865810993e0feddc4bcb8e");
        scheduledJobGr.orderByDesc('next_action');
        scheduledJobGr.query();
        if (!scheduledJobGr.hasNext()) {
            return true;
        }
        while (scheduledJobGr.next()) {
            var state = scheduledJobGr.getValue('state');
            if (state != '0') {
                //Job is already running
                return false;
            }
            var nextAction = scheduledJobGr.getValue('next_action');
            nextAction = new GlideDateTime(nextAction);
            var nextRunDay = nextAction.getDayOfMonthUTC().toString();
            var currentDay = new GlideDateTime().getDayOfMonthUTC().toString();
 
            if (nextRunDay === currentDay) {
                return false;
            } else {
                return true;
            }
        }
    },
 
    _insertPLCModules: function(item, import_set_table) {
        var moduleJSON = JSON.parse(item.plcModuleJSON);
        for (var i = 0; i < moduleJSON.length; i++) {
            var flattenedModule = this._flattenObj(moduleJSON[i]);
            var tempItem = {};
            tempItem.id = item.id;
            tempItem.name = item.name; // + ' Module ' + flattenedModule.index;
            tempItem.purdueLevel = '0';
            tempItem.type = 'plcs';
            tempItem.rowType = 'plcModule';
            tempItem.flatPLCModule = JSON.stringify(flattenedModule);
            tempItem.site_name = item.site_name;
            tempItem.site_map_type = item.site_map_type;
            tempItem.site_location = item.site_location;
            tempItem.site_approval_group = item.site_approval_group;
            tempItem.site_company = item.site_company;
            tempItem.site_managed_by = item.site_managed_by;
            tempItem.site_managed_by_group = item.site_managed_by_group;
            tempItem.site_support_group = item.site_support_group;
            tempItem.site_owned_by = item.site_owned_by;
            tempItem.site_change_group = item.site_change_group;
            tempItem.site_assigned_to = item.site_assigned_to;
            tempItem.site_supported_by = item.site_supported_by;
            tempItem.site_equipment_model = item.site_equipment_model;
            import_set_table.insert(tempItem);
        }
    },
 
    _insertNetworkInterface: function(item, import_set_table) {
        var nwInterfaceJSON = JSON.parse(item.networkInterfaceJSON);
        for (var i = 0; i < nwInterfaceJSON.length; i++) {
            var flattenedNWAdapter = this._flattenObj(nwInterfaceJSON[i]);
            var tempItem = {};
            tempItem.id = item.id;
            tempItem.rowType = 'networkAdapter';
            tempItem.flatNetworkAdapter = JSON.stringify(flattenedNWAdapter);
            import_set_table.insert(tempItem);
        }
    },
 
    _flattenObj: function(obj) {
        var newObj = {};
        for (var element in obj) {
            if (obj[element][0]) {
                newObj[element] = obj[element][0].value;
            } else {
                newObj[element] = '';
            }
        }
        return newObj;
    },
 
    //     importDevices: function(tokenObj, count, import_set_table) {
    //         try {
    //             var logCount = 0;
    //             var logFrequency = count / 20;
    //             for (var i = 0; i < count; i = i + this.pageLength) {
    //                 if (tokenObj.expirationTime < new GlideDateTime()) {
    //                     //if the token is going to expire in the next 10 seconds refresh the token automaticly;
    //                     tokenObj = this.apiHelper.getTokenObj();
    //                 }
    //                 var startFrom = i;
    //                 var token = tokenObj.token;
    //                 var devices = this.apiHelper.getDevicesSearch(token, this.aql, this.pageLength, startFrom, false);
    //                 if (devices && devices.results) {
    //                     logCount = logCount + devices.count;
 
    //                     this.addResultsToStaging(devices.results, import_set_table);
    //                 }
 
    //                 if (logCount >= logFrequency) {
    //                     gs.info('Armis Loaded ' + (i + logCount) + '/' + count + ' devices');
    //                     logCount = 0;
    //                 } else if (count <= (i + this.pageLength)) {
    //                     gs.info('Armis Loaded ' + (i + logCount) + '/' + count + ' devices');
    //                 }
    //             }
    //             gs.info('Armis completed loading all devices. Starting import.');
    //         } catch (ex) {
    //             var message = ex.message;
    //             gs.info(message);
    //         }
    //     },
 
    //     ArmisDevice: function(rawDevice) {
    //         this.accessSwitch = rawDevice.accessSwitch;
    //         this.category = rawDevice.category;
    //         this.firstSeen = rawDevice.firstSeen;
    //         this.id = rawDevice.id + '';
    //         this.ipAddress = rawDevice.ipAddress;
    //         this.lastSeen = rawDevice.lastSeen;
    //         this.macAddress = rawDevice.macAddress;
    //         this.manufacturer = rawDevice.manufacturer;
    //         this.model = rawDevice.model;
    //         this.name = rawDevice.name;
    //         this.operatingSystem = rawDevice.operatingSystem;
    //         this.operatingSystemVersion = rawDevice.operatingSystemVersion;
    //         this.riskLevel = rawDevice.riskLevel;
 
    //         if (rawDevice.sensor) {
    //             this.sensor_name = rawDevice.sensor.name;
    //             this.sensor_type = rawDevice.sensor.type;
    //         } else {
    //             this.sensor_name = '';
    //             this.sensor_type = '';
    //         }
 
    //         if (rawDevice.site) {
    //             this.site_location = rawDevice.site.location;
    //             this.site_name = rawDevice.site.name;
    //         } else {
    //             this.site_location = '';
    //             this.site_name = '';
    //         }
    //         if (rawDevice.tags) {
    //             this.tags = JSON.stringify(rawDevice.tags);
    //         } else {
    //             this.tags = '[]';
    //         }
 
    //         this.type = rawDevice.type;
    //         this.user = rawDevice.user;
    //         this.visibility = rawDevice.visibility;
    //     },
 
 
    initializeColumns: function(import_set_table) {
        import_set_table.addColumn("accessSwitch", 40);
        import_set_table.addColumn("category", 40);
        import_set_table.addColumn("firstSeen", 40);
        import_set_table.addColumn("id", 40);
        import_set_table.addColumn("ipAddress", 40);
        import_set_table.addColumn("lastSeen", 40);
        import_set_table.addColumn("macAddress", 40);
        import_set_table.addColumn("manufacturer", 40);
        import_set_table.addColumn("model", 40);
        import_set_table.addColumn("name", 40);
        import_set_table.addColumn("operatingSystem", 40);
        import_set_table.addColumn("operatingSystemVersion", 40);
        import_set_table.addColumn("riskLevel", 40);
        import_set_table.addColumn("sensor_name", 40);
        import_set_table.addColumn("sensor_type", 40);
        import_set_table.addColumn("site_location", 40);
        import_set_table.addColumn("site_name", 40);
        import_set_table.addColumn("tags", 240);
        import_set_table.addColumn("type", 40);
        import_set_table.addColumn("user", 40);
        import_set_table.addColumn("serialNumber", 40);
        import_set_table.addColumn("purdueLevel", 40);
        import_set_table.addColumn("rowType", 40);
        import_set_table.addColumn("firmwareVersion", 40);
        import_set_table.addColumn("flatNetworkAdapter", 300);
        import_set_table.addColumn("networkInterfaceJSON", 700);
        import_set_table.addColumn("flatPLCModule", 250);
        import_set_table.addColumn("plcModuleJSON", 2040);
        import_set_table.addColumn("boundaries", 40);
        import_set_table.addColumn("vlans", 500);
        import_set_table.addColumn("userIds", 500);
    },
 
    type: 'ArmisImportController'
};

Ashupakasma
Tera Expert

I haven't found the solution to it. working on an alternate solution for this. will posted here.

Ashupakasma
Tera Expert

Hello, I have found the RCA for that. actually, I do not have the admin rights to fetch the details from Armis. I am only having limited rights. but after providing the admin rights, it's working fine.