Ok, so the script I wrote looks an awful lot like yours... gmta, I guess?
I'm using perl instead of shell and mine will walk all of the plugin-generated maps in output/, but other than that they are about the same.
Code: Select all
#!/usr/local/bin/perl
# Archive weathermaps, building a movie of the last 24 hours worth
#
use strict;
use POSIX qw(strftime);
use File::Find;
# Location of the maps
my $MapDir = "/usr/local/share/cacti/plugins/weathermap/output";
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
chdir($MapDir);
# Loop through maps, copying to archive/map-date.png
my $datestamp = strftime("%Y-%m-%d-%H%M%S",localtime);
foreach my $map (glob("*.png")) {
# Assume we are running as a cacti plugin
next unless ($map =~ /^([a-f0-9]{20}).png$/);
my $mapbase = $1;
my $amap = "$mapbase-$datestamp.png";
`cp $map archive/$amap`;
`convert -quiet -delay 30 archive/$mapbase\*.png archive/$mapbase.mpg > /dev/null`
}
# Clean up anything older that 48 hours
File::Find::find({wanted => \&wanted}, 'archive');
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
/^.*\.png\z/s &&
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
(int(-M _) > 2) &&
unlink($name);
}
I just dropped that into cacti_path/plugins/weathermap/output, and added a call to it to the cron that runs poller. That way it runs every polling cycle after the maps have been created.
Code: Select all
*/5 * * * * cacti /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1 && /usr/local/share/cacti/plugins/weathermap/output/archivemaps.pl > /dev/null 2>&1