FOG API Question
-
I was looking at the FOG API and tried to copy examples like the one here: https://raw.githubusercontent.com/FOGProject/fog-community-scripts/master/PowershellModules/Snippets/Fog-Commands.psm1
I can’t seem to even get a list of users out. I guess I have no idea what I am doing.
My end goal is to take the fields of the machine that is being imaged of the “other tag #1” and “other tag #2” and output them.
I hope this is easy to do.
-
@Chris-Whiteley Enabled the FOG API both in FOG Configuration as well as user’s settings? Using both API tokens?
-
I did not have it set in the FOG Configuration. That was a good start
-
@Sebastian-Roth So that helped after I checked the box. Now I need to add another question in the Full Host Registration. I have set it up to ask it and assigned it a variable. How do I get that to show up within FOG?
I used “price” assigned as “$price”
price="" echo -n " * What is the purchase price of this device (1393.01): " read price price=$(echo $price | base64)
I also added this in the last long line
&price=$price
-
@Chris-Whiteley Do you want to save the price variable into “other tag #1” in the DB? I am not sure I get what you are trying to achieve.
-
@Sebastian-Roth I am trying to create a new variable. I don’t care if it shows up in FOG at all as long as it gets stored somewhere for me to be able to recall it via the FOG API.
-
This post is deleted! -
@Chris-Whiteley Sorry for the long delay! Now that I found some time to think through this I can give you two answers.
- Using the “other #1” tag should be simple! When registering a host you enter the price information when asked for the “other #1” and it will be saved to the database. After enabling the FOG API (user settings as well as general FOG settings) you should be able to query that information from any host using the following commands (make sure you have
curl
andjq
installed) to get a long list of all host IDs together with the corresponding “other #1” tag values.
curl --silent -H "fog-api-token: xxx" -H "fog-user-token: yyy" -X GET http://x.x.x.x/fog/inventory | jq '.inventorys | .[] | [.id,.other1]'
- Now you request on adding another “price” value to the full registration process is a lot more work. You start by adding the question to the
fog.man.reg
file as posted below. Then edit /var/www/html/fog/lib/reg-task/registration.class.php and add your price element similar to what you see in line 160 for other1/other2 as well as line 288 where the information is pushed to the database. As well edit /var/www/html/fog/lib/fog/inventory.class.php and add your new price field to the class definition just after line 40. Now as a final step you need to add that new column to the database for it to work properly as well!
shell> mysql -u root -p Password: ... mysql> use fog; ... mysql> ALTER TABLE `inventory` ADD COLUMN `iPrice` VARCHAR(50) NOT NULL AFTER `iOtherTag1`; ... mysql> quit
IMHO it’s way easier to chose the first route if you don’t use the other #1 or #2 tags yet! Why add the price field and risk causing issues on a later FOG updates when you can use what is officially part of FOG already.
- Using the “other #1” tag should be simple! When registering a host you enter the price information when asked for the “other #1” and it will be saved to the database. After enabling the FOG API (user settings as well as general FOG settings) you should be able to query that information from any host using the following commands (make sure you have
-
@sebastian-roth Thank you! I am going to give this a shot.