CMDB- Need help in splitting name to get MAC address

PrashanthS
Tera Expert

Hi, for a certain class of devices in our Org the data has been updated manually such that the Name field contains MAC address for the device. A sample name value is abc000832c61d1c.domain.net where the 12 digit MAC address is between abc and .domain.net. I need help with a fix script to get the MAC address field populated from this value in the required format like 00:08:32:c6:1d:1c. 

Please suggest if you have come across this scenario. Thanks in advance.

1 ACCEPTED SOLUTION

Hi Brahmjeet,

 

So I figured out the mistake, had to make use of slice:

 

var extractedString = inputString.slice(3).replace('.domain.net', '');

 

and then added the usuals

 

var newMac = extractedString.replace(/(.{2})/g,"$1:").slice(0,-1);
//gs.print(newMac);
}
macad.mac_address = newMac;
gs.info(newMac);
macad.update();
}

View solution in original post

7 REPLIES 7

Hi Brahmjeet,

 

So I figured out the mistake, had to make use of slice:

 

var extractedString = inputString.slice(3).replace('.domain.net', '');

 

and then added the usuals

 

var newMac = extractedString.replace(/(.{2})/g,"$1:").slice(0,-1);
//gs.print(newMac);
}
macad.mac_address = newMac;
gs.info(newMac);
macad.update();
}

Hey Prashanth,

great! I hope it's resolved now?

 

Hi Brahmjeet, yup it is resolved now. Thanks.