Create Global IP exclusion for IP addresses Discovered in ESX server and VMware Instance tables,

priya711
Tera Contributor

Requirement:
1. 2 IP address collections are created [ip_address_collection] named "Income VMware VM Instances" and "Income ESX servers".

2. These 2 IP address collections should be included in the Global IP exclusion for discovery [ip_exclusion] 

3. These 2 IP address collections are created from the IP address field in the tables [cmdb_ci_vmware_instance] and [cmdb_ci_esx_server] respectively, this should be a automated scheduled job to update the IP address collection and not a manual creation of the ip address collections.

Development done:
I created the below schedule job it is creating ip address collection but no ip's were updated

// Scheduled Script to update IP address collections for VMware VM Instances and ESX servers

// Get the IP addresses from VMware Instances (cmdb_ci_vmware_instance table)
var vmwareGr = new GlideRecord('cmdb_ci_vmware_instance');
var vmwareIPs = [];
if (vmwareGr.isValid()) {
    vmwareGr.query();
    while (vmwareGr.next()) {
        if (vmwareGr.ip_address) {
            vmwareIPs.push(vmwareGr.ip_address);
            gs.info(vmwareIPs);
        }
    }
}

// Create/Update IP address collection for VMware VM Instances
var ipCollectionVMware = new GlideRecord('ip_address_collection');
ipCollectionVMware.initialize();
ipCollectionVMware.name = 'Income VMware VM Instances';
ipCollectionVMware.ip_addresses = vmwareIPs.join(',');
ipCollectionVMware.insert();

// Get the IP addresses from ESX Servers (cmdb_ci_esx_server table)
var esxGr = new GlideRecord('cmdb_ci_esx_server');
var esxIPs = [];
if (esxGr.isValid()) {
    esxGr.query();
    while (esxGr.next()) {
        if (esxGr.ip_address) {
            esxIPs.push(esxGr.ip_address);
        }
    }
}

// Create/Update IP address collection for ESX Servers
var ipCollectionESX = new GlideRecord('ip_address_collection');
ipCollectionESX.initialize();
ipCollectionESX.name = 'Income ESX servers';
ipCollectionESX.ip_addresses = esxIPs.join(',');
ipCollectionESX.insert();

// Ensure that IP address collections are included in the Global IP exclusion
var exclusionGr = new GlideRecord('ip_exclusion');
exclusionGr.initialize();
exclusionGr.ip_collections = 'Income VMware VM Instances,Income ESX servers';
exclusionGr.insert();
0 REPLIES 0