REST API - Delete Method not working for HostGroup

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

REST API - Delete Method not working for HostGroup

Post by scomdco »

Nagios Version: 5.5.7

When i make this call through powershell, i get a HTTP 200 response from Nagios stating that it's removing the hostgroup, but the hostgroup is still there. I've toggled the applyconfig to see if that would change this, like forcing me to do a apply config but that did not change the result. Please help!

To note i have a delete method call for hosts coming from the same computer that is working successfully. Also in the Audit Log i do not see this call ever logged, but i do see the other one get logged.

The $AutoScalingGroup variable is inputted by the user who runs the script using the Read-Host command, which has the hostgroups name as a System.String (same type that is of the values in the other script i mentioned that works successfully)

Code: Select all

Invoke-WebRequest -Method Delete -Uri "https://nagios.prod02.aws.local/nagiosxi/api/v1/config/hostgroup?apikey=XXXX&pretty=1&hostgroup_name=$AutoScalingGroup&alias=HostGroup&applyconfig=1"
Here's the verbose response (I have the rest of the address chopped off for the sake of the API key. it ends with "with 0-byte payload"
DeleteMethod.png
Here's the output from the call when using Invoke-WebRequest,

Code: Select all

Removing BRIDGE_2019.14.6720.3671 From Nagios


StatusCode        : 200
StatusDescription : OK
Content           : null
                    
RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Orgin: *
                    Access-Control-Allow-Methods: *
                    Keep-Alive: timeout=5, max=100
                    Connection: Keep-Alive
                    Content-Length: 5
                    Content-Type: application/json
                    Date: Sat, 0...
Forms             : {}
Headers           : {[Access-Control-Allow-Orgin, *], [Access-Control-Allow-Methods, *], [Keep-Alive, timeout=5, max=100], [Connection, Keep-Alive]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 5
Here's the output from the call when using Invoke-RestMethod,

Code: Select all

Removing BRIDGE_2019.14.6720.3671 From Nagios
null
You do not have the required permissions to view the files attached to this post.
Last edited by scomdco on Wed Oct 09, 2019 1:59 pm, edited 1 time in total.
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: REST API - Delete Method not working for HostGroup

Post by mbellerue »

Could you post, or PM me your Powershell script? Also, if you could run through the script and try to remove a host group, then get a system profile from Nagios and PM that to me as well, that will help.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

Re: REST API - Delete Method not working for HostGroup

Post by scomdco »

Just seeing this, i'll collect the info and send it to you shortly!

EDIT: i sent the PM with the files now.
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: REST API - Delete Method not working for HostGroup

Post by mbellerue »

Your script looks great, I only changed one thing. What you had looked right, and I'm going to check to see if it's supposed to work that way, but line 15 I changed the Invoke-WebRequest inside the foreach loop to be this.

Code: Select all

Invoke-WebRequest -Method Delete -Uri "http://nagios.prod02.aws.local/nagiosxi/api/v1/config/host/${instance}?apikey=XXXX&pretty=1&applyconfig=0"
Let me know if this works on your side as well.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

Re: REST API - Delete Method not working for HostGroup

Post by scomdco »

Thanks!

Did you happen to mean to suggest to do this with the hostgroup instead? Because the issue i'm having is only with the hostgroup API call on line 19.

When i run the command with the host name put in the suggested place in the command the output looks to prefer the placement i have in the script currently on line 15

i ran it two ways:

Code: Select all

Invoke-WebRequest -Method Delete -Uri "https://nagios.prod02.aws.local/nagiosxi/api/v1/config/host/POSTALA-95B2CB?apikey=XXXX&pretty=1&applyconfig=0"

Code: Select all

Invoke-WebRequest -Method Delete -Uri "https://nagios.prod02.aws.local/nagiosxi/api/v1/config/host/{POSTALA-95B2CB}?apikey=XXXX&pretty=1&applyconfig=0"
Here's the output:

Code: Select all

StatusCode        : 200
StatusDescription : OK
Content           : {
                       [b] "error": "Missing required variables",
                        "missing": [
                            "host_name"[/b]
                        ]
                    }
                    
RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Orgin: *
                    Access-Control-Allow-Methods: *
                    Keep-Alive: timeout=5, max=100
                    Connection: Keep-Alive
                    Content-Length: 90
                    Content-Type: application/json
                    Date: Wed, ...
Forms             : {}
Headers           : {[Access-Control-Allow-Orgin, *], [Access-Control-Allow-Methods, *], [Keep-Alive, timeout=5, max=100], [Connection, Keep-Alive]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 90
Here's the code as it's currently configured on Line 15: the way you see the host_name value is what the value looks like when entered from the $instance variable

Code: Select all

Invoke-WebRequest -Method Delete -Uri "https://nagios.prod02.aws.local/nagiosxi/api/v1/config/host?apikey=XXXX&pretty=1&host_name=POSTALA-95B2CB&applyconfig=0"
Here's the output:

Code: Select all

StatusCode        : 200
StatusDescription : OK
Content           : {
                        "success": "Removed POSTALA-95B2CB from the system. Config imported but not yet applied."
                    }
                    
RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Orgin: *
                    Access-Control-Allow-Methods: *
                    Keep-Alive: timeout=5, max=100
                    Connection: Keep-Alive
                    Content-Length: 98
                    Content-Type: application/json
                    Date: Wed, ...
Forms             : {}
Headers           : {[Access-Control-Allow-Orgin, *], [Access-Control-Allow-Methods, *], [Keep-Alive, timeout=5, max=100], [Connection, Keep-Alive]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 98
i ran it with the hostgroup API in case that's what you meant and that didn't work either. It's still the same output as i reported originally,

i ran the code two ways:

Code: Select all

Invoke-WebRequest -Method Delete -Uri "https://nagios.prod02.aws.local/nagiosxi/api/v1/config/hostgroup/SWSIM_2019.15.6954.9533?apikey=XXXX&pretty=1&alias=HostGroup&applyconfig=0"

Code: Select all

Invoke-WebRequest -Method Delete -Uri "https://nagios.prod02.aws.local/nagiosxi/api/v1/config/hostgroup/{SWSIM_2019.15.6954.9533}?apikey=XXXX&pretty=1&alias=HostGroup&applyconfig=0"
Here's the output:

Code: Select all

StatusCode        : 200
StatusDescription : OK
Content           : null
                    
RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Orgin: *
                    Access-Control-Allow-Methods: *
                    Content-Length: 5
                    Content-Type: application/json
                    Date: Wed, 09 Oct 2019 18:45:48 GMT
                    Server: Apache/2.4.6 (CentOS) O...
Forms             : {}
Headers           : {[Access-Control-Allow-Orgin, *], [Access-Control-Allow-Methods, *], [Content-Length, 5], [Content-Type, application/json]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 5
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: REST API - Delete Method not working for HostGroup

Post by mbellerue »

My apologies, I misread your post. When I ran the script, it had issues removing the hosts, but successfully removed the host group. What version of Powershell are you running?

Code: Select all

PS C:\> $PSVersionTable

Name                           Value                                                                                                         
----                           -----                                                                                                         
PSVersion                      5.1.14393.3053                                                                                                
PSEdition                      Desktop                                                                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                       
BuildVersion                   10.0.14393.3053                                                                                               
CLRVersion                     4.0.30319.42000                                                                                               
WSManStackVersion              3.0                                                                                                           
PSRemotingProtocolVersion      2.3                                                                                                           
SerializationVersion           1.1.0.1
Can you show me the last few entries in /usr/local/nagiosxi/var/load_url.log after you try to run the Powershell script.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

Re: REST API - Delete Method not working for HostGroup

Post by scomdco »

No problem! I appreciate you looking into my post regardless,

Here's my current powershell version:

Code: Select all

PS C:\Scripts> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14409.1005
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1005
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
It looks like the file hasn't had data logged in it since last year,
load_url.png
Here's what it logged last:

Code: Select all

CURL ERROR
 TIME: 2018-11-16T21:14:16+00:00
Array
(
    [url] => https://api.nagios.com/versioncheck/
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 15.00112
    [namelookup_time] => 0.004115
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [primary_ip] => 50.116.21.73 - [b]IP resolves to newvs1.nagios.com[/b]
    [primary_port] => 443
    [local_ip] => 
    [local_port] => 0
    [redirect_url] => 
)

URL:
 https://api.nagios.com/versioncheck/?product=nagiosxi&version=5.5.7&build=1542046651&stableonly=1&output=xml&met=1&k5=ba4ef84789c97177eb507b69cd0ba0ca 
 OPTIONS: 
Array
(
    [return_info] => 1
    [method] => post
    [timeout] => 15
)

END LOGENTRY
I loaded the url in my browser and i see it's possibly related to a check or something similar that would let us know if there is a newer version? Is this correct?
You do not have the required permissions to view the files attached to this post.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: REST API - Delete Method not working for HostGroup

Post by scottwilkerson »

Sorry about leading you astray, the DELETE methods were fixed in XI 5.6.6 I see you are running 5.5.7
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
scomdco
Posts: 45
Joined: Fri Oct 04, 2019 3:18 pm

Re: REST API - Delete Method not working for HostGroup

Post by scomdco »

No problem, i still appreciate the insight!

Are there any issues to note when upgrading versions, specifically from 5.5.* to 5.6.*? If not great, but if there's documentation on this please provide me a link to review.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: REST API - Delete Method not working for HostGroup

Post by scottwilkerson »

scomdco wrote:No problem, i still appreciate the insight!

Are there any issues to note when upgrading versions, specifically from 5.5.* to 5.6.*? If not great, but if there's documentation on this please provide me a link to review.
Nope, should be straight forward
https://assets.nagios.com/downloads/nag ... ctions.pdf
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked