API wake on lan
-
Hi,
I’m searching a way ton use wol with the API but I can’t find. Is there a way or am I blind -
@Lenain This is a task, so I believe the task id for wol only is 4.
I forget the exact syntax, but this should do the job you need.
-
@Tom-Elliott
That’s right, it’s id 12 Thank you for you answer! I’m using a powershell script to wake up but for now I have error 501… I’m searching why -
@Tom-Elliott
I have finaly have it, it’s 14 with Fog 1.5.10. Task is send without error but no Wake Up… I’m using the powershell fog API, I have changed it to be able to send a task with ID 14… Can someone help me?function Send-FogImage { # .ExternalHelp FogApi-help.xml [CmdletBinding(DefaultParameterSetName='now')] [Alias('Push-FogImage','Deploy-FogImage')] param ( [Parameter(ParameterSetName='now')] [Parameter(ParameterSetName='schedule')] $hostId, $taskTypeID, [Parameter(ParameterSetName='schedule')] [datetime]$StartAtTime ) process { $fogHost = Get-FogHost -hostID $hostId; $currentImage = $fogHost.imageName; $fogImages = Get-FogImages; $fogImage = ($fogImages | Where-Object name -match $currentImage) if ($taskTypeID -eq ""){ $taskTypeID = 1 } if ($PSCmdlet.ParameterSetName -eq 'now') { "No Time was specified, queuing the task to start now" | out-host; if ($taskTypeID -ne 1) { "Creating Task for fog host of id $($hostID) named $($fogHost.name)" | Out-Host; $jsonData = "{`"taskTypeID`": `"$($taskTypeID)`", `"shutdown`":`"0`",`"other2`":`"0`",`"other4`":`"0`",`"isActive`":`"1`" }"; }else{ "Creating Deploy Task for fog host of id $($hostID) named $($fogHost.name) taskID $($taskTypeID)" | Out-Host; "Will deploy the assigned image $($fogImage.name) - $($fogImage.id) which will install the os $($fogImage.osname)" | Out-host; $jsonData = "{`"taskTypeID`": `"$($taskTypeID)`", `"shutdown`":`"0`",`"other2`":`"0`",`"other4`":`"1`",`"isActive`":`"1`" }"; } } else { "Start time of $($StartAtTime) specified, scheduling the task to start at that time" | out-host; $scheduleTime = Get-FogSecsSinceEpoch -scheduleDate $StartAtTime $runTime = get-date $StartAtTime -Format "yyyy-M-d HH:MM" $jsonData = @" { "name":"Deploy Task", "type":"S", "taskTypeID":"$($taskTypeID)", "runTime":"$runTime", "scheduleTime":"$scheduleTime", "isGroupTask":"0", "hostID":"$($hostId)", "shutdown":"0", "other2":"0", "other4":"1", "isActive":"1" } "@ } return New-FogObject -type objecttasktype -coreTaskObject host -jsonData $jsonData -IDofObject "$hostId"; } }
-
@Lenain Howdy, I’m the author of the FogApi powershell module and I’m happy to help.
A few questions
- Are you trying to send/push/deploy an image with wol enabled or are you trying to create a wake only task?
- Have you confirmed through other means that wake on lan is working in your environment, i.e. without additional switch configuration it typically doesn’t work across different subnets. It can, you just have to allow it.
- Here’s another alternative in powershell, you can send a magic packet to a mac address with this function
function Send-WoL { param ( $Mac, $port = 9 ) process { $MacByteArray = $Mac -split "[:-]" | ForEach-Object { [Byte] "0x$_"} [Byte[]] $MagicPacket = (,0xFF * 6) + ($MacByteArray * 16) $UdpClient = New-Object System.Net.Sockets.UdpClient $UdpClient.Connect(([System.Net.IPAddress]::Broadcast),$port) $UdpClient.Send($MagicPacket,$MagicPacket.Length) $UdpClient.Close() } } Send-Wol -mac "12:34:56:78:90:aa"
If you’re trying to do a wake only task, the syntax will likely be different for the json you need to send
You might try creating a scheduled wake on lan task manually and then get the pending task from the api to see the fields
i.e.Get-FogObject -type objectactivetasktype -coreActiveTaskObject scheduledtask | select -expand data | select * -ExcludeProperty host | ConvertTo-Json
I ran that and in comparing those values and assuming you don’t want it to be scheduled, this should do the trick (I tested it and it did indeed do the trick)
$jsonData = @" { "taskTypeID":"14", "wol":"1", "other2":"-1", "other4":"1", "isActive":"1" } "@ New-FogObject -type objecttasktype -coreTaskObject host -jsonData $jsonData -IDofObject $hostID
The send-fogimage function was a good one to look at for an example, but pushing an image has more fields for the task than other tasks, some tasks only need the type id and what host to run it on. This one might even work without some of these variables.
Hope that helps
-
@Lenain I also made a github issue for making a function out of this
https://github.com/darksidemilk/FogApi/issues/7If you’re feeling saucy feel free to fork the repo and give it a go and pull request it. I’ll get to it eventually, but it could be quite a while, life is rather busy at the moment.
-
Hi @JJ-Fullmer and thank you for your help!
I am trying to create a wake on lan task only, it work fine from the web interface. My fog can send icmp packet trought all vlans and it is the only one, that’s why I’m trying to use it with powershell. I will try youe example asap, thank’s!! -
@JJ-Fullmer Thank you so much, your solution work fine! I’ve made a script to do so:
param (
[Parameter(Mandatory=$true)]
[string]$machineName
)
$hostID= get-foghost -hostName $machineName | Select-Object -ExpandProperty id
$jsonData = @"
{
“taskTypeID”:“14”,
“wol”:“1”,
“other2”:“-1”,
“other4”:“1”,
“isActive”:“1”
}
"@New-FogObject -type objecttasktype -coreTaskObject host -jsonData $jsonData -IDofObject $hostID
-
@Lenain That’s great to hear, glad we could get it figured out.
-
@Lenain Just a little FYI.
I don’t know when I’ll have time to test it out fully before putting it into production, but the idea of adding this to the module was not forgotten and I started a branch for it while I was working on some other bug fixes
https://github.com/darksidemilk/FogApi/commit/03c0342cff759ef272a64bbb91cbb1b5999bab9c