Page 1 of 2
API Error Hosrtgroups - HTTP Error 414: Request Too Long
Posted: Fri Feb 25, 2022 5:09 am
by sgomeztd
Hi,
I'm implemeting an automated procedure to add host to Nagios and include them in hostgroups. While doing so I just arrive to a point where I have a hostgroups with 253 elements inside and when I try to run an API call to apend one more host to it I'm hitting an error.
This is the output of the call (I have edited the list of servers to put just 3 but there would be 253 servers FQDN on that memebers section.
Code: Select all
{
"hostgroup_review": {
"changed": false,
"connection": "close",
"content": "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>414 Request-URI Too Long</title>\n</head><body>\n<h1>Request-URI Too Long</h1>\n<p>The requested URL's length exceeds the capacity\nlimit for this server.<br />\n</p>\n</body></html>\n",
"content_length": "248",
"content_type": "text/html; charset=iso-8859-1",
"date": "Fri, 25 Feb 2022 09:53:36 GMT",
"elapsed": 0,
"failed": false,
"failed_when_result": false,
"msg": "Status code was 414 and not [200]: HTTP Error 414: Request-URI Too Long",
"redirected": false,
"server": "Apache/2.4.37 (Red Hat Enterprise Linux) OpenSSL/1.1.1k",
"status": 414,
"url": "https://nagios_url/nagiosxi/api/v1/config/hostgroup/W2K16?apikey=API_KEY&pretty=1&members=server1,server2,server3
Is there any kind of workarround for this limitation? Unfortunatelly the only way that seems to exist to append a new host to a hostgroup using the API is to pass the full list of memebrs so what I'm doing is retrieving the list, adding the new one and run a PUT call.
Code: Select all
https://NAGIOS_URL/nagiosxi/api/v1/config/hostgroup/HOSTGROUP_NAME?apikey=xi_api_key&pretty=1&members=servers1,server2,server3
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Mon Feb 28, 2022 4:18 pm
by pbroste
Hello
@sgomeztd
Thanks for reaching out, edit this file:
/etc/httpd/conf/httpd.conf
Add this:
Restart apache:
If the issue persists please grab the following so we can see what is going on:
Code: Select all
tar -czvf /tmp/results.tar.gz /etc/php.ini /etc/httpd/*log /var/log/httpd/ /var/log/message /etc/php*
Please send over the '/tmp/results.tar.gz' if the issue persists.
Thanks,
Perry
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Tue Mar 01, 2022 10:36 am
by sgomeztd
Hi,
I added that line directly at the end of file /etc/httpd/conf/httpd.conf, restarted apache and tested again but I'm still getting the same error. I have send you a PM with the tar file.
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Wed Mar 02, 2022 3:10 pm
by pbroste
Hello
@sgomeztd
Thanks for following up, want to increase the values in the php.ini:
Code: Select all
sed -i 's/post_max_size = 21M/post_max_size = 64M/g' /etc/php.ini
sed -i 's/upload_max_filesize = 20M/upload_max_filesize = 64M/g' /etc/php.ini
sed -i 's/max_file_uploads = 20/max_file_uploads = 64/g' /etc/php.ini
Verify:
Code: Select all
grep -Ei 'post_max_size|upload_max_size|Max_file_uploads' /etc/php.ini
You already have the 'max_input_vars set high enough so we should be okay there.
Restart the service by bouncing:
Please let us know how things look,
Perry
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Thu Mar 03, 2022 11:07 am
by sgomeztd
Hi,
I'm afraid those changed did not solved the issue. I have send you another PM with the same .tar extract in case it helps.
There is no other way to append members to a hostgroup?
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Fri Mar 04, 2022 3:04 pm
by pbroste
Hello
@sgomeztd
Spun-up my test VM on this one today to work on a possible solution. I was unable to find a way to get around the '414 error' code.
The other possible solution that you may want to implement for the time being until we do bump into a fix. By extracting and putting into a text list. I used this to convert from comma-separated to one column list:
Code: Select all
tr , '\n' < csvlist.txt > list.txt
Then took that over to the following curl command:
Code: Select all
for d in `cat list.txt` ; do curl -XPUT "https://xxx.xxx.xxx.xxx/nagiosxi/api/v1/config/hostgroup/Wxxxxx?apikey=oxxxxxxxx....xxxxxxxx...xxxA&members=$d&applyconfig=1" -k; done
This is only a suggestion; please test and make adjustments where necessary.
Perry
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Mon Mar 07, 2022 8:07 am
by sgomeztd
Hi,
That method do not work as the API for PUT config/hostgroup cannot append elements. On each loop of your for command, you are replacing the previuos element of the list for the current one in the loop but you end up with a hostgroup just containint the last element on the list.
It doesen't matther if you add the applyconfig to the API call or just run it a single time at the end of the loop. I have tested this quite a lot as this was the first way I tested adding elements into the hostgroup. Also, Nagios does not like doing 200 consecutive apply config.
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Thu Mar 10, 2022 1:34 pm
by pbroste
Hello
@sgomeztd
Thanks, getting back to me, will test this up to see what we can do on this one and follow up soon.
Thanks,
Perry
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Tue Mar 22, 2022 4:41 am
by sgomeztd
pbroste wrote:Hello
@sgomeztd
Thanks, getting back to me, will test this up to see what we can do on this one and follow up soon.
Thanks,
Perry
Did you managed to test this a bit more? I tried increasing the LimitRequestFieldSize on apache but that didn't solve the issue either. I find it kind of strange that nobody else have faced this issue before because of how the API works.
I'm starting to thing about ditching the API and go back to the old way using .cfg files.
Re: API Error Hosrtgroups - HTTP Error 414: Request Too Lon
Posted: Fri Mar 25, 2022 12:07 pm
by pbroste
Hello
@sgomeztd
Thanks for holding on here, it took a while to get back and test this. While on my Test VM I also noticed that the api command when looping through the text message would result in inconsistent results. Exactly what you stated previously.
Today in my test I ran the api calling from a list of 241 members in one comma-delimited line *(please see example below:
Code: Select all
for d in `cat new\ 8.txt` ; do curl -XPOST "https://myhostaddresshere/nagiosxi/api/v1/config/hostgroup?apikey=myapikeyhere&pretty=1" -d "hostgroup_name=testapihostgroup&alias=HostGroup&members=$d&applyconfig=1&force=1" -k && echo $d && sleep 10 && curl -XPOST "https://myhostapikeyhere/nagiosxi/api/v1/system/applyconfig?apikey=myapikeyhere" -k; done;
As you can see from the command I echo the member's list so you can visualize it:
{
"success": "Added testapihostgroup to the system. Config applied, Nagios Core was restarted."
}
your,hostgroup,list,here,with,all,members,241,of,them,here"
{"success":"Apply config command has been sent to the backend.","command_id":3827}
The results on this test were consistent, functioned, and completed without failure.
Here is a couple of screenshots: attached via email.
241hostgroups.png
hostgrouplist.png
Thanks,
Perry