Blame contrib/mrtg-archiver/mrtg.archive.pl

Packit 667938
#!/usr/bin/perl -w
Packit 667938
#
Packit 667938
# Filename: mrtg.archive.pl
Packit 667938
# Archive mrtg gifs and summary files
Packit 667938
# Original author: Emanuele Leonardi <Emanuele.Leonardi@roma1.infn.it>
Packit 667938
# Modified by: Rawlin Blake <blake@nevada.edu>
Packit 667938
#
Packit 667938
# Default placement of mrtg.archive.* is in /usr/local/sbin
Packit 667938
# If you place them elsewhere, change the $Conf_File setting later in this file.
Packit 667938
#
Packit 667938
# The cron entry I use is:
Packit 667938
# 57 23 * * * /usr/local/sbin/mrtg.archive.pl 1>> /var/log/mrtg.archive.log 2>&1
Packit 667938
#
Packit 667938
# At 23:57 every night it copies the current gifs for the given list of router
Packit 667938
# interfaces to a directory named with the current date (e.g. 970717).
Packit 667938
#
Packit 667938
#    This program is free software; you can redistribute it and/or modify
Packit 667938
#    it under the terms of the GNU General Public License as published by
Packit 667938
#    the Free Software Foundation; either version 2 of the License, or
Packit 667938
#    (at your option) any later version.
Packit 667938
#
Packit 667938
#    This program is distributed in the hope that it will be useful,
Packit 667938
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 667938
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 667938
#    GNU General Public License for more details.#
Packit 667938
#
Packit 667938
#    You should have received a copy of the GNU General Public License
Packit 667938
#    along with this program; if not, write to the Free Software
Packit 667938
#    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
Packit 667938
#    USA.
Packit 667938
#
Packit 667938
# revision 1.1  09/10/1999
Packit 667938
#   Improved error handling
Packit 667938
#   Most configurations moved to separate file
Packit 667938
#
Packit 667938
# revision 1.0  07/01/1999
Packit 667938
#   Named my version mrtg.archive.pl, allowing Emanuele to update his
Packit 667938
#     software without confusion resulting :-)
Packit 667938
#   Weekly archiving of week gifs, monthly archiving of month gifs, yearly
Packit 667938
#     archiving of year gifs. 
Packit 667938
#   Specification of which interfaces summary files are saved for.
Packit 667938
#   Terse log messages.
Packit 667938
#   Creation of the archive directory if it doesn't exist.
Packit 667938
#   Symlinking of the mrtg gifs instead of copying (I have limited disk space).
Packit 667938
#
Packit 667938
# backup.pl 07/17/97
Packit 667938
#  Author: Emanuele Leonardi <Emanuele.Leonardi@roma1.infn.it>
Packit 667938
#
Packit 667938
Packit 667938
use strict
Packit 667938
Packit 667938
#
Packit 667938
# User configuration
Packit 667938
#
Packit 667938
# Change this setting if the mrtg.archive files are
Packit 667938
# not placed in /usr/local/sbin/
Packit 667938
#
Packit 667938
Packit 667938
$Conf_File = "/usr/local/sbin/mrtg.archive.conf";
Packit 667938
Packit 667938
#
Packit 667938
# End user configuration
Packit 667938
#
Packit 667938
Packit 667938
# Check for configuration file
Packit 667938
open(CONF,"$Conf_File") ||
Packit 667938
    die "Error opening configuration file $Conf_File: $!\n";
Packit 667938
close(CONF);
Packit 667938
Packit 667938
# Get date and time of execution
Packit 667938
chomp ($date = `date +%y%m%d`);
Packit 667938
chomp ($time = `date +%H:%M:%S`);
Packit 667938
chomp ($week = `date +%w`);
Packit 667938
chomp ($month = `date +%d`);
Packit 667938
chomp ($year = `date +%m%d`);
Packit 667938
Packit 667938
require "$Conf_File";
Packit 667938
Packit 667938
print "===\nArchive $date at $time\n";
Packit 667938
Packit 667938
# Create daily directory and copy default GIF files
Packit 667938
if (!-e $ARCHIVE_DIR) {
Packit 667938
   mkdir($ARCHIVE_DIR, 0755) || die "Error creating $ARCHIVE_DIR: $!\n";
Packit 667938
   chmod(0755, $ARCHIVE_DIR);
Packit 667938
   print "Create $ARCHIVE_DIR\n";
Packit 667938
}
Packit 667938
mkdir($TO_DIR, 0755) || die "Error creating $TO_DIR: $!\n";
Packit 667938
chmod(0755, $TO_DIR);
Packit 667938
print "Create $TO_DIR\n";
Packit 667938
foreach $mgif ( @common_gifs ) {
Packit 667938
    symlink("$MRTG_DIR" . "\/" . "$mgif", "$TO_DIR" . "\/" . "$mgif");
Packit 667938
}
Packit 667938
Packit 667938
# For each node copy the daily gifs
Packit 667938
foreach $node ( @nodes_to_archive ) {
Packit 667938
    system(sprintf("cp -a %s/%s.*-day.gif %s",$MRTG_DIR,$node,$TO_DIR));
Packit 667938
}
Packit 667938
# For each node copy the weekly gifs on Sunday
Packit 667938
if ($week == "0") {
Packit 667938
    foreach $node ( @nodes_to_archive ) {
Packit 667938
        system(sprintf("cp -a %s/%s.*-week.gif %s",$MRTG_DIR,$node,$TO_DIR));
Packit 667938
    }
Packit 667938
}
Packit 667938
# For each node copy the monthly gifs on the first
Packit 667938
if ($month == "01") {
Packit 667938
    foreach $node ( @nodes_to_archive ) {
Packit 667938
        system(sprintf("cp -a %s/%s.*-month.gif %s",$MRTG_DIR,$node,$TO_DIR));
Packit 667938
    }
Packit 667938
}
Packit 667938
# For each node copy the yearly gifs on January first
Packit 667938
if ($year == "0101") {
Packit 667938
    foreach $node ( @nodes_to_archive ) {
Packit 667938
        system(sprintf("cp -a %s/%s.*-year.gif %s",$MRTG_DIR,$node,$TO_DIR));
Packit 667938
    }
Packit 667938
}
Packit 667938
Packit 667938
# For each node copy the daily summary file and create the index file
Packit 667938
foreach $summary ( @nodes_to_summary ) {
Packit 667938
    printf("%s\n",$summary);
Packit 667938
    $Summary_Source = "$MRTG_DIR/$summary.html";
Packit 667938
    $Summary_Destination = "$TO_DIR/$summary.html";
Packit 667938
    open(SRC,"<$Summary_Source") || die "Error opening $Summary_Source: $!\n";
Packit 667938
    open(DST,">$Summary_Destination") ||
Packit 667938
		die "Error opening $Summary_Destination: $!\n";
Packit 667938
    while (<SRC>) {
Packit 667938
	s/]*>//g;
Packit 667938
	s/<\/A>//g;
Packit 667938
	s/Router Overview/Router Overview of $date/;
Packit 667938
	s/<META HTTP-EQUIV=\"Refresh\" CONTENT=300 >//;
Packit 667938
	print DST; }
Packit 667938
    close(SRC);
Packit 667938
    close(DST);
Packit 667938
    chmod(0644, $Summary_Destination);
Packit 667938
}
Packit 667938
Packit 667938
# Create the general index file
Packit 667938
$INDEX = "$TO_DIR/index.html";
Packit 667938
print "Create $INDEX\n";
Packit 667938
open(IDX,">$INDEX") || die "Could not open $INDEX: $!\n";
Packit 667938
printf IDX
Packit 667938
"<HTML>
Packit 667938
<HEAD>
Packit 667938
<TITLE>Router Summary for %s</TITLE>
Packit 667938
</HEAD>
Packit 667938
<BODY BGCOLOR=\"#FFFFFF\">
Packit 667938
<CENTER>

Router Summary for %s

</CENTER>
Packit 667938

Packit 667938
    Packit 667938
    ",$date,$date;
    Packit 667938
    foreach $summary ( @nodes_to_summary ) {
    Packit 667938
        printf IDX "
  • %s
  • \n",$summary,$summary;
    Packit 667938
    }
    Packit 667938
    Packit 667938
    print IDX
    Packit 667938
    "
    Packit 667938

    Packit 667938
    </BODY>
    Packit 667938
    </HTML>";
    Packit 667938
    close(IDX);
    Packit 667938
    chmod(0644, $INDEX);
    Packit 667938
    Packit 667938
    @common_gifs = "";
    Packit 667938
    chomp ($time = `date +%H:%M:%S`);
    Packit 667938
    print "Archive $date done at $time\n";
    Packit 667938
    exit(0);
    Packit 667938
    Packit 667938
    # Eof mrtg.archive.pl