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

API

Scheduled Pinned Locked Moved Solved
General
6
19
7.3k
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.
  • G
    george1421 Moderator
    last edited by May 5, 2017, 12:07 PM

    #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!

    1 Reply Last reply Reply Quote 1
    • T
      Tom Elliott
      last edited by May 5, 2017, 12:18 PM

      This is just a quick means to represent how you could filter the tasks if you needed to as well.

      Our “List all tasks” works without a body sent, but CAN be filtered to get specific information for active tasks. The example just shows how you might want to get active tasks for host ids of 5 and 6. I’m not trying to show actual payload right now. Just trying to show example use cases.

      So let’s do this command line style:
      Let’s just say your api token is abcde
      Let’s just say your user token is fghij
      List all current/active tasks is a GET request.
      URL for now is just fogserver

      curl -H 'fog-api-token: abcde' -H 'fog-user-token: fghij' -X GET http://fogserver/fog/task/current -o listalltasks.json -d '{"hostID":[5,6]}'
      

      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

      1 Reply Last reply Reply Quote 0
      • T
        theWizard @Tom Elliott
        last edited by May 5, 2017, 12:53 PM

        @Tom-Elliott said in API:

        curl -H ‘fog-api-token: abcde’ -H ‘fog-user-token: fghij’ -X GET http://fogserver/fog/task/current

        Thankyou perhaps i will have to wait as anything i try results in
        The requested URL /fog/task/current was not found on this server.

        T 1 Reply Last reply May 5, 2017, 12:53 PM Reply Quote 0
        • T
          Tom Elliott @theWizard
          last edited by May 5, 2017, 12:53 PM

          @theWizard I don’t follow.

          What are you using as a test, exactly?

          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

          T 1 Reply Last reply May 5, 2017, 12:55 PM Reply Quote 0
          • T
            theWizard @Tom Elliott
            last edited by May 5, 2017, 12:55 PM

            @Tom-Elliott
            I’m using powershell with Invoke-WebRequest which is alias for curl

            U 1 Reply Last reply Jul 10, 2017, 6:31 PM Reply Quote 0
            • U
              UWPVIOLATOR @theWizard
              last edited by Jul 10, 2017, 6:31 PM

              @theWizard

              What did your Powershell command look like? I would like to see that example. I am most familiar with it and the one main thing I need to work on is a for each from a csv file with all of our old junked computers and laptops returned from lease. We no longer need them in fog.

              G 2 Replies Last reply Jul 10, 2017, 7:34 PM Reply Quote 0
              • G
                george1421 Moderator @UWPVIOLATOR
                last edited by Jul 10, 2017, 7:34 PM

                @UWPVIOLATOR Not the answer you are looking for, but a bit more details that Wayne uses for FOG scripting. https://forums.fogproject.org/topic/9779/can-i-use-some-kind-of-script-to-create-image-and-ghost-my-lab-machines/15

                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 1
                • G
                  george1421 Moderator @UWPVIOLATOR
                  last edited by george1421 Jul 10, 2017, 6:23 PM Jul 11, 2017, 12:21 AM

                  @UWPVIOLATOR Warning: I’m not a programmer (or even know how to program in PS) and sometimes I even question if I know what I doing here…

                  But I think I was able to translate one of Wayne’s posts with a curl call into powershell.

                  curl --silent -k -H 'Content-Type: application/json' -H 'fog-user-token: ZjBkMmE3YmI5NmUzZDcxYTliYzNkZTc4MmJhNTFiYTQ3Mzc2MTg5MzYxMThmNjA5NDYyMjllMTA5YzE0NWUxMjFiNzkyMTc5OTMwZjFhZGM5NWIxMTc3YWZmNTU2MmMwYjFhNjg0NjVmMTkyMGZkNDQxYmY0MzI1NWNkMzQyM2M=' -H 'fog-api-token: MzI2NDY1NjY2NjM0MzUzMDMzMzA2MzM1MzEzNzYyMzg2NTYyNjQ2MjMxMzczMTM0NjY2NDM0NjUzOTM2NjIzNDM4MzQ2NDM3MzY2MzM2MzMzNjYyMzUzODY0MzUzNDYyMzgzMDY2NjQzNTMxMzI2MzM5NjYzNjYzMzMzMzM0MzA=' http://10.0.0.28/fog/host/testhost1/task -d '{"taskTypeID":1,"shutdown": true}'
                  

                  would translate into something like this:

                  $headers = @{}
                  $headers.Add("fog-user-token", "ZjBkMmE3YmI5NmUzZDcxYTliYzNkZTc4MmJhNTFiYTQ3Mzc2MTg5MzYxMThmNjA5NDYyMjllMTA5YzE0NWUxMjFiNzkyMTc5OTMwZjFhZGM5NWIxMTc3YWZmNTU2MmMwYjFhNjg0NjVmMTkyMGZkNDQxYmY0MzI1NWNkMzQyM2M=")
                  $headers.Add("fog-api-token", "MzI2NDY1NjY2NjM0MzUzMDMzMzA2MzM1MzEzNzYyMzg2NTYyNjQ2MjMxMzczMTM0NjY2NDM0NjUzOTM2NjIzNDM4MzQ2NDM3MzY2MzM2MzMzNjYyMzUzODY0MzUzNDYyMzgzMDY2NjQzNTMxMzI2MzM5NjYzNjYzMzMzMzM0MzA=")
                  
                  $mydata = @{}
                  $mydata.Add("taskTypeID", "1")
                  $mydata.Add("shutdown", "true")
                  
                  $json = $mydata | ConvertTo-Json
                  $Uri = 'http://10.0.0.28/fog/host/testhost1/task'
                  
                  Invoke-WebRequest -Method Post -Uri $Uri -Header $header -Body $json -ContentType 'application/json'
                  
                  

                  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!

                  T 1 Reply Last reply Jul 11, 2017, 2:05 AM Reply Quote 0
                  • T
                    Tom Elliott @george1421
                    last edited by Tom Elliott Jul 10, 2017, 8:09 PM Jul 11, 2017, 2:05 AM

                    @george1421 There’ s a simpler method

                    Here’s some scripts that I run.

                    This is specific to my needs on a different project, but could be converted as needed.

                    buildheaders.ps1

                    <# Build headers script help
                        .SYNOPSIS
                            This powershell script just creates a single point for building headers
                            rather than constantly rewriting the same script over and over.
                        .USAGE
                            This just sources the function so there is no real usage here.
                    #>
                    function Build-Headers {
                        Param(
                            [string]$authorizationString,
                            [string]$tenantCode,
                            [string]$acceptType,
                            [string]$contentType
                        )
                        
                        $header = @{
                            "fog-api-token" = $fogApiToken;
                            "fog-user-token" = $fogUserToken;
                            #"Accept" = $accept;
                            "Content-Type" = $contentType
                        }
                    
                        Write-Verbose("");
                        Write-Verbose("---------- Headers ----------");
                        Write-Verbose("Authorization: " + $authorizationString);
                        Write-Verbose("fog-api-token: " + $fogApiToken);
                        Write-Verbose("fog-user-token: " + $fogUserToken);
                        Write-Verbose("Accept: " + $acceptType);
                        Write-Verbose("Content-Type: " + $contentType);
                        Write-Verbose("-----------------------------");
                        Write-Verbose("");
                    
                        Return $header
                    }
                    

                    Use case script – To create a task for a host with say ID # 10.

                    taskhost.ps1

                    <# Creates Task for id passed in to script.
                        .SYNOPSIS
                            Helps create task from command line.
                        .PARAMETER id (required)
                            This is the ID Of the Host to task.
                        .PARAMETER configFile (optional)
                            This is not a required file, this allows you to use a different
                            basicconfig.ps1 file if need be.
                    #>
                    [CmdletBinding()]
                        Param(
                            [Parameter(Mandatory=$True)]
                            [string]$id,
                    
                            [Parameter()]
                            [string]$configFile
                        )
                    
                    # Set errors to silent if we are not in verbose mode.
                    If (!$PSCmdlet.Myinvocation.BoundParameters["Verbose"].IsPresent) {
                        $ErrorActionPreference = "SilentlyContinue"
                    }
                    
                    # Setup up defailt if configFile is not already set.
                    If (!$configFile) {
                        $configFile = '.\basicconfig.ps1'
                    }
                    
                    # Load our config file.
                    . $configFile
                    
                    # Set our base call (item) for the api.
                    $baseURL = $endpointURL + "/host/" + $id + "/task"
                    
                    # Source build headers function.
                    . ".\buildheaders.ps1"
                    
                    # We know we're using json so set accept/content type as such.
                    $contentType = "application/json"
                    
                    # Get our headers Building off the config file information.
                    $headers = Build-Headers $fogApiToken $fogUserToken $contentType $contentType
                    
                    # Display what url we are calling so somebody could use it later if in verbose.
                    Write-Verbose ""
                    Write-Verbose "---------- Caller URL ----------"
                    Write-Verbose ("URL: " + $baseURL)
                    Write-Verbose "--------------------------------"
                    Write-Verbose ""
                    
                    $dataSet = @{
                        "taskTypeID" = 1
                        "shutdown" = true
                    }
                    
                    $dataToSend = ($dataSet | ConvertTo-JSON)
                    
                    # Display the data we're sending
                    Write-Verbose ""
                    Write-Verbose "---------- Sending Body ----------"
                    Write-Verbose $dataToSend
                    Write-Verbose "----------------------------------"
                    Write-Verbose ""
                    
                    # Perform the request
                    $ret = Invoke-RestMethod -Method Post -Uri $baseURL -Headers $headers -ContentType $contentType -Body $dataToSend
                    
                    # Write our return information if there is anything to see.
                    Write-Verbose ""
                    Write-Verbose "---------- Returned Data ----------"
                    Write-Verbose $ret
                    Write-Verbose "-----------------------------------"
                    Write-Verbose ""
                    
                    # All Done
                    

                    You would have all three files in the same place and call from powershell:
                    .\taskhost.ps1 -id 10

                    Hopefully this helps. Of course it could be more generalized, but I’m just giving a basic overview.

                    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

                    1 Reply Last reply Reply Quote 0
                    • T
                      Tom Elliott
                      last edited by Jul 11, 2017, 2:07 AM

                      basicconfig.ps1

                      <# Config for our scripts.
                          .SYNOPSIS
                              Just used to store our common variables that we don't want to
                              recode for every script.
                          .USAGE
                              No related usage, just sets variables.
                      #>
                      $fogApiToken = "TokenFromGUIForAPIAccess";
                      $fogUserToken = "TokenFromGUIForUserToken";
                      $endpointURL = "http://fogserver/fog/";
                      

                      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

                      1 Reply Last reply Reply Quote 0
                      • Wayne WorkmanW
                        Wayne Workman @theWizard
                        last edited by Jul 11, 2017, 2:41 AM

                        @theWizard I’ve listed the examples I have here: https://forums.fogproject.org/topic/9779/can-i-use-some-kind-of-script-to-create-image-and-ghost-my-lab-machines

                        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
                        • A
                          AndrewG78
                          last edited by Nov 15, 2017, 1:20 PM

                          Hi, Could you please share an example of query to obtain list of active tasks per given GROUP ID?
                          I just want to check if all multicast jobs are done in a specific group.
                          Thx.

                          Wayne WorkmanW 1 Reply Last reply Nov 16, 2017, 6:12 PM Reply Quote 0
                          • Wayne WorkmanW
                            Wayne Workman @AndrewG78
                            last edited by Nov 16, 2017, 6:12 PM

                            @andrewg78 Probably, I’ll have to look into it. Multicast tasks are handled differently than unicast tasks - they are treated as an individual job. If you wanted to get the status of the entire job, you could probably just follow along with the examples in this link: https://forums.fogproject.org/topic/9779/can-i-use-some-kind-of-script-to-create-image-and-ghost-my-lab-machines Though you would need to use the multicast task type, or know the task ID already.

                            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/

                            A 1 Reply Last reply Dec 1, 2017, 4:24 PM Reply Quote 0
                            • A
                              AndrewG78 @Wayne Workman
                              last edited by Dec 1, 2017, 4:24 PM

                              @wayne-workman
                              Thx. I figured out where was the issue. Maybe this info will help somebody.
                              I use curl under Windows, but command line doesn’t support single quotes '.
                              I used " and had to escape inner ones
                              –data “{\“hostID\”:13}”

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

                              286

                              Online

                              12.0k

                              Users

                              17.3k

                              Topics

                              155.2k

                              Posts
                              Copyright © 2012-2024 FOG Project