aboutsummaryrefslogtreecommitdiffstats
path: root/clients/flatify.pl
blob: f2aa18a8229b025afe526ced83f5496e400850b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#! /usr/bin/perl

# Make the given switch into a D-Link placement-wise.

use strict;
use warnings;
use lib '../include';
use nms;

my $dbh = nms::db_connect();
my $q = $dbh->prepare('SELECT switch,placement FROM switches NATURAL JOIN placements WHERE sysname LIKE ?');
$q->execute('%'.$ARGV[0].'%');

while (my $ref = $q->fetchrow_hashref) {
	$ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/ or die;
	my ($x1,$y1,$x2,$y2) = ($1, $2, $3, $4);
	my $placement = sprintf "(%d,%d),(%d,%d)", $x2 - 100, $y2 - 16, $x2, $y2;
	$dbh->do("UPDATE placements SET placement=? WHERE switch=?",
		undef, $placement, $ref->{'switch'});
	last;  # Take only one.
}