REST API stress behaviour

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
gomatze
Posts: 64
Joined: Mon Jan 09, 2017 12:33 am
Location: Duesseldorf, Germany

REST API stress behaviour

Post by gomatze »

Good Morning,

i have a question regarding the behaviour af the API functions when there is stress.
To be more precise heres an example:
I want to implement a routine in productive thin Clients to configure themselves in Nagios via REST Call when the main Application starts up.
Further i would like to make them delete themselves when the Host is shut down normally.

Now the concern is the following:
In our Environment we have something like 500 of these clients. Because of other Problems these Clients a sceduled to reboot each Sunday at the same time.
That means that they would delete themselves from nagios all at the same time to reconfigure themselves also all at the same time.
How would the REST API react to that...

Following that concern:
The Clients would have to apply the configuration in order to activate the monitoring. (we also install and reboot single clients)
How would the Api react to a bunch of requests which all come with an apply command nearly at the same instant???

And finally:
Is there a way to block the apply command from the API when someone is working on the core configuration?
We dont whant to have half completed changes applied when we are configuring something and out there in the production someone restarts any client..

Can you follow my concerns? Can you give some information an these cases?
HOMO SUM HUMANI NIHIL A ME ALIENUM PUTO
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: REST API stress behaviour

Post by cdienger »

I did a bit of testing and the requests to restart after applying config will get queued. So while having 500 clients request restart of the core service may technically work, the result will likely be a long wait time for all the add/stop/starts to occur. I would instead investigate the option of not restarting the service immediately after adding a new config and leave the restarting to specific hosts or to run periodically. For example, to create three new hosts but only apply after the third one, I used the commands:

curl -XPOST "https://XI/nagiosxi/api/v1/config/host? ... Y&pretty=1" -d "host_name=testapihost1&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=0" --insecure

curl -XPOST "https://XI/nagiosxi/api/v1/config/host? ... Y&pretty=1" -d "host_name=testapihost2&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=0" --insecure

curl -XPOST "https://XI/nagiosxi/api/v1/config/host? ... I&pretty=1" -d "host_name=testapihost3&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1" --insecure


applyconfig=0 will add the config but not apply(restart the service) it, whiel applyconfig=1 will add and apply.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
gomatze
Posts: 64
Joined: Mon Jan 09, 2017 12:33 am
Location: Duesseldorf, Germany

Re: REST API stress behaviour

Post by gomatze »

Thank you for that.
I think i would do it exactly that way.
But i would like to apply only if there where changes.
How can i determine if there where changes since the last apply command?
Is there something like a spool file on which i can test to determine recend API commands?
HOMO SUM HUMANI NIHIL A ME ALIENUM PUTO
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: REST API stress behaviour

Post by cdienger »

I'm not aware of any API call, but the way the CCM determines if a change needs to be applied is checking the last modified timestamps in the database versus the timestamps on the config files. To check the timestamps for example, something like the following would work:

echo "select last_modified from tbl_host order by last_modified DESC;" | mysql -uroot -pnagiosxi -Dnagiosql

and to find the timestamps on the hosts files:

ll /usr/local/nagios/etc/hosts
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
gomatze
Posts: 64
Joined: Mon Jan 09, 2017 12:33 am
Location: Duesseldorf, Germany

Re: REST API stress behaviour

Post by gomatze »

Ok i testet a bit and used the following SQL to determine when the last Change in configuration actually took place.
echo "select max(last_modified) from tbl_host;" | mysql -uroot -pnagiosxi -Dnagiosql

now, when i am doin the ll Thing on the host files i see many different timestamps.
Is there something more precise to determine when last time the configuration has been applied?

Maybe some database entry (and how to select it)?
HOMO SUM HUMANI NIHIL A ME ALIENUM PUTO
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: REST API stress behaviour

Post by scottwilkerson »

When you run an apply configuration, it only writes the file if the timestamp of the existing file is older than the timestamp on the server in the last_modified field.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
gomatze
Posts: 64
Joined: Mon Jan 09, 2017 12:33 am
Location: Duesseldorf, Germany

Re: REST API stress behaviour

Post by gomatze »

Ok, that makes sense.
I will come to a solution.

One more Thing i Need to know:
I would like the Clients to check if they are already configured in NagiosXI, but without requesting the whole list of Hosts from NagiosXI. Is there an API Call to get one single Hoststatus, or an error if the Host is not configured..?
HOMO SUM HUMANI NIHIL A ME ALIENUM PUTO
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: REST API stress behaviour

Post by scottwilkerson »

If you request the hoststatus and add the column with their hostname you would fine it like

Code: Select all

/nagiosxi/api/v1/objects/hoststatus?apikey=XXXXXXXXX&name=YOU-HOST
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked