CI Lookup rules Vulnerable response

Mahesh137
Tera Contributor

Can someone help me out here to build a script for the below requirements in CI Lookup rules.   

1) if Hostname is partial match for example ABCDE.email.com or ABCDE and if the CMDB has the similar record then prevent new discovered item creation and refer to old record in CMDB

2) if the operational Status is Not retired then Match

3)Statement to match Upper case vs lower case statements

4) if R7 Hostname=CMDB Hostname(name) then MATCH

 

 

1 REPLY 1

Tushar
Kilo Sage
Kilo Sage

Hi @Mahesh137 

 

I hope this helps -

 

function lookup_rules(hostname, operational_status) {
  // Check if the hostname is a partial match.
  if (hostname.toLowerCase().endsWith('.email.com') || hostname.toLowerCase() == 'abcde') {
    // Get the CMDB record for the hostname.
    var cmdbRecord = gs.getRecord('cmdb_ci', {
      'name': hostname.toLowerCase()
    });

    // If the CMDB record exists, prevent new discovered item creation and refer to the old record.
    if (cmdbRecord) {
      return {
        'match': true,
        'cmdb_id': cmdbRecord.sys_id
      };
    }
  }

  // Check if the operational status is not retired.
  if (operational_status != 'Retired') {
    return {
      'match': true
    };
  }

  // Return false if the hostname is not a partial match or the operational status is retired.
  return {
    'match': false
  };
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar