diff options
Diffstat (limited to 'include')
-rwxr-xr-x | include/config.pm.dist | 28 | ||||
-rwxr-xr-x | include/nms.pm | 2 | ||||
-rw-r--r-- | include/nms/util.pm | 33 | ||||
-rwxr-xr-x | include/nms/web.pm | 33 |
4 files changed, 63 insertions, 33 deletions
diff --git a/include/config.pm.dist b/include/config.pm.dist index cce82df..a1db01a 100755 --- a/include/config.pm.dist +++ b/include/config.pm.dist @@ -10,8 +10,32 @@ our $db_host = "gerald.tg15.gathering.org"; our $db_username = "nms"; our $db_password = "<removed>"; -# NMS hash used for public NMS obfuscation of interface names -our $nms_hash = "<removed>"; +# NMS: What SNMP objects to fetch. +# Some basics +our @snmp_objects = [ +['ifIndex'], +['sysName'], +['sysDescr'], +['ifHighSpeed'], +['ifType'], +['ifName'], +['ifDescr'], +['ifAlias'], +['ifOperStatus'], +['ifAdminStatus'], +['ifLastChange'], +['ifHCInOctets'], +['ifHCOutOctets'], +['ifInDiscards'], +['ifOutDiscards'], +['ifInErrors'], +['ifOutErrors'], +['ifInUnknownProtos'], +['ifOutQLen'], +['1.3.6.1.4.1.2636.3.1.13.1.7.7.1.0'] +]; +# Max SNMP polls to fire off at the same time. +our $snmp_max = 20; # DHCP-servers our $dhcp_server1 = "185.12.59.66"; # primary diff --git a/include/nms.pm b/include/nms.pm index 6a9598e..2ec922b 100755 --- a/include/nms.pm +++ b/include/nms.pm @@ -26,7 +26,7 @@ sub db_connect { my $dbh = DBI->connect($connstr, $nms::config::db_username, - $nms::config::db_password) + $nms::config::db_password, {AutoCommit => 0}) or die "Couldn't connect to database"; return $dbh; } diff --git a/include/nms/util.pm b/include/nms/util.pm index c97572b..79598d7 100644 --- a/include/nms/util.pm +++ b/include/nms/util.pm @@ -18,6 +18,7 @@ sub parse_switch { 'mgtmt4' => "$mgtmt4", 'mgtmt6' => "$mgtmt6", 'lolid' => "$lolid", + 'ip' => "$mgtmt4", 'distro' => "$distro" ); %{$ret{'placement'}} = guess_placement($switch); @@ -62,13 +63,13 @@ sub guess_placement { my ($e, $s) = ($1, $2); $src = "main"; - $x = int(232 + (($e-1)/2) * 31.1); + $x = int(292 + (($e-1)/2) * 31.1); $y = undef; - $x += 14 if ($e >= 17); - $x += 14 if ($e >= 29); - $x += 14 if ($e >= 45); - $x += 14 if ($e >= 63); + $x += 14 if ($e >= 13); + $x += 14 if ($e >= 25); + $x += 14 if ($e >= 41); + $x += 14 if ($e >= 59); if ($s > 2) { $y = 405 - 120 * ($s-2); @@ -83,17 +84,18 @@ sub guess_placement { $y += 45 if $name eq "e1-4"; $y += 20 if $name eq "e3-4"; $y += 15 if $name eq "e5-4"; - $yy -= 25 if $name eq "e11-1"; + $yy -= 25 if $name eq "e7-1"; + $y += 10 if $name eq "e5-2"; + $yy -= 25 if $name eq "e5-2"; + $y += 20 if ($e >= 81 and $s == 2); + $yy -= 20 if ($e >= 79 and $s == 1); + $yy -= 30 if ($e >= 81 and $s == 1); - #$yy -= 14 if $name eq "e77-1"; - #$yy -= 28 if $name eq "e79-1"; - #$yy -= 15 if $name eq "e81-1"; - #$yy -= 56 if $name eq "e83-1"; } elsif ($name =~ /^sw(\d+)-creativia$/) { my ($s) = ($1); $src = "creativia"; $x = 1535; - $y = int(130 + 32.2 * $s); + $y = int(160 + 32.2 * $s); $yy = $y + 20; if ($s == 1) { $xx = $x + 70; @@ -108,14 +110,11 @@ sub guess_placement { } elsif ($name =~ /^crew(\d+)-(\d+)$/) { my ($s, $n) = ($1, $2); $src = "crew"; - $x = 1023 + 45 * $n; - $y = int(329 + 20.5 * $s); - $xx = $x + 45; + $x = 550 + 65 * $n; + $y = int(759 + 20.5 * $s); + $xx = $x + 65; $yy = $y + 14; - if ($s == 1 && $n == 1) { - $xx += 25; - } } else { # Fallback to have _some_ position $src = "random"; diff --git a/include/nms/web.pm b/include/nms/web.pm index ddc1be0..2a5e132 100755 --- a/include/nms/web.pm +++ b/include/nms/web.pm @@ -7,8 +7,9 @@ use DBI; use Data::Dumper; use JSON; use nms; -use Digest::SHA qw(sha512_base64); -use FreezeThaw qw(freeze); +use Digest::SHA; +use FreezeThaw; +use URI::Escape; package nms::web; use base 'Exporter'; @@ -51,39 +52,45 @@ sub db_safe_quote { # returns a valid $when statement # Also sets cache-control headers if time is overridden +# This can be called explicitly to override the window of time we evaluate. +# Normally up to 15 minutes old data will be returned, but for some API +# endpoints it is better to return no data than old data (e.g.: ping). sub setwhen { - my $when; $now = "now()"; + my $window = '15m'; + if (@_ == 1) { + $window = $_[0]; + } if (defined($get_params{'now'})) { $now = db_safe_quote('now') . "::timestamp "; $cc{'max-age'} = "3600"; } - if (defined($get_params{'offset'})) { - $now = "(" . $now . " - " . db_safe_quote('offset') . "::interval)"; - } - $when = " time > " . $now . " - '5m'::interval and time < " . $now . " "; - return $when; + $when = " time > " . $now . " - '".$window."'::interval and time < " . $now . " "; } sub finalize_output { my $query; my $hash = Digest::SHA::sha512_base64(FreezeThaw::freeze(%json)); - $query = $dbh->prepare ('select ' . $now . ' as time;'); + $dbh->commit; + $query = $dbh->prepare('select to_char(' . $now . ', \'YYYY-MM-DD"T"HH24:MI:SS\') as time;'); $query->execute(); $json{'time'} = $query->fetchrow_hashref()->{'time'}; $json{'hash'} = $hash; + printcc; - + + print "Etag: $hash\n"; print "Content-Type: text/jso; charset=utf-8\n\n"; print JSON::XS::encode_json(\%json); print "\n"; } sub populate_params { - foreach my $hdr (split("&",$ENV{'QUERY_STRING'} || "")) { + my $querystring = $ENV{'QUERY_STRING'} || ""; + foreach my $hdr (split("&",$querystring)) { my ($key, $value) = split("=",$hdr,"2"); - $get_params{$key} = $value; + $get_params{$key} = URI::Escape::uri_unescape($value); } } @@ -93,6 +100,6 @@ BEGIN { $dbh = nms::db_connect(); populate_params(); - $when = setwhen(); + setwhen(); } 1; |