is there a way to bulk change a password for WMI check?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
stf_792
Posts: 48
Joined: Fri Jul 17, 2015 12:55 pm

is there a way to bulk change a password for WMI check?

Post by stf_792 »

Hello,

We are relatively new to Nagios and Nagios Xi.

We recently encounter an issue that we are not sure how to correct. It is more specific to Nagios Xi than Nagios Core.

We deployed a number of hosts with WMI checks using our Template. After deployment we noticed that we mistyped a password, so all WMI checks are failing. This was in test environment, and we could easily reset everything. But in production environment we will do periodic password change, so we need to have a process in place to address it.

In Nagios we could bulk edit config files, but how do you do it in Nagios Xi that stores everything in database?

What we tried was going to "Bulk Modifications" in CCM and tried to changed $ARG2$ with new password, while selecting affected services. But we end up with configuration that removed everything but updated $ARG2$.

Do we have to do it by each Service copying all $ARG$ or there is other way we not aware of?

Thank you

Steve.
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: is there a way to bulk change a password for WMI check?

Post by gormank »

One way is to go into the services dir, grep the password, and copy all the files with the password to the import dir. Then go to the import dir, search and replace the password in all the files, and finally run the reconfigure script or Apply Configuration in the GUI.

Here's a crappy search_n_replace script I wrote a million years ago...

search_n_replace.sh old new *

Code: Select all

cat search_n_replace.sh
#!/bin/sh

S_TEXT=$1
R_TEXT=$2
shift 2
FILES=$@
OLD=.org

##############################################################
if ! [ $# -gt 0 ]
then
  echo Usage: $0 \<text_to_replace\> \<replacement_text\> \<[path]/file_name\> 
  echo Example: $0 SMS_TYP SMP_TYP /global/views/all/file.vie
  exit 1
fi
##############################################################
# make sure we are root

if [ `whoami` != root ]
then
  echo You must run this script as root
  exit 1
fi
##############################################################
for FNAME in $FILES
do
  cp -p  $FNAME $FNAME$OLD
  sed "s/$S_TEXT/$R_TEXT/g" $FNAME$OLD > $FNAME
  mv $FNAME$OLD /tmp
done

exit $?
Last edited by gormank on Fri Apr 01, 2016 6:34 pm, edited 1 time in total.
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: is there a way to bulk change a password for WMI check?

Post by gormank »

Or in shellspeak...

cd /usr/local/nagios/etc/services
grep <password> * | awk -F : '{print "cp " $1 " ../import/"}' | sh
cd ../import
search_n_replace.sh oldpw newpw *
cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.sh

For a general solution, look into /usr/local/nagios/etc/resource.cfg
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: is there a way to bulk change a password for WMI check?

Post by lmiltchev »

Thank you, gormank!
For a general solution, look into /usr/local/nagios/etc/resource.cfg
@ stf_792, if you set up your passwords in the "resource.cfg", you will have to change them in one place only, which would make your life easier. Review our documentation on understanding user macros here:

https://assets.nagios.com/downloads/nag ... Macros.pdf
Be sure to check out our Knowledgebase for helpful articles and solutions!
stf_792
Posts: 48
Joined: Fri Jul 17, 2015 12:55 pm

Re: is there a way to bulk change a password for WMI check?

Post by stf_792 »

Thank you.

I completely forgot about resource.cfg
That method is much preferred, as "Nagios Operators" will not be able to see privileged passwords, while still able to modify records.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: is there a way to bulk change a password for WMI check?

Post by lmiltchev »

Great! Is it safe to lock this thread, and mark it as "resolved"?
Be sure to check out our Knowledgebase for helpful articles and solutions!
stf_792
Posts: 48
Joined: Fri Jul 17, 2015 12:55 pm

Re: is there a way to bulk change a password for WMI check?

Post by stf_792 »

yes please
Locked