Permalink
Browse files

Minor coloration for Migrator Restore

  • Loading branch information...
NEMS Linux
NEMS Linux committed Feb 5, 2019
1 parent ad50380 commit faa08e9cd8decd7756f681cdae7d341f00ff6979
Showing with 23 additions and 19 deletions.
  1. +14 −14 data/nconf-import.sh
  2. +9 −5 data/reconcile-nagios.sh
@@ -28,22 +28,22 @@ confdest=$2 # Importing from DESTINATION because we already imported the backup

echo "Importing Nagios Configs to NEMS NConf..."
# 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"
printf -- "\e[37mImporting:\e[97m timeperiod\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c timeperiod -f $confdest/global/timeperiods.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m misccommand\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c misccommand -f $confdest/global/misccommands.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"
printf -- "\e[37mImporting:\e[97m checkcommand\033[0m\n" && /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"
echo "Importing: host" && /var/www/nconf/bin/add_items_from_nagios.pl -c host -f $confdest/Default_collector/hosts.cfg 2>&1 | grep -E "ERROR"
echo "Importing: hostgroup" && /var/www/nconf/bin/add_items_from_nagios.pl -c hostgroup -f $confdest/Default_collector/hostgroups.cfg 2>&1 | grep -E "ERROR"
echo "Importing: host-dependency" && /var/www/nconf/bin/add_items_from_nagios.pl -c host-dependency -f $confdest/Default_collector/host_dependencies.cfg 2>&1 | grep -E "ERROR"
echo "Importing: service-template" && /var/www/nconf/bin/add_items_from_nagios.pl -c service-template -f $confdest/global/service_templates.cfg 2>&1 | grep -E "ERROR"
echo "Importing: service" && /var/www/nconf/bin/add_items_from_nagios.pl -c service -f $confdest/Default_collector/services.cfg 2>&1 | grep -E "ERROR"
echo "Importing: advanced-service" && /var/www/nconf/bin/add_items_from_nagios.pl -c advanced-service -f /tmp/reconcile-advanced-services.cfg 2>&1 | grep -E "ERROR" && rm /tmp/reconcile-advanced-services.cfg
echo "Importing: servicegroup" && /var/www/nconf/bin/add_items_from_nagios.pl -c servicegroup -f $confdest/Default_collector/servicegroups.cfg 2>&1 | grep -E "ERROR"
echo "Importing: service-dependency" && /var/www/nconf/bin/add_items_from_nagios.pl -c service-dependency -f $confdest/Default_collector/service_dependencies.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m contact\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c contact -f $confdest/global/contacts.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m contactgroup\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c contactgroup -f $confdest/global/contactgroups.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m host-template\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c host-template -f $confdest/global/host_templates.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m host\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c host -f $confdest/Default_collector/hosts.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m hostgroup\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c hostgroup -f $confdest/Default_collector/hostgroups.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m host-dependency\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c host-dependency -f $confdest/Default_collector/host_dependencies.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m service-template\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c service-template -f $confdest/global/service_templates.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m service\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c service -f $confdest/Default_collector/services.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m advanced-service\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c advanced-service -f /tmp/reconcile-advanced-services.cfg 2>&1 | grep -E "ERROR" && rm /tmp/reconcile-advanced-services.cfg
printf -- "\e[37mImporting:\e[97m servicegroup\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c servicegroup -f $confdest/Default_collector/servicegroups.cfg 2>&1 | grep -E "ERROR"
printf -- "\e[37mImporting:\e[97m service-dependency\033[0m\n" && /var/www/nconf/bin/add_items_from_nagios.pl -c service-dependency -f $confdest/Default_collector/service_dependencies.cfg 2>&1 | grep -E "ERROR"
echo "Done."

@@ -1,5 +1,8 @@
#!/usr/bin/php
<?php
require_once('/usr/local/share/nems/nems-scripts/inc/terminal-colors.php');
$colors = new Colors();
$ver = $argv[1];
$confsrc = $argv[2];
$confdest = $argv[3];
@@ -109,18 +112,19 @@ $confdest = $argv[3];
echo PHP_EOL;
function parsefile($filename,$file) {
global $colors;
$definitions = array(); // prevent error if file is empty
if (substr($filename,0,5) == '/tmp/') $filename_short = 'your backup of ';
if (substr($filename,0,6) == '/root/') $filename_short = 'NEMS\' Default of ';
$filename_short .= basename($filename);
echo "Scanning " . $filename_short . "... ";
echo 'Scanning ' . $colors->getColoredString($filename_short, "light_gray", "black") . '... ';
if (!file_exists($filename)) {
echo "File not found. Cannot load." . PHP_EOL;
echo $colors->getColoredString("File not found. Cannot load.", 'red', 'black') . PHP_EOL;
} else {
echo "File found. Loading...";
echo $colors->getColoredString("File found.", 'green', 'black') . ' ';
$data = file($filename);
if (is_array($data) && count($data) > 0) {
echo 'Found ' . count($data) . ' lines... Importing.';
echo 'Importing ' . count($data) . ' lines.';
$inside = 0;
$index = 0;
@@ -147,7 +151,7 @@ $confdest = $argv[3];
}
} else {
echo "Couldn't find any data. Aborting.";
echo $colors->getColoredString("Couldn't find any data. Aborting.", 'red', 'black');
}
echo PHP_EOL;
}

0 comments on commit faa08e9

Please sign in to comment.