copying nagios users from one server to another(s)
Posted: Mon Mar 30, 2015 8:14 am
Hello All:
I have one nagios XI instance (2014R2.0) that has a number of users that I want to set up on multiple (4) other nagios XI servers (same revision).
Clicking on the application's add user screen for every user (60) in each instance isn't a workable mechanism and it is a great opportunity to generate errors.
I don't see any way to do this bulk transfer using normal nagios xi tools.
The discussion at:
http://support.nagios.com/forum/viewtop ... ebfb#p9912
sort of hints at a tool that could automate this, but it doesn't seem that was completed/released.
So I am planning on doing this at the postgres level. To make matters more interesting, some of the users already have accounts on the other XI instances.
Here is what I am planning, dump the user entries using:
SELECT 'INSERT INTO xi_users (user_id,username,password,name,email,backend_ticket,enabled) VALUES ('||user_id + 100||','''||username||''','''||password||''','''||name||''','''||email||''','''||backend_ticket||''','||enabled||');' FROM xi_users where username != 'nagiosadmin' order by user_id asc;
where the '+ 100' user_id offset is high enough that it won't cause duplicates id's on any of the instances. Then use grep to remove any duplicate usernames and feed the file to psql using:
cat xi_users | egrep -v 'existing_user1|existing_user2' | \
sudo -u postgres psql nagios_xi
then I will reset the sequence used for user_id using:
select setval('xi_users_user_id_seq', 192);
where 192 is the max user_id value present in the xi_users file.
Then I'll do the same with usermeta data using:
SELECT 'INSERT INTO xi_usermeta (usermeta_id,user_id,keyname,keyvalue,autoload) VALUES ('||usermeta_id + 1000||','||user_id + 100||','''||keyname||''','''||keyvalue||''','||autoload||');' FROM xi_usermeta where user_id != 18 order by usermeta_id asc;
where the user_id offset is the same as used for the users table and the '+ 1000' usermeta_id offset is again chosen to make sure there are no duplicates.
Then I will reset the sequence used for usermeta_id generation
select setval('xi_usermeta_usermeta_id_seq', max from dump)
Does anybody see any issues with this? Is there some referential integrity I am missing?
AFAICT from groveling the code the _id's aren't passed back by any of the get/set functions for user/usermeta data.
Also would it make more sense to not include the usermeta_id in the usermeta dump and just insert
INSERT INTO xi_usermeta (user_id,keyname,keyvalue,autoload) VALUES
(user_id + 100||','''||keyname||''','''||keyvalue||''','||autoload||');
and let the automatic sequence fill in the usermeta_id numbers? (I can't do that for the user_id since I have to coordinate the user_id between the user and usermeta tables.)
Any comments, evasions, questions or answers?
I have one nagios XI instance (2014R2.0) that has a number of users that I want to set up on multiple (4) other nagios XI servers (same revision).
Clicking on the application's add user screen for every user (60) in each instance isn't a workable mechanism and it is a great opportunity to generate errors.
I don't see any way to do this bulk transfer using normal nagios xi tools.
The discussion at:
http://support.nagios.com/forum/viewtop ... ebfb#p9912
sort of hints at a tool that could automate this, but it doesn't seem that was completed/released.
So I am planning on doing this at the postgres level. To make matters more interesting, some of the users already have accounts on the other XI instances.
Here is what I am planning, dump the user entries using:
SELECT 'INSERT INTO xi_users (user_id,username,password,name,email,backend_ticket,enabled) VALUES ('||user_id + 100||','''||username||''','''||password||''','''||name||''','''||email||''','''||backend_ticket||''','||enabled||');' FROM xi_users where username != 'nagiosadmin' order by user_id asc;
where the '+ 100' user_id offset is high enough that it won't cause duplicates id's on any of the instances. Then use grep to remove any duplicate usernames and feed the file to psql using:
cat xi_users | egrep -v 'existing_user1|existing_user2' | \
sudo -u postgres psql nagios_xi
then I will reset the sequence used for user_id using:
select setval('xi_users_user_id_seq', 192);
where 192 is the max user_id value present in the xi_users file.
Then I'll do the same with usermeta data using:
SELECT 'INSERT INTO xi_usermeta (usermeta_id,user_id,keyname,keyvalue,autoload) VALUES ('||usermeta_id + 1000||','||user_id + 100||','''||keyname||''','''||keyvalue||''','||autoload||');' FROM xi_usermeta where user_id != 18 order by usermeta_id asc;
where the user_id offset is the same as used for the users table and the '+ 1000' usermeta_id offset is again chosen to make sure there are no duplicates.
Then I will reset the sequence used for usermeta_id generation
select setval('xi_usermeta_usermeta_id_seq', max from dump)
Does anybody see any issues with this? Is there some referential integrity I am missing?
AFAICT from groveling the code the _id's aren't passed back by any of the get/set functions for user/usermeta data.
Also would it make more sense to not include the usermeta_id in the usermeta dump and just insert
INSERT INTO xi_usermeta (user_id,keyname,keyvalue,autoload) VALUES
(user_id + 100||','''||keyname||''','''||keyvalue||''','||autoload||');
and let the automatic sequence fill in the usermeta_id numbers? (I can't do that for the user_id since I have to coordinate the user_id between the user and usermeta tables.)
Any comments, evasions, questions or answers?