diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-03-17 21:31:30 +0000 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-03-17 21:31:30 +0000 |
commit | b7887d4b7181e057d77a5f5d093de0400052bd0b (patch) | |
tree | 5c5653a19c9469bd2923fd11015cbfe06ef7e2b3 /clients/dhcptail.pl | |
parent | 151f2403dec93d32199afea4ceff9833b8980cf4 (diff) | |
parent | 8eb1b43ce136e808fbd90aeb11eecd03eaa821d8 (diff) |
Merge branch 'master' of ssh://github.com/tech-server/tgmanage
Diffstat (limited to 'clients/dhcptail.pl')
-rwxr-xr-x | clients/dhcptail.pl | 39 |
1 files changed, 5 insertions, 34 deletions
diff --git a/clients/dhcptail.pl b/clients/dhcptail.pl index e7898aa..2b7e6bf 100755 --- a/clients/dhcptail.pl +++ b/clients/dhcptail.pl @@ -31,44 +31,15 @@ my %months = ( Dec => 12 ); -my ($dbh, $q, $cq); +my ($dbh, $q); +$dbh = nms::db_connect(); +$q = $dbh->prepare("INSERT INTO dhcp (switch,time,mac) VALUES((SELECT switch FROM switches WHERE ?::inet << network),?,?)"); 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; my $machine = $5; - my $owner_color; - - if ($machine eq '00:15:c5:42:ce:e9') { - $owner_color = '#00ff00'; # Steinar - } elsif ($machine eq '00:1e:37:1c:d2:65') { - $owner_color = '#c0ffee'; # Trygve - } elsif ($machine eq '00:16:d3:ce:8f:a7') { - $owner_color = '#f00f00'; # Jon - } elsif ($machine eq '00:16:d4:0c:8a:1c') { - $owner_color = '#ff99ff'; # Jørgen - } elsif ($machine eq '00:18:8b:aa:2f:f8') { - $owner_color = '#663300'; # Kjetil - } elsif ($machine eq '00:15:58:29:14:e3') { - $owner_color = '#f1720f'; # Bård - } else { - $owner_color = "#000000"; # Unknown - } - - if (!defined($dbh) || !$dbh->ping) { - $dbh = nms::db_connect(); - $q = $dbh->prepare("UPDATE dhcp SET last_ack=? WHERE ?::inet << network AND ( last_ack < ? OR last_ack IS NULL )") - or die "Couldn't prepare query"; - $cq = $dbh->prepare("UPDATE dhcp SET owner_color=? WHERE ?::inet << network AND owner_color IS NULL") - or die "Couldn't prepare query"; - } - - print STDERR "$date $4\n"; - $q->execute($date, $4, $date) - or die "Couldn't push $1 into database"; - if (defined($owner_color)) { - $cq->execute($owner_color, $4) - or die "Couldn't push $1 into database"; - } + $q->execute($4,$date,$machine); + $q->commit; } close SYSLOG; |