/build/static/layout/Breadcrumb_cap_w.png

Custom rule to format Hardware Address

A question was posted in the KACE Slack Community regarding the possibility of having a custom field for a computer's hardware address (aka MAC) be formatted in IEEE 802 format using colons. Always being up for a challenge, I created the following custom service desk rule to do that. To create this rule on your SMA, go to Service Desk, Rules and select the relevant queue. Under Action, select New (SQL)

A couple of notes:
My custom field is CUSTOM 19, in the database that means it is called CUSTOM_FIELD_VALUE18. You will have to adjust the statements below to match your custom field, notice that the database column is one less than the UI column.
My queue ID is 1, you will have to adjust that for your queue.

Here is the Select statement for the rule:

SELECT ID FROM HD_TICKET WHERE 
CUSTOM_FIELD_VALUE18 not regexp BINARY '([0-9A-F]{2}[:]){5}([0-9A-F]{2})'
AND HD_QUEUE_ID = 1

Credit to https://stackoverflow.com/questions/4260467/what-is-a-regular-expression-for-a-mac-address for the regular expression.

Here is the update statement:

UPDATE HD_TICKET SET CUSTOM_FIELD_VALUE18 = 
CASE
WHEN CHAR_LENGTH(CUSTOM_FIELD_VALUE18) = 12 THEN
UPPER(concat_ws(':', substr(CUSTOM_FIELD_VALUE18, 1,2), 
substr(CUSTOM_FIELD_VALUE18,3,2), 
substr(CUSTOM_FIELD_VALUE18,5,2),
substr(CUSTOM_FIELD_VALUE18,7,2),
substr(CUSTOM_FIELD_VALUE18,9,2),
substr(CUSTOM_FIELD_VALUE18,11,2)))
WHEN CHAR_LENGTH(CUSTOM_FIELD_VALUE18) = 17 THEN
UPPER(concat_ws(':', substr(CUSTOM_FIELD_VALUE18, 1,2), 
substr(CUSTOM_FIELD_VALUE18,4,2), 
substr(CUSTOM_FIELD_VALUE18,7,2),
substr(CUSTOM_FIELD_VALUE18,10,2),
substr(CUSTOM_FIELD_VALUE18,13,2),
substr(CUSTOM_FIELD_VALUE18,16,2)))
ELSE 'Please enter a valid hardware address'
END
WHERE ID = <TICKET_IDS>
The rule handles three scenarios:
The user entered twelve characters - I'm assuming that the user entered twelve characters that are valid for a hardware address.
The user entered seventeen characters - I'm assuming that the user entered seventeen characters that are valid for a hardware address, but they are lower case or are using the wrong separator.
The user did not enter a value or it is neither twelve or seventeen characters - The field is set to 'Please enter a valid hardware address'

Those rules aren't by any means going to cover all possible scenarios in the best way, but they will get the basic job done.

Set the rule to run on ticket save and watch the magic happen.



Comments

This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ