aboutsummaryrefslogtreecommitdiffstats
path: root/clients
diff options
context:
space:
mode:
Diffstat (limited to 'clients')
-rwxr-xr-xclients/lldpdiscover.pl8
-rwxr-xr-xclients/ping.pl48
2 files changed, 56 insertions, 0 deletions
diff --git a/clients/lldpdiscover.pl b/clients/lldpdiscover.pl
index bfd4f84..3f24a63 100755
--- a/clients/lldpdiscover.pl
+++ b/clients/lldpdiscover.pl
@@ -199,6 +199,14 @@ sub add_switch {
$dbh->do('INSERT INTO portnames (switchtype, port, description) VALUES (?, ?, ?)',
undef, $switchtype, $port->{'ifIndex'}, $port->{'ifDescr'});
}
+
+ # Entirely random placement. Annoying? Fix it yourself.
+ my $x = int(rand 1200);
+ my $y = int(rand 650);
+ my $box = sprintf "((%d,%d),(%d,%d))", $x, $y, $x+40, $y+40;
+ $dbh->do("INSERT INTO placements (switch,placement) VALUES (CURRVAL('switches_switch_seq'), ?)",
+ undef, $box);
+
$dbh->commit;
}
diff --git a/clients/ping.pl b/clients/ping.pl
new file mode 100755
index 0000000..b0eb57d
--- /dev/null
+++ b/clients/ping.pl
@@ -0,0 +1,48 @@
+#! /usr/bin/perl
+use DBI;
+use POSIX;
+use Time::HiRes;
+use Net::Oping;
+use Data::Dumper;
+use strict;
+use warnings;
+
+use lib '../include';
+use nms;
+
+my $dbh = nms::db_connect();
+$dbh->{AutoCommit} = 0;
+$dbh->{RaiseError} = 1;
+
+my $q = $dbh->prepare("SELECT switch,ip FROM switches WHERE ip<>'127.0.0.1'");
+
+while (1) {
+ my $ping = Net::Oping->new;
+ $ping->timeout(0.2);
+
+ $q->execute;
+ my %ip_to_switch = ();
+ while (my $ref = $q->fetchrow_hashref) {
+ my $switch = $ref->{'switch'};
+ my $ip = $ref->{'ip'};
+ $ping->host_add($ip);
+ $ip_to_switch{$ip} = $switch;
+ }
+ my $result = $ping->ping();
+ die $ping->get_error if (!defined($result));
+
+ $dbh->do('COPY ping (switch, latency_ms) FROM STDIN'); # date is implicitly now.
+ while (my ($ip, $latency) = each %$result) {
+ my $switch = $ip_to_switch{$ip};
+ if (!defined($latency)) {
+ $dbh->pg_putcopydata("$switch\t\\N\n");
+ } else {
+ $dbh->pg_putcopydata("$switch\t$latency\n");
+ }
+ }
+ $dbh->pg_putcopyend();
+ $dbh->commit;
+
+ sleep 1;
+}
+