Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Created February 23, 2023 20:15
Show Gist options
  • Select an option

  • Save cmcdevitt/5aff62e0c859534e8622197af43a5397 to your computer and use it in GitHub Desktop.

Select an option

Save cmcdevitt/5aff62e0c859534e8622197af43a5397 to your computer and use it in GitHub Desktop.
Unclassed Hardware Helper
/*
Unclassed Hardware [cmdb_ci_unclassed_hardware]
Transform FQDN to Short Name in CI Name[name] Field
The IRE relies on the Hardware CI Name field for a match
SN Discovery uses the Short Host Name and VR Scanners sometime just use FQDNs
*/
/*
Script One: Host Import Maps [sn_sec_cmn_src_cmdb_map.list]
For records that have a Target Field of 'Name' and a Source Field like DNS,FQDN, etc
We want to transform the FQDN to a Short Name for the 'Name' field on Unclassed Hardware
This ensures and IRE / Identfication Match on Harware and it's children
Fix the problem before it occures
/*
//Expecting an FQDN
answer = value;//Default values, just in case
var short_name = value.split('.');
if(short_name.length > 0){
answer = short_name[0];
}
/*
Script Two: (Background / Fix Script) for Unclassed Hardware [cmdb_ci_unclassed_hardware]
IF you have created records with an FQDN in the Name field AND SN Discovery has ***NOT*** run yet
Fix the probelm after
*/
var short_name;
var uh = new GlideRecord('cmdb_ci_unclassed_hardware');
uh.addEncodedQuery('nameLIKE.');//Filter out Short Names
//uh.limit(1); //For testing
uh.query();
while(uh.next()){
short_name = uh.getValue('name').split('.');
uh.setValue('name',short_name[0]);
uh.update();
}
//gs.info(short_name[0]);// For testing
/*
So... if you have the FQDN in the Name field AND SN Discovery HAS already run...
You now have a duplicate record:
One in Unclassed hardware: Example Name Field 'foo.bar.com'
One in Linux (or Windows) Server: Exampe Field 'foo'
Adjust any CI Lookups as necessary and re apply them.
Delete old / duplicate record now in Unclassed Hardware
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment