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

    API - Create Host Deploy Task "error": "Invalid tasking type passed"

    Scheduled Pinned Locked Moved Solved
    FOG Problems
    5
    11
    1.5k
    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.
    • S
      scottybullet
      last edited by

      After Creating hosts and Assigning the image now trying to create a deploy task. I am getting “Invalid tasking type passed” This is what i am running:

      $TaskURL = $baseUri + "/host/" + $HostID + "/task"
              $TaskdataSet = @{
                  "imageID" = $Image.id
                  "type" = "1"
                  "typeID" = $TasktypeID
                  "stateID" = 1
                  }
              $taskdataToSend = ConvertTo-JSON($TaskdataSet)
              $TaskResult = Invoke-RestMethod -Method Post -Uri $TaskURL -Headers $headers  -Body $taskdataToSend -ContentType "application/json"
      
      1 Reply Last reply Reply Quote 0
      • george1421G
        george1421 Moderator
        last edited by

        I can only shoot in the dark here since I have not personally used the API. But I think the API in this case is referencing the tasks table in mysql. If that is the case, I don’t see a “type” field in the table. I don’t know if there is a one for one relationship between the API json request and the database table.

        +------------------------+---------------------------+------+-----+-------------------+----------------+
        | Field                  | Type                      | Null | Key | Default           | Extra          |
        +------------------------+---------------------------+------+-----+-------------------+----------------+
        | taskID                 | int(11)                   | NO   | PRI | NULL              | auto_increment |
        | taskName               | varchar(250)              | NO   |     | NULL              |                |
        | taskCreateTime         | timestamp                 | NO   |     | CURRENT_TIMESTAMP |                |
        | taskCheckIn            | datetime                  | NO   | MUL | NULL              |                |
        | taskHostID             | int(11)                   | NO   | MUL | NULL              |                |
        | taskImageID            | int(11)                   | NO   |     | NULL              |                |
        | taskStateID            | int(11)                   | NO   | MUL | NULL              |                |
        | taskIsDebug            | mediumint(9)              | NO   |     | NULL              |                |
        | taskCreateBy           | varchar(200)              | NO   |     | NULL              |                |
        | taskForce              | varchar(1)                | NO   | MUL | NULL              |                |
        | taskScheduledStartTime | datetime                  | NO   |     | NULL              |                |
        | taskTypeID             | mediumint(9)              | NO   | MUL | NULL              |                |
        | taskPCT                | int(10) unsigned zerofill | NO   |     | NULL              |                |
        | taskBPM                | varchar(250)              | NO   |     | NULL              |                |
        | taskTimeElapsed        | varchar(250)              | NO   |     | NULL              |                |
        | taskTimeRemaining      | varchar(250)              | NO   |     | NULL              |                |
        | taskDataCopied         | varchar(250)              | NO   |     | NULL              |                |
        | taskPercentText        | varchar(250)              | NO   |     | NULL              |                |
        | taskDataTotal          | varchar(250)              | NO   |     | NULL              |                |
        | taskNFSGroupID         | int(11)                   | NO   | MUL | NULL              |                |
        | taskNFSMemberID        | int(11)                   | NO   | MUL | NULL              |                |
        | taskNFSFailures        | char(1)                   | NO   | MUL | NULL              |                |
        | taskLastMemberID       | int(11)                   | NO   | MUL | NULL              |                |
        | taskWOL                | enum('0','1')             | NO   |     | NULL              |                |
        | taskPassreset          | varchar(250)              | NO   |     | NULL              |                |
        | taskShutdown           | char(1)                   | NO   |     | NULL              |                |
        +------------------------+---------------------------+------+-----+-------------------+----------------+
        

        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!

        1 Reply Last reply Reply Quote 0
        • S
          scottybullet
          last edited by

          This is what a qued deploy task looks like from the api:

          
          id                 : 2
          name               : Deploy Task
          checkInTime        : 0000-00-00 00:00:00
          hostID             : 2
          stateID            : 1
          createdTime        : 2017-12-06 18:35:47
          createdBy          : fog
          isForced           : 0
          scheduledStartTime : 0000-00-00 00:00:00
          typeID             : 1
          pct                : 0000000000
          bpm                : 
          timeElapsed        : 
          timeRemaining      : 
          dataCopied         : 
          percent            : 
          dataTotal          : 
          storagegroupID     : 1
          storagenodeID      : 1
          NFSFailures        : 
          NFSLastMemberID    : 0
          shutdown           : 
          passreset          : 
          isDebug            : 0
          imageID            : 1
          wol                : 1
          image              : @{imageTypeID=1; imagePartitionTypeID=1; id=1; name=Ubuntu1604minimal; description=Base Ubuntu 16.04 Image; path=Ubuntu1604minimal; createdTime=2017-12-06 15:07:51; createdBy=fog; building=0; size=60477440.000000:20961034240.000000:; 
                               osID=50; deployed=2017-12-06 15:55:46; format=0; magnet=; protected=0; compress=6; isEnabled=1; toReplicate=1; srvsize=984037345; os=; imagepartitiontype=; imagetype=; imagetypename=Single Disk - Resizable; 
                               imageparttypename=Everything; osname=Linux; storagegroupname=default; hosts=System.Object[]; storagegroups=System.Object[]}
          host               : @{id=2; name=005056a47ffc; description=Created by FOG Reg on December 6, 2017, 3:37 pm; ip=; imageID=1; building=0; createdTime=2017-12-06 15:37:39; deployed=0000-00-00 00:00:00; createdBy=fog; useAD=; ADDomain=; ADOU=; ADUser=; 
                               ADPass=; ADPassLegacy=; productKey=; printerLevel=; kernelArgs=; kernel=; kernelDevice=; init=; pending=; pub_key=; sec_tok=; sec_time=0000-00-00 00:00:00; pingstatus=<i class="icon-ping-down fa fa-exclamation-circle red fa-1x" 
                               title="No such device or address"></i>; biosexit=; efiexit=; enforce=; primac=00:50:56:a4:7f:fc; imagename=Ubuntu1604minimal; hostscreen=; hostalo=; inventory=; macs=System.Object[]}
          type               : @{id=1; name=Deploy; description=Deploy action will send an image saved on the FOG server to the client computer with all included snapins.; icon=download; kernel=; kernelArgs=type=down; type=fog; isAdvanced=0; access=both}
          state              : @{id=1; name=Queued; description=Task has been created and FOG is waiting for the Host to check-in.; order=1; icon=bookmark-o}
          storagenode        : @{id=1; name=DefaultMember; description=Auto generated fog nfs group member; isMaster=1; storagegroupID=1; isEnabled=1; isGraphEnabled=1; path=/images/; ftppath=/images/; bitrate=; snapinpath=/opt/fog/snapins; 
                               sslpath=/opt/fog/snapins/ssl; ip=10.10.12.24; maxClients=10; user=fog; pass=I1MKdP3eIKFmA4jgrbHjO9+J3LohoizYUag9qOqj4Rg=; key=; interface=ens160; bandwidth=0; webroot=/fog/; storagegroup=}
          storagegroup       : @{id=1; name=default; description=Auto generated fog nfs group}
          
          george1421G 1 Reply Last reply Reply Quote 0
          • george1421G
            george1421 Moderator @scottybullet
            last edited by

            @scottybullet Ok (first I’m a db guy not an api guy, so everything I see is sql).

            If you look at the table def. There is no type but there is a taskTypeID which appears to be a foreign key to the taskType table.

            +---------------+-----------------------------+------+-----+---------+----------------+
            | Field         | Type                        | Null | Key | Default | Extra          |
            +---------------+-----------------------------+------+-----+---------+----------------+
            | ttID          | mediumint(9)                | NO   | PRI | NULL    | auto_increment |
            | ttName        | varchar(30)                 | NO   | UNI | NULL    |                |
            | ttDescription | text                        | NO   |     | NULL    |                |
            | ttIcon        | varchar(30)                 | NO   |     | NULL    |                |
            | ttKernel      | varchar(100)                | NO   |     | NULL    |                |
            | ttKernelArgs  | text                        | NO   |     | NULL    |                |
            | ttType        | enum('fog','user')          | NO   |     | user    |                |
            | ttIsAdvanced  | enum('0','1')               | NO   |     | 0       |                |
            | ttIsAccess    | enum('both','host','group') | NO   |     | both    |                |
            +---------------+-----------------------------+------+-----+---------+----------------+
            
            

            If you run the command select ttID, ttName, ttType from taskTypes; this is the results

            +------+-------------------------+--------+
            | ttID | ttName                  | ttType |
            +------+-------------------------+--------+
            |    1 | Deploy                  | fog    |
            |    2 | Capture                 | fog    |
            |    3 | Debug                   | fog    |
            |    4 | Memtest86+              | fog    |
            |    5 | Test Disk               | fog    |
            |    6 | Disk Surface Test       | fog    |
            |    7 | Recover                 | fog    |
            |    8 | Multi-Cast              | fog    |
            |   10 | Hardware Inventory      | fog    |
            |   11 | Password Reset          | fog    |
            |   12 | All Snapins             | fog    |
            |   13 | Single Snapin           | fog    |
            |   14 | Wake-Up                 | fog    |
            |   15 | Deploy - Debug          | fog    |
            |   16 | Capture - Debug         | fog    |
            |   17 | Deploy - No Snapins     | fog    |
            |   18 | Fast Wipe               | fog    |
            |   19 | Normal Wipe             | fog    |
            |   20 | Full Wipe               | fog    |
            |   21 | Virus Scan              | fog    |
            |   22 | Virus Scan - Quarantine | fog    |
            +------+-------------------------+--------+
            
            

            What I don’t know from the API side is type the ttID value or the ttType.

            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!

            S 1 Reply Last reply Reply Quote 0
            • george1421G
              george1421 Moderator
              last edited by

              looking at the API docs, I’m not sure but you might be in the wrong tree to create a new task??

              https://news.fogproject.org/simplified-api-documentation/

              specifically

              2. /fog/<object>/create Create new object. 
              

              but again I can only guess.

              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!

              1 Reply Last reply Reply Quote 0
              • S
                scottybullet @george1421
                last edited by

                @george1421
                Correct, this will be API specific and I am getting the ID of the Deploy task type form another api call. the raw json I am passing is this:

                {
                    "typeID":  "1",
                    "imageID":  "1",
                    "type":  "1",
                    "stateID":  1
                }
                

                I saw a Sample to run a single Snapin Task as :

                since I am only running a Deploy Task I would assume to meed the hostID in the URL as i am

                http://10.10.12.24/fog/host/12/task
                

                my ImageID is 1 since it’s the first one I have created and type is 1 for Deploy task… I was just guessing at TypeID and StateID.

                S 1 Reply Last reply Reply Quote 0
                • S
                  scottybullet @scottybullet
                  last edited by

                  Figured this out, I hope it helps someone out… this PS Script creates a Host and then creates a deploy task to the Image specified when the host was created.

                  $vmname = "vmname"
                  $MacAddress = "00:00:00:00:00:00"
                  $ImageName = "ImageName"
                  
                  #######################################################################################################################
                  # Configure the variables below for the Fog Server
                  #######################################################################################################################
                      #FogServer
                          $fogApiToken = 'your token'
                          $fogUserToken = 'your user token'
                          $fogServer = "fog server IP or dns name"
                          $Description = "Created by vCommander"   # www.embotics.com
                      
                  ########################################################################################################################
                  # Nothing to configure below this line - Starting the main function of the script
                  ########################################################################################################################
                  
                  ########################################################################################################################
                  # Setting Cert Policy - required for successful auth with the server if set to https
                  ########################################################################################################################
                  add-type @"
                      using System.Net;
                      using System.Security.Cryptography.X509Certificates;
                      public class TrustAllCertsPolicy : ICertificatePolicy {
                          public bool CheckValidationResult(
                              ServicePoint srvPoint, X509Certificate certificate,
                              WebRequest request, int certificateProblem) {
                              return true;
                          }
                      }
                  "@
                  [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
                  [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
                  
                  ########################################################################################################################
                      #Setup Auth headers and base url for FogServer
                          $headers = @{};
                          $headers.Add('fog-api-token', $fogApiToken);
                          $headers.Add('fog-user-token', $fogUserToken);
                          $baseUri = "http://$fogServer/fog"
                      
                      #Get Image List From Fog Server
                          $ImageURL = $baseUri+"/image/"
                          $ImageResult = Invoke-RestMethod -Uri $ImageURL -Method GET -Headers $headers -ContentType "application/json"
                          $Image = $ImageResult.images | Select-object imageTypeID,id,name | Where-object {$_.name -eq $ImageName}
                         
                  
                      #GetHost List from fog Server
                          $HostURL = $baseUri +"/host/"
                          $HostResult = Invoke-RestMethod -Uri $HostURL -Method GET -Headers $headers -ContentType "application/json"
                  
                      #Create Host entry from vCommander
                         $HostJson = @{
                                             "name"=  $vmname
                                             "description"=  $Description
                                             "macs" =  @($MacAddress)
                                             "imageID"= $Image.id
                                             "imagename" =  $ImageName  
                                             }
                          $CreateHostJson = ConvertTo-Json($HostJson)
                          $createHostURL = $baseUri +"/host/create"
                          $createHostResult = Invoke-RestMethod -Uri $createHostURL -Method POST -body $CreateHostJson -Headers $headers -ContentType "application/json"
                  
                      #Get Task types to confirm Structure
                           $TasktypesURL = $baseUri + "/tasktype"
                           $TasktypesResult = Invoke-RestMethod -Uri $TasksURL -Method GET -Headers $headers -ContentType "application/json"
                           $TasktypeID = ($TasktypesResult.tasktypes | Select-object name,id | Where-object {$_.name -eq "Deploy"}).id
                  
                      #Create Task to Image Host    
                          $ImageID = $image.id
                          $HostID = $createHostResult.id  
                  
                          $TaskURL = $baseUri + "/host/" + $HostID + "/task"
                          $TaskdataSet = @{
                              "hostname" = $createHostResult.name
                              "taskTypeID" = $TasktypeID
                              }
                          $taskdataToSend = ConvertTo-JSON($TaskdataSet)
                          $TaskResult = Invoke-RestMethod -Method Post -Uri $TaskURL -Headers $headers -Body $taskdataToSend -ContentType "application/json"
                  
                  1 Reply Last reply Reply Quote 2
                  • Wayne WorkmanW
                    Wayne Workman
                    last edited by

                    #wiki worthy

                    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!
                    Daily Clean Installation Results:
                    https://fogtesting.fogproject.us/
                    FOG Reporting:
                    https://fog-external-reporting-results.fogproject.us/

                    1 Reply Last reply Reply Quote 0
                    • J
                      Jamaal
                      last edited by Sebastian Roth

                      I’m having issues with this, not sure what I’m doing wrong.
                      I’ll still troubleshoot, but getting this error:

                      Invoke-RestMethod : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command 
                      again.
                      At E:\Temp\Scripts\fogtest2.ps1:66 char:52
                      +          $TasktypesResult = Invoke-RestMethod -Uri $TasksURL -Method  ...
                      +                                                    ~~~~~~~~~
                          + CategoryInfo          : InvalidData: (:) [Invoke-RestMethod], ParameterBindingValidationException
                          + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
                       
                      Invoke-RestMethod : The remote server returned an error: (501) Not Implemented.
                      At E:\Temp\Scripts\fogtest2.ps1:79 char:23
                      + ... askResult = Invoke-RestMethod -Method Post -Uri $TaskURL -Headers $he ...
                      

                      This is how I have it edited from the beginning, not sure if this messing it up:

                      $vmname =read-host "Enter the computer name you want to name"
                      $MacAddress = read-host "Enter the MAC Address of the host computer you're going to image"
                      $ImageName = read-host " Enter the name of the image you want to use"
                      

                      I edited it like that because I want to test for example, another technician to just put the values in there and then your script will automate everything.

                      1 Reply Last reply Reply Quote 0
                      • S
                        Sebastian Roth Moderator
                        last edited by

                        @Jamaal From the error message I would imagine that this last call is failing because an earlier query also failed and variables are not being set correctly because of the earlier error. So you need to post the full error you see!

                        I am not a PowerShell wiz but from what I know the read-host stuff you added should work.

                        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

                        J 1 Reply Last reply Reply Quote 0
                        • J
                          Jamaal @Sebastian Roth
                          last edited by

                          @Sebastian-Roth said in API - Create Host Deploy Task "error": "Invalid tasking type passed":

                          @Jamaal From the error message I would imagine that this last call is failing because an earlier query also failed and variables are not being set correctly because of the earlier error. So you need to post the full error you see!

                          I am not a PowerShell wiz but from what I know the read-host stuff you added should work.

                          Thanks man, you pointed me in the right direction.
                          So I went back to your script again and ran it and noticed it kept giving an error message after the 1st throw command, like Powershell was skipping the 2nd and 3rd throw command.

                          What I had to do was do a read-host, but kept the $ (read-host “enter machine name”) for example:

                          [String] $MachineName = $( read-host “Provide the target machines Name”),
                          [String] $MacAddress = $(Read-Host “Provide the target machine Address”),
                          [String] $ImageName = $(read-host “Provide the Image Name to assign to the new target host”)
                          So I saw the task in the task list right away. I’m so so with powershell and starting to get better with it, you know. What I would like to do is maybe figure out powershell commands to add the snapins as a read-host so the tech can select which snapins to use instead of going to the Fog console to be more automatic.

                          And I would like Powershell to start the task once the hostname is added to Fog. I can start playing around that.

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

                          160

                          Online

                          12.0k

                          Users

                          17.3k

                          Topics

                          155.2k

                          Posts
                          Copyright © 2012-2024 FOG Project