aboutsummaryrefslogtreecommitdiffstats
path: root/clients/dhcptail.pl
diff options
context:
space:
mode:
Diffstat (limited to 'clients/dhcptail.pl')
-rwxr-xr-xclients/dhcptail.pl26
1 files changed, 20 insertions, 6 deletions
diff --git a/clients/dhcptail.pl b/clients/dhcptail.pl
index 2b7e6bf..9c2111f 100755
--- a/clients/dhcptail.pl
+++ b/clients/dhcptail.pl
@@ -4,6 +4,7 @@ use POSIX;
use lib '../include';
use nms;
use strict;
+use Data::Dumper;
use warnings;
BEGIN {
@@ -31,15 +32,28 @@ my %months = (
Dec => 12
);
-my ($dbh, $q);
+my $realtime = 0;
+my ($dbh, $q,$check);
$dbh = nms::db_connect();
-$q = $dbh->prepare("INSERT INTO dhcp (switch,time,mac) VALUES((SELECT switch FROM switches WHERE ?::inet << network),?,?)");
+$q = $dbh->prepare("INSERT INTO dhcp (switch,time,ip,mac) VALUES((SELECT switch FROM switches WHERE ?::inet << subnet4 ORDER BY sysname LIMIT 1),?,?,?)");
+$check = $dbh->prepare("SELECT max(time)::timestamp - ?::timestamp < '0s'::interval as doit FROM dhcp;");
+
open(SYSLOG, "tail -n 9999999 -F /var/log/syslog |") or die "Unable to tail syslog: $!";
while (<SYSLOG>) {
- /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d+)\s+(\d+:\d+:\d+).*DHCPACK on (\d+\.\d+\.\d+\.\d+) to (\S+)/ or next;
- my $date = $year . "-" . $months{$1} . "-" . $2 . " " . $3;
+ /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d+)\s+(\d+:\d+:\d+).*DHCPACK on (\d+\.\d+\.\d+\.\d+) to (\S+) / or next;
+ my $date = $year . "-" . $months{$1} . "-" . $2 . " " . $3 . " Europe/Oslo";
my $machine = $5;
- $q->execute($4,$date,$machine);
- $q->commit;
+ my $via = $6;
+ $check->execute($date);
+ $dbh->commit;
+ my $cond = $check->fetchrow_hashref();
+ if (!defined($cond) or !defined($cond->{'doit'}) or $cond->{'doit'} eq '1') {
+ if ($realtime != 1) {
+ $realtime = 1;
+ print "real time achieved...\n";
+ }
+ $q->execute($4,$date,$4,$machine);
+ $dbh->commit;
+ }
}
close SYSLOG;