I have multiple Nagios servers with the same user on each setup to run reports
But because I cannot specify an API key to use - it means I have to track the API key of each server separately
Is there a way of putting the same API key for this user into the database on all of my Nagios boxes?
Assigning an API key to a user
Re: Assigning an API key to a user
Hello @optionstechnology
Thanks for reaching out, there are possibly other ways or workarounds but this is what I tested on my test VM's:
Logged in to the Nagios XI web console on Server A to copy the api key fH4CoSSE05J7cPqnIhiWVbqceLuKFsaX92YJPhFA9vIC9EFVWdS3p9kAoeJFYRlN to distribute.
On Server B (receiving the updated distributed api key):
Verified the original key is found on Server B before making the update:
Updating the api key on Server B:
Verified that the key was written to server B:
Writing the database:
Restart services:
Make sure that you have backed up your server instance before making any changes.
Thanks,
Perry
Thanks for reaching out, there are possibly other ways or workarounds but this is what I tested on my test VM's:
Logged in to the Nagios XI web console on Server A to copy the api key fH4CoSSE05J7cPqnIhiWVbqceLuKFsaX92YJPhFA9vIC9EFVWdS3p9kAoeJFYRlN to distribute.
On Server B (receiving the updated distributed api key):
Code: Select all
mysqldump -uroot -pnagiosxi nagiosxi > nagiosxi.sqlCode: Select all
grep -o 'rVFc7FAkabP8dcqhhj62VBeG5n5E8pP2ZC9MUsbdBr9eDWpfs9qVABdfIO0iiRri' nagiosxi.sqlCode: Select all
sed -i 's/rVFc7FAkabP8dcqhhj62VBeG5n5E8pP2ZC9MUsbdBr9eDWpfs9qVABdfIO0iiRri/fH4CoSSE05J7cPqnIhiWVbqceLuKFsaX92YJPhFA9vIC9EFVWdS3p9kAoeJFYRlN/g' nagiosxi.sqlCode: Select all
grep -o 'fH4CoSSE05J7cPqnIhiWVbqceLuKFsaX92YJPhFA9vIC9EFVWdS3p9kAoeJFYRlN' nagiosxi.sqlCode: Select all
mysql -uroot -pnagiosxi nagiosxi < nagiosxi.sqlCode: Select all
systemctl restart nagios mysqld httpdThanks,
Perry
-
optionstechnology
- Posts: 234
- Joined: Thu Nov 17, 2016 11:26 am
Re: Assigning an API key to a user
Hey this is great - one minor tweek - is it possible to do by username instead of find/replacing the actual token string?
Reason I ask is ill be automating it on newly built servers so I don't want to have to manually go in every time and get the current API key just to replace it
Reason I ask is ill be automating it on newly built servers so I don't want to have to manually go in every time and get the current API key just to replace it
Re: Assigning an API key to a user
Hello @optionstechnology
Thanks for following up, technically this is going outside of the spectrum of our support and into customizing.
Ran through some trials but the results are not what I expect and want to toss this out to the forum for a possible workaround. Here is what I tried but please bear in mind that the results did not work as intended. Either tweaks are needed or someone might have an idea that goes off in a different direction.
Tried the following and please make any adjustments:
or
The idea to grep for the 'username' and six comma-delimited data placement indexes gets us over to the "apikey". Where you could then use sed to find, using a regular expression to /replace.
Thanks,
Perry
Thanks for following up, technically this is going outside of the spectrum of our support and into customizing.
Ran through some trials but the results are not what I expect and want to toss this out to the forum for a possible workaround. Here is what I tried but please bear in mind that the results did not work as intended. Either tweaks are needed or someone might have an idea that goes off in a different direction.
Tried the following and please make any adjustments:
Code: Select all
grep -i 'usernamehere' nagiosxidump.sql | awk -F "," '{print $6}'Code: Select all
grep -Ei 'usernamehere' nagiosxidump.sql | cut -d , -f 6Thanks,
Perry
-
optionstechnology
- Posts: 234
- Joined: Thu Nov 17, 2016 11:26 am
Re: Assigning an API key to a user
Just in case anyone is interested in doing this I achieved it with:
Then just apply config in nagios
Code: Select all
mysql -uroot -pnagiosxi nagiosxi -e "UPDATE xi_users SET api_key = 'bigapikeygoeshere' WHERE user_id=1;"Re: Assigning an API key to a user
Hello @optionstechnology
Excellent solution, and thanks for sharing. I will go ahead and lock this, please let us know if there is anything further.
Thanks,
Perry
Excellent solution, and thanks for sharing. I will go ahead and lock this, please let us know if there is anything further.
Thanks,
Perry