#!/usr/local/bin/perl
#

# Rest can be left alone as the Makefile will edit the $nocolroot.
$nocolroot = "/nocol"  unless $nocolroot;	# SET_THIS
$etcdir  = "$nocolroot/etc"  unless $etcdir;	# location of config file
$bindir  = "$nocolroot/bin"  unless $bindir;
$datadir = "$nocolroot/data" unless $datadir;

push(@INC, $bindir); push(@INC, $etcdir); # add to search paths for 'require'
require "nocollib.pl";

# get all log files from NOCOL data directory
# (extract only those files that have '-output' as prefix)
opendir(LOGDIR, "$datadir") || die "\nCannot open input directory $datadir";
@logfiles = sort(grep(/.+-output/i, readdir(LOGDIR)));
closedir(LOGDIR);

print <<EOL;
# The format of this file is important and it is generated automatically
# by nocol.pl. It should not be edited by hand!
# Comments begin with # and blank lines are allowed.
# The order of addresses is not important

EOL

# process each log file one at a time
foreach $logfile (@logfiles) {
   next if $logfile eq 'etherload-output';

    open (INPUT, "< $datadir/$logfile") or die "cannot open $logfile";

    # process log file line by line
    $i = 1;
    while (&readevent (INPUT, $i)) {
		$sitename{$i} =~ tr/\000//d;
		$siteaddr{$i} =~ tr/\000//d;
		$varname{$i} =~ tr/\000//d;

		$update = "$sitename{$i}:$siteaddr{$i}:$varname{$i}";
      if ($severity{$i} == 1)  {
         print "$update\t(H) Device non-responsive at startup\n";
   	}
	 $i++;
    }  # end of processing entry
    close INPUT;
} # end foreach(), process next log file
