Permalink
Browse files

Migrator progress for NEMS 1.5

  • Loading branch information...
NEMS Linux
NEMS Linux committed Jan 13, 2019
1 parent 46d0daa commit 314cdd31ea10c50b2937b7811977c439be62ea5b
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +0 Bytes (100%) data/1.5/mysql/NEMS-Clean/ibdata1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -30,7 +30,10 @@ confdest=$2 # Importing from DESTINATION because we already imported the backup
# Import Nagios configs into NConf's MySQL Database
echo "Importing: timeperiod" && /var/www/nconf/bin/add_items_from_nagios.pl -c timeperiod -f $confdest/global/timeperiods.cfg 2>&1 | grep -E "ERROR"
echo "Importing: misccommand" && /var/www/nconf/bin/add_items_from_nagios.pl -c misccommand -f $confdest/global/misccommands.cfg 2>&1 | grep -E "ERROR"
echo "Importing: checkcommand" && /var/www/nconf/bin/add_items_from_nagios.pl -c checkcommand -f $confdest/global/checkcommands.cfg 2>&1 | grep -E "ERROR"
# Do not import check commands in NEMS 1.5+ - these come from the database itself, otherwise arg variables (names, count) get lost since they are not part of nagios conf
if (( $(awk 'BEGIN {print ("'$ver'" < "'1.5'")}') )); then
echo "Importing: checkcommand" && /var/www/nconf/bin/add_items_from_nagios.pl -c checkcommand -f $confdest/global/checkcommands.cfg 2>&1 | grep -E "ERROR"
fi
echo "Importing: contact" && /var/www/nconf/bin/add_items_from_nagios.pl -c contact -f $confdest/global/contacts.cfg 2>&1 | grep -E "ERROR"
echo "Importing: contactgroup" && /var/www/nconf/bin/add_items_from_nagios.pl -c contactgroup -f $confdest/global/contactgroups.cfg 2>&1 | grep -E "ERROR"
echo "Importing: host-template" && /var/www/nconf/bin/add_items_from_nagios.pl -c host-template -f $confdest/global/host_templates.cfg 2>&1 | grep -E "ERROR"
@@ -37,7 +37,8 @@ $confdest = $argv[3];
foreach ($files as $file) {
$backup = '/tmp/nems_migrator_restore' . $confsrc . '/' . $file['file'];
if ($ver >= 1.5) {
$default = '/root/nems/nems-migrator/data/1.5/nconf/confdump/' . $file['file'];
// $default = '/root/nems/nems-migrator/data/1.5/nconf/confdump/' . $file['file'];
$default = '/root/nems/nems-migrator/data/1.5/nagios/conf/' . $file['file'];
} else if ($ver >= 1.4) {
$default = '/root/nems/nems-migrator/data/1.4/nagios/conf/' . $file['file'];
} else {
@@ -65,6 +66,7 @@ $confdest = $argv[3];
}
$newfile = '# ' . $file['file'] . PHP_EOL . '# This file was generated by NEMS-Migrator' . PHP_EOL . '# Visit https://nemslinux.com/ to learn more' . PHP_EOL . PHP_EOL;
$newfileEND = '';
foreach ($consolidation as $definition) {
$isChild = 0;
// Check if it has a parent
@@ -4,6 +4,9 @@ ver=$(/usr/local/bin/nems-info nemsver)
username=$(/usr/local/bin/nems-info username)
startpath=$(/bin/pwd)

# Get the email address as per initialized NEMS NConf - will use this to later update the imported contact to match
email=$(mysql -s -r -u nconf -pnagiosadmin nconf -e "SELECT attr_value FROM ConfigValues WHERE fk_id_attr=55;" | sed -n 1p)

# Backward compatible
if (( $(awk 'BEGIN {print ("'$ver'" >= "'1.4'")}') )); then
nagios=nagios
@@ -284,12 +287,31 @@ else
echo " your backup again. There's really no other way."
fi


# This may cause errors, but at least it gives them the old logs.
cp -Rfp /tmp/nems_migrator_restore/var/log/* /var/log

service mysql start
service $nagios start

# NEMS 1.5+
if (( $(awk 'BEGIN {print ("'$ver'" >= "'1.5'")}') )); then
cp -fr /root/nems/nems-migrator/data/1.5/nagios/etc/* /usr/local/nagios/etc/
/bin/sed -i -- 's/nemsadmin/'"$username"'/g' /usr/local/nagios/etc/cgi.cfg

# Remove nconf history, should it exist
mysql -u nconf -pnagiosadmin nconf -e "TRUNCATE History"

# Change contact info in NConf
if (( $(awk 'BEGIN {print ("'$ver'" >= "'1.5'")}') )); then
# Update user info (no need to import in 1.5
echo " Updating contact: $username"
mysql -t -u nconf -pnagiosadmin nconf -e "UPDATE ConfigValues SET attr_value='$username' WHERE fk_id_attr=47;"
mysql -t -u nconf -pnagiosadmin nconf -e "UPDATE ConfigValues SET attr_value='$email' WHERE fk_id_attr=55;"
fi
fi


echo ""
echo I hope everything worked okay for you.
echo Please let me know if you had any trouble.

0 comments on commit 314cdd3

Please sign in to comment.