Skip to content
Permalink
Browse files

Blow up checkcommands (Import custom commands in 1.5)

  • Loading branch information...
NEMS Linux
NEMS Linux committed Aug 23, 2019
1 parent 8138a6b commit 7fa2375ed96ef6e399acfcf5dd5fe6cf8e63cd17
Showing with 34 additions and 1 deletion.
  1. +17 −0 data/cfg-exploder.sh
  2. +17 −1 data/nconf-import.sh
@@ -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.'}');
}
}
?>
@@ -30,9 +30,25 @@ confdest=$2 # Importing from DESTINATION because we already imported the backup
# 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 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
# 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"
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
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"

0 comments on commit 7fa2375

Please sign in to comment.
You can’t perform that action at this time.