Code Monkey home page Code Monkey logo

kacesma's Introduction

KaceSMA

Build Status

A Powershell module for administering and interacting with a Quest Systems Management Appliance (SMA) via it's API interface.

To Install

Install-Module KaceSMA

Quickstart

  • Import the module
  • Authenticate to the appliance
  • Perform a request
PS> Import-Module KaceSma
PS> Connect-SmaServer -Server 'https://kace.example.com' -Org 'Default' -Credential (Get-Credential)
PS> Get-SmaServiceDeskTicket -Id 1

title       : I want to reset my password
created     : 2019-06-13 09:01:13
modified    : 2019-06-13 09:31:02
id          : 1
hd_queue_id : 10
sla_dates   : {}

FAQ

Visit the FAQ on the wiki

Questions or comments?


Join the community Slack channel (#Api)

kacesma's People

Contributors

artisanbytecrafter avatar artvandelay440 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kacesma's Issues

Failure to post new asset

Invoke-restMehtod @IRMSplat is failing with a 500 Internal Server error when using New-SMAAsset

Kace appliance logs say "PUT /api/asset/assets HTTP/1.1" 500 86 1311 1055 0

Referencing API documentation the method for creating a new asset is a POST to /api/asset/assets. Changed the method of $IRMSplat to POST and it works successfully.

Creating barcodes with assets

Having issues creating a new asset and a barcode with it. From the documentation barcodeData schema, it looks like the monitor asset has to be created before the barcode can be created:

asset_id required: Only valid when creating new barcode. Required, used to associate with a specific asset

If that's correct, it looks like we'll need another cmdlet like New-SmaAssetBarcode to follow up with. I've tried to use the New-SmaAsset cmdlet but a body for a barcode, shown below, and it does return successful, but I don't see any changes reflected in KACE.

Input:

> # Create monitor asset in KACE
        $Monitors.$hostname.Keys | select -first 1 | ForEach-Object {
            $mon = $Monitors.$hostname.$_

            $NewAsset = @{
                'Assets' = @(
                    @{
                        'name'            = '{0} {1}' -f $mon.ModelNumber, $owner
                        'asset_type_id'   = '10201'
                        'asset_type_name' = 'Monitors'
                        'field_10027'     = $mon.SerialNumber
                        'field_10033'     = $mon.ManufactureDate
                        'field_10026'     = @{
                            'id'            = $kaceComputer.id
                            'asset_type_id' = 5
                        }
                    }
                )
            }

            $asset = New-SmaAsset -Body $NewAsset
            if ($asset.result -eq 'Success') {
                '- Asset created in KACE. Asset ID: {0} Link: https://K1000/adminui/asset.php?ID={0}' -f $asset.IDs
            } else {
                '- Asset creation failed.'
            }

            # Barcodes
            $barcodeData = $mon.SerialNumber.Replace('-', '')[-7..-1] -join ''
            
            $newBarcode = @{
                'barcodes' = @(
                    @{
                        'barcode_id'          = $asset.IDs
                        'barcode_data'        = $barcodeData
                        'barcode_name'        = 'Monitor Serial Number'
                        'barcode_format'      = 'Code 128'
                        'scanned_geolocation' = 'UNKNOWN'
                        'scanned_method'      = 'UNKNOWN'
                    }
                )
            }

            '- creating barcode'
            $barcode = New-SmaAsset -Body $newBarcode
            $barcode; ''
        }

Output:

- Asset created in KACE. Asset ID: 919 Link: https://K1000/adminui/asset.php?ID=919

- creating barcode

Result  IDs
------  ---
Success {}

>

Thanks

Alex

It would be nice if authentication could be handled centrally, once per session.

I'm exploring the idea of a one-time authentication, per session, something akin to Connect-SmaServer -Server ... -Org ... -Credential ....

This would persist the login within the same session state, and discard it when finished or closed.

this would involve significant rework, but it's definitely worth exploring, as it could make the individual calls much cleaner and shorter.

Get-SmaArchiveAsset does not properly return archived assets

I can successfully retrieve the archival status of an asset with Get-SmaAsset, using -QueryParameters "?filtering=asset.archive eq completed,asset.id eq 1234", however, running Get-SmaArchiveAsset against the same AssetID returns a 500 error.

Working Endpoint:

"/api/asset/assets?filtering=asset.archive eq completed,asset.id eq 1234"

Not Working Endpoint:

"/api/asset/archived_devices/<AssetID>"

Steps to reproduce:

Error:

Get-SmaArchiveAsset -Server 'https://kace.example.com' -Credential (Get-Credential) -AssetID 1234

- Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.

Workaround using Get-SmaAsset with filter:

Get-SmaAsset -Server 'https://kace.example.com' -Credential (Get-Credential) -QueryParameters "?filtering=asset.archive eq completed,asset.id eq 1234"

+ Returns successfully
 

RFC - RE: Pipeline input. How should this be handled?

All exposed functions should accept pipeline input. In order to accomplish this the traditional Powershell way, objects in the pipeline should have the properties expected by the funtions being piped to, however the API returns objects one level higher than that. Changing this output would be a major breaking change, and should be considered very carefully.

There are two options:

1) Leave output alone and simply query one level deep before piping:

$query = Get-SmaMachineInventory .....
$Query.Machines | Set-SmaMachineInventory ....

Advantages:

  • No breaking change needed

Disadvantages:

  • Contrary to best practice in pipeline input
  • Would cause confusion for those expecting traditional pipeline behavior

2) Format output to remove top-level parameters Count and Warning, and only return results:

Get-SmaMachineInventory .... | Set-SmaMachinenventory ....

Advantages:

  • Best practice in handling pipeline input
  • Could take advantage of pipeline parallelism to improve performance on longer queries

Disadvantages:

  • Major breaking change. Any scripts that use syntax like $Query.Machines to retrieve objects would need to be re-written to simply use $Query. This would apply to all endpoints.
  • Note Properties Count and Warnings would not be returned with the request, although traditional count methods would still be easily usable. (.count , | Measure-Object, etc.)

I'm leaning towards a phased approach, i.e. enabling pipeline input like in option 1, so as not to break anything, then at some point in the future, simply making the switch to v2 after a warning has been out for a while.

Set-SmaAssetAsArchinved does not return successfully

fixed in 1.0.6

API docs bug resulted in no body credential being presented. This has been verified and resolved.

Set-SmaAssetAsArchived now requires a -Body parameter in the following format:

$Body = @{
        archiveReason = "Testing Archival via API"
}

Updating Asset custom fields

I want to update the owner field on an asset.
When I run Get-SMAAsset I get this:

id              : 7341
asset_type_id   : 10202
name            : Polycom VVX 411 (PoE)
asset_data_id   : 351
owner_id        : 11450
modified        : 2021-05-04 15:54:43
created         : 2021-03-30 13:36:06
mapped_id       : 0
asset_class_id  : 0
archive         : 
asset_status_id : 493
field_10283     : @{id=11450; user_name=user; [email protected]; full_name=User}
field_10284     : Spare
field_10278     : Polycom VVX 411 (PoE)
field_10279     : 4001
field_10280     : 64167fd2854f
field_10281     : Department
field_10285     : 
field_10286     : 
field_10287     : 
asset_type_name : VOIP Phones
location        : @{id=7274; asset_type_id=1; name=Spare; owner_id=0; asset_class_id=11011; asset_status_id=0}
Associations    : {}

The field I need to update is field_10283.
I've tried creating a hash table with the info to be updated but I still get errors.

Powershell shows:

At U:\Documents\WindowsPowerShell\Modules\KaceSMA\2.0.1\private\New-ApiPUTRequest.ps1:29 char:9
         Invoke-RestMethod @IRMSplat
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

KACE Server logs show:

[Tue May 04 15:52:19.012997 2021] [proxy_fcgi:error] [pid 34407:tid 34382394112] [client 127.0.0.1:20597] AH01071: Got error 'PHP message: [2021-05-04 15:52:19 -0400] PHP Warning: preg_match() expects parameter 2 to be string, array given in /kbox/kboxwww/include/RowValues.class.php on line 337\nPHP message: [2021-05-04 15:52:19 -0400] PHP Warning: strcasecmp() expects parameter 1 to be string, array given in /kbox/kboxwww/include/RowValues.class.php on line 337\n'

Any help on how to format the code to update this field is appreciated.

Unable to create tickets - Error 400 Bad Request

Hi,

I have tried every way i can think of to get this to work. I am authenitcating with my KACE1000 Server, and i can get tickets and other information no problem. I have checked permissions and the user i am autheticating with has permissions to create tickets. but no matter what i do, if i try and submit your example ticket i get 400 bad request. Even if i try and use the API Directly.

Any idea what is going on? My KACE Server is at the latest version, V11...

New-SmaServiceDeskTicket -Body $NewTicket
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Program Files\WindowsPowerShell\Modules\KaceSMA\2.0.1\private\New-ApiPOSTRequest.ps1:36 char:9
Invoke-RestMethod @IRMSplat
~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

This is the error i get.

this is the object i am passing it:

$NewTicket = @{
'Tickets' = @(
@{
'hd_queue_id' = 1
'title' = "ApiTest"
'custom_2' = "Site"
'due_date' = "2021-03-17 00:00:00"
'submitter' = 1947
'status' = 1
'owner' = 1947
"category" = 2
}
)
}

Get-SmaAsset result size & Set-SmaAssetAsArchived input options

I am looking to retire assets en masse providing only a computer name. I am able to get the Asset ID to feed into Set-SmaAssetAsArchived with Get-SmaAsset and some pipelines, but the result size is only 50 items at a time (all the same every time as well). Couple questions:

  1. Is there a way to feed Set-SmaAssetAsArchived a computer name instead of an Asset ID?
  2. If not, how can I look through all of our active assets (~500 items)?

Thanks in advance!

POST /api/script returns 'no route found'

This might be a documentation bug or a problem with the endpoint itself. This should not be exposed until it has been fixed upstream or the docs are updated with the correct endpoint.

Better error detail for Connect-Server

The canned error message from Connect-Server does not give any information that could be useful for troubleshooting. If I was put in the wrong org, I should receive:
(500) Internal Server Error

If I mess up my credentials, I should receive:
(401) Unauthorized

Please consider changing the error message to give the server response or putting it in Write-Verbose. This will help users better troubleshoot the problem.

SAML Authentication Support

With 10.x now supporting SAML Authentication, it would be great if this module supported servers where SSO was utilized for logins.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.