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

Update-FogObject / Powershell module use

Scheduled Pinned Locked Moved Solved
General
3
7
1.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.
  • M
    mparlette
    last edited by Sebastian Roth Sep 18, 2018, 1:06 PM Sep 18, 2018, 7:04 PM

    Not sure if this is the correct place for this post but I am using the PowerShell module created by: JJ Fullmer
    https://github.com/FOGProject/fog-community-scripts/tree/master/PowershellModules/FogApi

    Can someone look over this code for me? Trying to move hosts from one group to another:

    Import-Module FogApi
    
    $Groupnames = Get-FogObject -type object -coreObject group
    $groupassoc = (Get-FogObject -type object -coreObject groupassociation).groupassociations
    $queue = $Groupnames.groups | where {$_.Name -eq "Queued"}
    $Hostnames = (Get-FogObject -type object -coreObject host).hosts
    $sys_queue = $groupassoc | where {$_.groupID -eq $queue.id}
    $free_sys = $groupassoc  | where {$_.groupID -eq "0"}
    
    if($free_sys.Count -gt 0){
        Write-host I found $free_sys.count hosts to move to Queued.
        foreach($freehost in $free_sys){
        #command to move $free_sys to queued group.
        $HostJson = (@{hosts = $free_sys.ID} | ConvertTo-Json)
        write-host Update-FogObject ...
        Update-FogObject -type object -coreObject group -jsonData $HostJson -IDofObject $queue.ID
        
        }
        
    }
    

    output:

    Update-FogObject ...
    Invoke-RestMethod : The remote server returned an error: (501) Not Implemented.
    At C:\Program Files\WindowsPowerShell\Modules\FogApi\FogApi.psm1:270 char:19
    +         $result = Invoke-RestMethod @apiCall;
    +                   ~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
     
    
    PS C:\Users\Administrator> $HostJson
    {
        "hosts":  [
                      "34",
                      "35",
                      "36",
                      "37",
                      "38",
                      "39",
                      "40",
                      "41",
                      "42",
                      "43"
                  ]
    }
    
    PS C:\Users\Administrator> $queue.ID
    35
    
    1 Reply Last reply Reply Quote 1
    • M
      mparlette
      last edited by Sep 27, 2018, 5:57 PM

      I have this figured out. IT seems like the Update-FogObject PS module isn’t handling this correctly (Content type issue?). Just used Invoke-RestMethod instead.

      Please resolve this.
      Thanks.

      J 3 Replies Last reply Oct 11, 2018, 6:19 PM Reply Quote 1
      • S
        Sebastian Roth Moderator
        last edited by Sep 27, 2018, 7:57 PM

        @mparlette Nice you figured this one out! I have had a quick look when you first posted but didn’t seem to be able to say what’s wrong. Maybe you are keen to find out why Update-FogObject PS module is failing and help us improve it?

        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 1
        • J
          JJ Fullmer Testers @mparlette
          last edited by Oct 11, 2018, 6:19 PM

          @mparlette I just saw this and just today was finding some issue with Update-fogobject
          The issue appears to be with the dynamic parameter variable I have in the function for the coreobjecttype.
          For some reason it is working when you call the function and brings up all the coreobject type choices but then the variable is being set to null when the function is running.
          Meaning that when function builds the uri it only gets
          http://fogserver/fog//id/edit
          instead of
          http://fogserver/fog/coreObjectType/id/edit

          So one workaround I will try to publish by the end of the day is adding an optional uri parameter to that function so that you can manually override it when neccesarry.
          Also I should really add more documentation to each of the functions instead of just having it all under Invoke-fogapi

          I also will add a try/catch block to invoke-fogapi for when invoke-restmethod fails and have it try invoke-webrequest.

          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
          • J
            JJ Fullmer Testers @mparlette
            last edited by Oct 11, 2018, 6:24 PM

            @mparlette also, ps. If you run that same code with a -verbose on update-fogobject you’ll get a lot more information.

            Another quick update is that I’m also working on a better settings system where the module’s saved settings are stored in the fog service program file folder so that they aren’t overridden when you update the module.

            All of these updates may take a while to get done and published as I have a lot of other projects at the moment and I tend to put my work in an internal git repo and just publish stable things to the fog community git and psgallery.

            If you’re in a bit of a rush and are ok with beta code to play with, I can zip up my current working version and post it here

            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
            • J
              JJ Fullmer Testers @mparlette
              last edited by Oct 11, 2018, 6:27 PM

              @mparlette Also, also, thank you for using my module! I’m glad to see that others are finding use of it!
              Also also also, another failsafe is to just run commands through invoke-fogapi if the other functions aren’t working. It requires a bit more understanding of the uri paths and using the api. But all the other functions are really just helper functions that make it easier to call that one master function. It’s also the function that actually has some info in it if you run help invoke-fogapi -full

              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

              M 1 Reply Last reply Nov 16, 2018, 7:12 PM Reply Quote 0
              • M
                mparlette @JJ Fullmer
                last edited by Nov 16, 2018, 7:12 PM

                @JJ-Fullmer I love your PS module, great work! I am still hammering away on things. and I will let you know if I run across anything else like this. I have been able to make a neat script in less than 200 lines that does a lot based off of a CSV input file.

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

                249

                Online

                12.0k

                Users

                17.3k

                Topics

                155.2k

                Posts
                Copyright © 2012-2024 FOG Project