Bash Script to disable machines

ruf-u
(binh.au) #1

Hi,

We are trying to create a script that will disable certain octopus machines.

This is the script that we have come up with:

API_KEY=’###’
OCTO=‘http://server/octopus/api
NODE=‘nodeName’
NODEID=$(curl -s -H “X-Octopus-ApiKey: ${API_KEY}”
-X GET ${OCTO}/machines/all |
jq “.[] | select(.Endpoint.Host==”${NODE}") | .Id" -r)

curl -s -H “X-Octopus-ApiKey: ${API_KEY}”
-H “Accept:application/json”
-X PUT ${OCTO}/machines/${NODEID}
-d “{“Id”: “${NODEID}”, “Thumbprint”: “ABCD”, “Status”: “Disabled”}”

When this script run it return the error message :

"Errors": [ "An HTTPS address must be supplied for the machines's URI" ]

We don’t have https switched on.
Any idea where we are going wrong?

(Tom Williams) #3

Hi Binh,
Thanks for reaching out. That error coming from the Octopus Server indicates that the PUT request is invalid. specifically that the endpoint address must be specified.
The best practice for updating object via the API would be to query the object, like you are doing in the GET request, and then use the whole JSON object in the body of the PUT when doing the update. i.e. take the whole machine object from your query, update the required fields and then put the whole JSON object in the body for the PUT request.

I hope that helps, please let me know if you have further questions.

Kind regards,
Tom W

(binh.au) #4

Yep that’s sorted.
Thank you

(system) closed #6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.