Assigning Snapins to Hosts via FOG API – Proper JSON Structure and Method?
-
Server OS: Debian 10 Buster
FOG OS: 1.5.10Hey all,
I’ve been integrating the FOG API in with our existing mangement software and I have been successful with using the API to assign Images to hosts and then queue up deployment tasks, but I’m currently hitting a snag trying to assign a snapin to a host using the FOG API. I haven’t able to determine the right JSON structure and request type for this action and it doesn’t appear to be on the API Documentation so I’m really just kinda guessing at this point. I will describe below what I have tried so far:
Request:
PUT http://10.15.0.2/fog/host/7700/
JSON Body:
{ "taskTypeID": 11, "snapinID": 1 }
Response:
{ "id": "7700", "name": "f43909d8047b", "description": "Created by FOG Reg on May 26, 2022, 12:02 pm", "ip": "", "imageID": "529", "building": "0", "createdTime": "2022-05-26 12:02:49", "deployed": "2024-11-19 09:25:39", "createdBy": "fog", "useAD": "", "ADDomain": "", "ADOU": "", "ADUser": "", "ADPass": "", "ADPassLegacy": "", "productKey": "", "printerLevel": "", "kernelArgs": "", "kernel": "", "kernelDevice": "", "init": "", "pending": "", "pub_key": "", "sec_tok": "", "sec_time": "2024-09-26 11:11:04", "pingstatus": "<i class=\"icon-ping-down fa fa-exclamation-circle red\" data-toggle=\"tooltip\" data-placement=\"right\" title=\"Unknown\"></i>", "biosexit": "", "efiexit": "", "enforce": "", "primac": "f4:39:09:d8:04:7b", "imagename": "! HP Elitebook 840 G3", "hostscreen": { "id": null, "hostID": null, "width": null, "height": null, "refresh": null, "orientation": null, "other1": null, "other2": null }, "hostalo": { "id": null, "hostID": null, "time": null }, "inventory": { "id": "7700", "hostID": "7700", "primaryUser": "", "other1": "", "other2": "", "createdTime": "2022-05-26 12:03:01", "deleteDate": "0000-00-00 00:00:00", "sysman": "HP", "sysproduct": "HP EliteBook 840 G3", "sysversion": "", "sysserial": "5CG83651CN", "sysuuid": "caf1b9df-b277-11e8-97a3-6c1072018059", "systype": "Type: Notebook", "biosversion": "N75 Ver. 01.57", "biosvendor": "HP", "biosdate": "07/28/2022", "mbman": "HP", "mbproductname": "8079", "mbversion": "KBC Version 85.79", "mbserial": "PFKZU00WBBA9CO", "mbasset": "", "cpuman": "Intel(R) Corporation", "cpuversion": "Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz", "cpucurrent": "Current Speed: 2900 MHz", "cpumax": "Max Speed: 8300 MHz", "mem": "MemTotal: 7924528 kB", "hdmodel": "INTEL SSDSCKKF256G8H", "hdserial": "BTLA820625EQ256J", "hdfirmware": "LHFH03N", "caseman": "HP", "casever": "", "caseserial": "5CG83651CN", "caseasset": "", "memory": "7.56 GiB" }, "image": { "imageTypeID": "1", "imagePartitionTypeID": "1", "id": "529", "name": "! HP Elitebook 840 G3", "description": "", "path": "HPElitebook840G3", "createdTime": "2024-08-16 14:34:05", "createdBy": "fog", "building": "0", "size": "607121408.000000:12935051.000000:52981968896.000000:10500096.000000:5376049152.000000:176639.000000:723513344.000000:", "osID": "9", "deployed": "2024-11-18 16:16:26", "format": "5", "magnet": "", "protected": "0", "compress": "6", "isEnabled": "1", "toReplicate": "1", "srvsize": "27312695983", "os": {}, "imagepartitiontype": {}, "imagetype": {} }, "pingstatuscode": 6, "pingstatustext": "No such device or address", "macs": [ "f4:39:09:d8:04:7b", "38:ba:f8:c7:32:a1", "38:ba:f8:c7:32:a2", "3a:ba:f8:c7:32:a1", "38:ba:f8:c7:32:a5" ] }
It’s returning all the info about this host, including the Image ID, which I’ve been able to dynamically change with the API, but there doesn’t appear to be any apparent field in the response that indicates a snapin association. It seems like my current JSON body might be incorrect, or perhaps I’m using the wrong request type or endpoint.
So, my questions to the developers are:
-
What is the correct JSON body to use in order to assign specific snapins to a host before deploying?
-
Should I be using a PUT or a POST request for this action?
Assigning an image to a host is typically done using a PUT request, so I assumed snapin assignments would follow the same convention, but this may not be the case. -
Is there a specific endpoint that I should be using for assigning snapins to a host?
If possible, could you provide an example of the correct JSON body, endpoint, and HTTP method for assigning a snapin to a host?
This is something that can apprently be done via the API Documentation. I have tried assigning both
"10"
and"11"
as thetaskTypeID
and have had no luck.Thank you so much for your time and assistance!
-
-
@danieln Figured it out. Posting the answer here for posterity. This is the request that worked:
Request:
PUT http://10.15.0.2/fog/host/<FOG host ID>
JSON body:
{ "snapins": 1 }
it was
"snapins"
that I had to pass into the JSON body. I found this by just running a general GET request for snapinsGET http://10.15.0.2/fog/snapin
(another total guess that ended up being correct) and in the JSON body response it returned"snapins"
with an array of objects, so I just passed that into the PUT request body and it worked. The Snapins are literally numbered in the order in which you create them and you can reference them here to assign them.Hope this is helpful to any future person who tries to do this!
-
@danieln
Check out the FogApi powershell module, links in my signature.
I even have functions for setting snapins alreadyhttps://fogapi.readthedocs.io/en/latest/commands/Set-FogSnapins
https://github.com/darksidemilk/FogApi/blob/master/FogApi/Public/Set-FogSnapins.ps1and for starting snapins
https://github.com/darksidemilk/FogApi/blob/master/FogApi/Public/Start-FogSnapins.ps1
https://fogapi.readthedocs.io/en/latest/commands/Start-FogSnapins.ps1https://github.com/darksidemilk/FogApi/blob/master/FogApi/Public/Start-FogSnapin.ps1
https://fogapi.readthedocs.io/en/latest/commands/Start-FogSnapin.ps1 -
I saw this a while ago! Pretty impressive. Right now, we’re working to integrate the FOG API into Oracle NetSuite, but I do use Powershell quite a lot as well and could definitely see a benefit here. I will check it out.
Thanks,