Skip to content

Commit

Permalink
Blow up checkcommands (Import custom commands in 1.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
NEMS Linux committed Aug 23, 2019
1 parent 8138a6b commit 7fa2375
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions data/cfg-exploder.sh
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php
// blow up checkcommands
// This simply breaks a checkcommandsfile into separate files for each check_command. That way the importer can fail on one but will still continue to import the rest.
if (!isset($argv) || !isset($argv[1]) || !isset($argv[2])) {
exit('Usage: ' . $argv[0] . ' /path/checkcommands.cfg /tmp/path' . PHP_EOL);
}
if (!file_exists($argv[2])) mkdir($argv[2]);
$data = file_get_contents($argv[1]);
$dataArr = explode('}', $data);
$v=0;
if (is_array($dataArr)) {
foreach ($dataArr as $block) {
file_put_contents($argv[2].'/'.$v++.'.cfg',$block.PHP_EOL.'}');
}
}
?>
18 changes: 17 additions & 1 deletion data/nconf-import.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,9 +30,25 @@ confdest=$2 # Importing from DESTINATION because we already imported the backup
# Import Nagios configs into NConf's MySQL Database # Import Nagios configs into NConf's MySQL Database
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 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" 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 # Do not import check commands directly from the cfg 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
# Instead, we'll need to break apart the NEMS 1.5+ config so we can try one at a time
if (( $(awk 'BEGIN {print ("'$ver'" < "'1.5'")}') )); then if (( $(awk 'BEGIN {print ("'$ver'" < "'1.5'")}') )); then
# Legacy support (NEMS 1.4.1 and before)
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" 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"
else
# NEMS 1.5+
# Blow up the config file
tmpdir=`mktemp -d -p /tmp/`
/root/nems/nems-migrator/data/cfg-exploder.sh $confdest/global/checkcommands.cfg $tmpdir
cd $tmpdir
printf -- "\e[37mImporting:\e[97m checkcommand\033[0m\n"
echo ""
echo "NOTE: Don't worry if you see several checkcommands aborted."
echo " This simply means they are already in the database."
echo ""
sleep 2
for f in *.cfg; do /var/www/nconf/bin/add_items_from_nagios.pl -c checkcommand -f $f 2>&1 | grep -E "ERROR"; done
rm -rf $tmpdir
fi fi
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 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 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"
Expand Down

0 comments on commit 7fa2375

Please sign in to comment.