Page 1 of 1

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

Posted: Fri Apr 01, 2016 2:31 pm
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.

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

Posted: Fri Apr 01, 2016 4:01 pm
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 $?

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

Posted: Fri Apr 01, 2016 6:34 pm
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

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

Posted: Mon Apr 04, 2016 9:24 am
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

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

Posted: Mon Apr 04, 2016 11:30 am
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.

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

Posted: Mon Apr 04, 2016 11:35 am
by lmiltchev
Great! Is it safe to lock this thread, and mark it as "resolved"?

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

Posted: Mon Apr 04, 2016 1:31 pm
by stf_792
yes please