#!/usr/bin/env php . * * @package LibreNMS * @link http://librenms.org * @copyright 2017 Neil Lathwood * @author Neil Lathwood */ $init_modules = array(); require realpath(__DIR__ . '/..') . '/includes/init.php'; $options = getopt('h:'); $hostname = $options['h'] ?: ''; if (empty($hostname)) { echo "*********************************************************************\n"; echo "We highly suggest that you back up your rrd files before running this\n"; echo "*********************************************************************\n"; echo "-h Device to process the rrd file for\n"; echo "\n"; exit; } if ($hostname !== 'all') { $hostname = !ctype_digit($hostname) ? $hostname : gethostbyid($hostname); } if (empty($hostname)) { echo "Invalid hostname or device id specified\n"; exit; } $step = $config['rrd']['step']; $heartbeat = $config['rrd']['heartbeat']; $rrd_path = $config['rrd_dir']; $rrdtool = $config['rrdtool']; $tmp_path = $config['temp_dir']; if ($hostname === 'all') { $hostname = '*'; } $files = glob($rrd_path . '/' . $hostname . '/*.rrd'); $run = readline("Are you sure you want to run this command [N/y]: "); if (!($run == 'y' || $run == 'Y')) { echo "Exiting....." . PHP_EOL; exit; } foreach ($files as $file) { $random = $tmp_path.'/'.mt_rand() . '.xml'; $tmp = explode('/', $file); $rrd_file = array_pop($tmp); echo "Converting $file: "; $command = "$rrdtool dump $file > $random && sed -i 's/300/$step/' $random && sed -i 's/600/$heartbeat/' $random && $rrdtool restore -f $random $file && rm -f $random"; exec($command, $output, $code); if ($code === 0) { echo "[OK]\n"; } else { echo "\033[FAIL]\n"; } }