Register Host using Chassis Serial number



  • Hi All,

    I’ve been trying to adjust fog so when we use a custom fog registration it doesn’t prompt for the Hostname but instead uses the chassis serial number which for Dell’s and HP’s normally relates to the service tag.

    To create the custom.fog.reg I’ve duplicated fog.man.reg and changed line 158 from: ‘read host’

    while [[ $res != "#!ok" ]]; do
        echo -n " * Enter hostname for this computer: "
        read host
        if [[ ${#host} -gt 15 ]]; then
            host=${host:0:15}
            echo " | Truncated to 15 characters: $host"
            usleep 2000000
        fi
        host=$(echo $host | base64)
        res=$(wget --post-data="host=$host" -qO - http://${web}service/hostnameloop.php 2>/dev/null)
        [[ $res != "#!ok" ]] && echo "$res"
    

    To

    # while [[ $res != "#!ok" ]]; do
    #    echo -n " * Enter hostname for this computer: "
    #    read host
    #    if [[ ${#host} -gt 15 ]]; then
    #        host=${host:0:15}
    #        echo " | Truncated to 15 characters: $host"
    #        usleep 2000000
    #    fi
    #    host=$(echo $host | base64)
    #    res=$(wget --post-data="host=$host" -qO - http://${web}service/hostnameloop.php 2>/dev/null)
    #    [[ $res != "#!ok" ]] && echo "$res"
    #done
    host=$(dmidecode -s chassis-serial-number)
    echo “Host: ${host}”
    

    Using the code from funcs.sh to grab the chassis-serial number unfortunately this is not working and the pxe seems to load the BZimage and then just skips to “complete” then reboots.

    Can someone please help?

    Please go easy on my I’m learning as I go here and this is all new territory to me!



  • Hi,

    Mwebb_Sureline’s boss here.

    I’ve cobbled this together to do what was needed.
    It is rather quick and dirty I’m afraid, could probably call “doInventory” and use the results from there to populate the service tag / serial number rather than directly running the dmidecode in the script.

    I’ve seen a few people on the forums trying to get something similar working, so here is the code.
    Thanks go to @george1421, I modified his script in the post he linked to make this.

    (Using SVN rev 5698) I’ve copied fog.man.reg and setup a new custom job for this, the code replaces the hostname input section from fog.man.reg directly, e.g. remove lines 156 to 167 and paste this in.

    Whilst this works for us, you use this at your own risk.

    while [[ $res != "#!ok" ]]; do
        echo " * Retrieving serial number or service tag for this computer to use as hostname "
        getserialno=`dmidecode -s chassis-serial-number`;
        getserialno="${getserialno%"${getserialno##*[![:space:]]}"}";  # Remove trailing whitespace
        # get the serial no from the baseboard if bios doesn't give it up
        if [ "$getserialno" = "" ];
         then
          getserialno=`dmidecode -s baseboard-serial-number`;
          getserialno="${getserialno%"${getserialno##*[![:space:]]}"}"; # Remove trailing whitespace
        fi
        if [[ "$getserialno" = "" || "$getserialno" == "None" ]];
         then
          echo " * Unable to retrieve tag or serial number, please enter hostname manually. Just hit return to leave blank (will use MAC address)"
          read getserialno
          getserialno="${getserialno%"${getserialno##*[![:space:]]}"}"; # Remove trailing whitespace
        fi
        host="$getserialno";
        if [[ ${#host} -gt 15 ]]; then
            host=${host:0:15}
            echo " | Truncated to 15 characters: $host"
            usleep 2000000
        fi
        echo " * Hostname set to: $getserialno"
        host=$(echo $host | base64)
        res=$(wget --post-data="host=$host" -qO - http://${web}service/hostnameloop.php 2>/dev/null)
        [[ $res != "#!ok" ]] && echo "$res"
    done
    

  • Moderator

    @Mwebb_Sureline That auto naming was a hack in 0.29 and a pseudo feature in 0.30. I do have a feature request out there for this function: https://forums.fogproject.org/topic/6304/fog-2-0-request-advanced-host-naming

    How I handle this today is to do the full registration like Tom suggested. I enter the site prefix and then use a bar code scanner to read the dell asset tag from the back/bottom of the device. Doing it manually works for us now, but I would like to get time to look in the code to see if I could reintegrate this feature into the current build.

    As a side note, I also have a hack that will calculate the name in a post install script that updates the unattend.xml file. The issue is getting FOG to see this new calculated name. It not the best solution but it does work too.


  • Senior Developer

    @Mwebb_Sureline

    The quickregister already has capability to define which image id you want associated with a host (no it’s not customized yet but that’s kind of where capone can come in, though I suppose if you’re actually registering hosts itd be good to have a plugin that works similarly to capone, but allowing registered hosts to operate in much the same way – no that’s a lot of work right now.)



  • Thanks for the quick response :)

    I’d be happy to use quick register, but I can’t see where to change the host from registering with the MAC address and instead register with the Chassis serial number…

    I’d also like it to prompt for which Image ID, but that’s not a must.

    I did have this working on 0.32 using this:

    host=echo $caseserial | base64;


  • Senior Developer

    I’m just guessing but you want this on the “full register” and NOT the quick register?

    I haven’t added any magic parsing to the quick install, but FOG has NEVER defined a hostname based on another attribute for the full register. This is because full register is basically waiting for your input – that’s its purpose in life.


Log in to reply
 

Looks like your connection to FOG Project was lost, please wait while we try to reconnect.