Page 1 of 2
REST API - Delete Method not working for HostGroup
Posted: Sat Oct 05, 2019 1:07 am
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
Re: REST API - Delete Method not working for HostGroup
Posted: Mon Oct 07, 2019 9:15 am
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.
Re: REST API - Delete Method not working for HostGroup
Posted: Tue Oct 08, 2019 6:11 pm
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.
Re: REST API - Delete Method not working for HostGroup
Posted: Wed Oct 09, 2019 1:06 pm
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.
Re: REST API - Delete Method not working for HostGroup
Posted: Wed Oct 09, 2019 1:54 pm
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
Re: REST API - Delete Method not working for HostGroup
Posted: Wed Oct 09, 2019 3:57 pm
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.
Re: REST API - Delete Method not working for HostGroup
Posted: Wed Oct 09, 2019 4:25 pm
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?
Re: REST API - Delete Method not working for HostGroup
Posted: Thu Oct 10, 2019 10:11 am
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
Re: REST API - Delete Method not working for HostGroup
Posted: Thu Oct 10, 2019 10:33 am
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.
Re: REST API - Delete Method not working for HostGroup
Posted: Thu Oct 10, 2019 10:38 am
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