• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    API wake on lan

    Scheduled Pinned Locked Moved
    General
    3
    10
    632
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • LenainL
      Lenain
      last edited by

      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 😅

      Tom ElliottT 1 Reply Last reply Reply Quote 0
      • Tom ElliottT
        Tom Elliott @Lenain
        last edited by

        @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.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        LenainL 2 Replies Last reply Reply Quote 0
        • LenainL
          Lenain @Tom Elliott
          last edited by

          @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

          1 Reply Last reply Reply Quote 0
          • LenainL
            Lenain @Tom Elliott
            last edited by

            @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";
                }
                
            }
            
            JJ FullmerJ 2 Replies Last reply Reply Quote 0
            • JJ FullmerJ
              JJ Fullmer Testers @Lenain
              last edited by

              @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

              Have you tried the FogApi powershell module? It's pretty cool IMHO
              https://github.com/darksidemilk/FogApi
              https://fogapi.readthedocs.io/en/latest/
              https://www.powershellgallery.com/packages/FogApi
              https://forums.fogproject.org/topic/12026/powershell-api-module

              LenainL 1 Reply Last reply Reply Quote 0
              • JJ FullmerJ
                JJ Fullmer Testers @Lenain
                last edited by

                @Lenain I also made a github issue for making a function out of this
                https://github.com/darksidemilk/FogApi/issues/7

                If 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.

                Have you tried the FogApi powershell module? It's pretty cool IMHO
                https://github.com/darksidemilk/FogApi
                https://fogapi.readthedocs.io/en/latest/
                https://www.powershellgallery.com/packages/FogApi
                https://forums.fogproject.org/topic/12026/powershell-api-module

                LenainL 1 Reply Last reply Reply Quote 1
                • LenainL
                  Lenain @JJ Fullmer
                  last edited by

                  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 FullmerJ 1 Reply Last reply Reply Quote 0
                  • LenainL
                    Lenain @JJ Fullmer
                    last edited by

                    @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

                    JJ FullmerJ 1 Reply Last reply Reply Quote 1
                    • JJ FullmerJ
                      JJ Fullmer Testers @Lenain
                      last edited by

                      @Lenain That’s great to hear, glad we could get it figured out.

                      Have you tried the FogApi powershell module? It's pretty cool IMHO
                      https://github.com/darksidemilk/FogApi
                      https://fogapi.readthedocs.io/en/latest/
                      https://www.powershellgallery.com/packages/FogApi
                      https://forums.fogproject.org/topic/12026/powershell-api-module

                      1 Reply Last reply Reply Quote 0
                      • JJ FullmerJ
                        JJ Fullmer Testers @Lenain
                        last edited by

                        @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

                        Have you tried the FogApi powershell module? It's pretty cool IMHO
                        https://github.com/darksidemilk/FogApi
                        https://fogapi.readthedocs.io/en/latest/
                        https://www.powershellgallery.com/packages/FogApi
                        https://forums.fogproject.org/topic/12026/powershell-api-module

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post

                        166

                        Online

                        12.0k

                        Users

                        17.3k

                        Topics

                        155.2k

                        Posts
                        Copyright © 2012-2024 FOG Project