Windows Batch Create/update host
-
I would like to create a batch file to create or update hosts in fog’s database.
I would simply still ask the same questions:
Computer NAME == %computername%
IMAGE FILE#:
Add to AD [y/n]: YGrab the LAN MAC using:
[QUOTE]
@echo off
set mac=&set ealac=
for /f “tokens=1,2 delims=:” %%i in ( ’ ipconfig /all^|findstr /c:“Ethernet adapter” /c:“Physical Address” ’ ) do (
if defined ealac if not defined mac set mac=%%j
if not defined ealac if “%%i”==“Ethernet adapter Local Area Connection” set ealac=Y
)
echo %mac%
set ealac=
[/QUOTE]Image now [y/n]?
-
seems like this was already working at one time or another with the Fog Client Host Registration but was disable.
[url]http://fogproject.org/forum/threads/fog-client-and-host-registration.793/[/url]
Was this fixed in the newest client?
-
It wasn’t fixed or set within the client, though I believe when the “host” registers to the system, it passes all of it’s MAC’s to the FOG Server. The FOG Server then parses this information and finds the relevant host based on “all” of the MAC’s sent to FOG. If it finds one, and another MAC is not found, it should place it in the Pending MAC’s field. FOG 0.33b will find a host no matter what MAC is sent to it so long as that MAC is assigned to a host (not in pending state). So really this should be working to at least still do snapin/task checkins even if wireless.
-
So is there any way that I can collect the data required for a Host Registration (e.g. Full Inventory Registration) and send it to the fog database using a bat file?
-
I don’t know. The utility FOG uses during an inventory job is dmidecode, I don’t know of the equivalent command under Windows. That said, if the host is already registered, why not just schedule an Inventory Task form the Tasks menu option?
-
What you’re trying to do might be possible if you can get the hostname, mac, imageID, OS ID, and answer to “image now?” question. You just need to collect this information and then send it to the proper web scripts, imitating what the FOG scripts do from within the init.gz.
Registering a host is basically passing info to a web page, processing the result, and moving to the next step to setup the image task. If you look at how the scripts in the init.gz do it, then you can “fake it” as long as you can collect and submit the data to the same URL from your batch file.
-
Chad,
init.gz is no more. Tom has changed init.gz to init.xz. I just need the info to connect to the fog server, open the correct scripts, input the data, update the database and close the connection.
So what scripts for init.xz initialize when selecting “Full Host Registration”?
-
I see that you must have php installed on the windows machine before you can pass variables from a batch to a php page. Looks like to me that I’m going at this wrong. I think I just use a batch file to launch a webpage for auto registration.
Seems like there is something that can be done to change the auto.register.php file.
So if I would visit this webpage it would register the client?
hmmmmm…looks like it needs some modding for my purposes. What else uses this file???
-
If you look at the main bing/fog script in the init file, look for the code that handles the mode=manreg, I believe it calls fog.man.reg script. In that script, you can follow it along as it prompts for options and then submits those to the web server for registration, then calls doInventory, then submits the inventory info to the server. Somewhere in there, the option to image now is given and the result is either passed along, or used to call a web script that sets up the imaging task.
-
You’ll need something on the windows side that can imitate wget for querying the fog server for image and os info, and can submit the results in POST format back to the fog server. The inventory part, I’m not sure, it might just be easier to avoid that during registration and call a hardware inventory task later.
-
Since I reformatted my fog server and did a complete new install from Fog 0.32 --> 0.33 --> 1.0.0 --> 1.0.1–>1.1.0, I have lost my client list. I originally hoped the client would re-register themselves but that function was lost in 0.29 and it makes sense why. The HOST has no idea what image to point to. Considering there may be 2 possible images for the same Make\Model of machine.
So I wanted to make this easier on myself.
Here is what I came up with… I have a shortcut to a network shared batch file so I can make some changes on the fly with our users that can’t do things for themselves. This batch file is in windows All Users\Startup folder. (Dirty I know but works). SO if I want my staff to look at a webpage as soon as they log in I can force that.
[B]Windows Batch file:[/B]
[CODE]start <fogserverip>/fog/management/index.php?node=host&sub=add[/CODE][B]Install arpscan to fog server[/B]
[CODE]sudo apt-get install arp
[/CODE][B]Edit /var/www/fog/lib/pages/[/B][B]HostManagementPage.class.php[/B] to include just below print “\n\t\t\t<h2>”._(‘Add new host definition’).‘</h2>’;
[CODE] //----------------------------------------------------------------------------------------
//Register this host Button (wolfbane8653)
//Must install arp first (sudo apt-get install arp) before enabling this button
?>
<script>
function fillinfo()
{
//get this hosts info
<?php
$ipaddr = $_SERVER[‘REMOTE_ADDR’];
$chk = exec('/usr/sbin/arp -a '.$ipaddr,$output);
$data = explode(" “,$output[0]);
$name = explode(”.",$data[0]);
$hostname = $name[0];
$macaddr = $data[3];
?>
//export php info into javascript
var hostname = “<?php echo $hostname ?>”;
var macaddr = “<?php echo $macaddr ?>”;
//output to textboxes
document.getElementsByName(“host”)[0].value=hostname;
document.getElementsByName(“mac”)[0].value=macaddr;
}
</script>
<button onclick=“fillinfo()”>Register THIS HOST</button>
<?php
//end button
//----------------------------------------------------------------------------------------[/CODE]With this edit I now can click on this new button and it inputs my current computer name and mac address in the correct fields. Is there anyway this can be incorporated as a hook/plugin/option?
[COLOR=#ff0000]Warning this only works on LAN.[/COLOR]