]> git.sesse.net Git - nms/commitdiff
Lots of merging from TG06 NMS.
authorroot <root@space>
Wed, 4 Apr 2007 10:11:22 +0000 (12:11 +0200)
committerroot <root@space>
Wed, 4 Apr 2007 10:11:22 +0000 (12:11 +0200)
web/ext/graph.h
web/ext/showswitch.pl
web/nettkart.pl
web/portkart.pl
web/smanagement.pl
web/sshow.pl

index 2d392173e5fffec9250d72ab9ecc746965d12dd9..c6376af1952bd7c612081ffb1cffd1bf78f0d864 100644 (file)
@@ -11,29 +11,26 @@ typedef struct _graph {
   int width;
   int height;
   int xoffset;
-  int yoffset;
-  float min_x;
-  float max_x;
-  float min_y;
-  float max_y;
-  float xs;
-  float ys;
+  double min_x;
+  double max_x;
+  double min_y;
+  double max_y;
+  double xs;
+  double ys;
 } graph;
 
-int tz_local_offset() { return 7200; } // riktig?
-
 void mygraph_fill_background(graph *mygraph);
 
 void mygraph_draw_graph (cairo_t *cr, int x, int y );
 
 graph *mygraph_new (int width, int height);
 
-graph *mygraph_make_graph (graph *mygraph, float min_x,
-                          float max_x, float min_y, float max_y,
+graph *mygraph_make_graph (graph *mygraph, double min_x,
+                          double max_x, double min_y, double max_y,
                           int tickgran);
 
-void mygraph_plot_series (graph *mygraph, int *xvals, int *yvals,
-                         int n_vals, float r, float g, float b);
+void mygraph_plot_series (graph *mygraph, int *xvals, unsigned long long *yvals,
+                         int n_vals, double r, double g, double b);
 
 void mygraph_to_file (graph *mygraph, char *filename);
 
index c0150054e271d89c605af1c110cc7e50868996fe..f2851c149f2998ab05a0ad2d3186e0b346f0f199 100755 (executable)
@@ -6,6 +6,9 @@ use POSIX ":sys_wait_h";
 use strict;
 use warnings;
 
+use lib '../../include';
+
+use nms;
 use mygraph;
 require 'glue.pl';
 
@@ -22,8 +25,7 @@ $height = 250 unless (defined($height));
 my $graph = mygraph::mygraph_new($width, $height);
 
 my $start = [Time::HiRes::gettimeofday];
-my $dbh = DBI->connect("dbi:Pg:dbname=tg", "tg", "tg06")
-    or die "Couldn't connect to database";
+my $dbh = nms::db_connect();                                                                           
 
 # Fetch the name
 my $ref = $dbh->selectrow_hashref('SELECT sysname FROM switches WHERE switch=?', undef, $switch);
@@ -38,7 +40,7 @@ print <<"EOF";
     <h1>Switch $switch ($ref->{'sysname'})</h1>
 EOF
 
-my $q = $dbh->prepare('select port,coalesce(description, \'Port \' || port) as description,extract(epoch from time) as time,bytes_in,bytes_out from polls natural join switches natural left join portnames where time between \'2005-03-23 05:17:36+01\' and  \'2005-03-24 05:17:36+01\' and switch=? order by switch,port,time;');
+my $q = $dbh->prepare('select port,coalesce(description, \'Port \' || port) as description,extract(epoch from time) as time,bytes_in,bytes_out from polls natural join switches natural left join portnames where time between now() - \'1 day\'::interval and now() and switch=? order by switch,port,time;');
 $q->execute($switch);
 
 my (@totx, @toty1, @toty2) = ();
@@ -60,7 +62,7 @@ while (my $ref = $q->fetchrow_hashref()) {
     my $in = $ref->{'bytes_in'};
     my $out = $ref->{'bytes_out'};
     next if ($time == $prev_time);
-
+    
     if ($ref->{'port'} != $last_port) {
        if ($last_port != -1) {
            my $filename = "$switch-$last_port-$width-$height.png";
index f4b9ee0e966fcd8e264136378d73f7d02b8791d8..cab7a3b8675100c11d08dfa912037f4ca992aa88 100755 (executable)
@@ -1,35 +1,71 @@
 #! /usr/bin/perl
 use CGI;
 use GD;
+use Image::Magick;
 use DBI;
 use lib '../include';
 use nms;
 my $cgi = CGI->new;
 
+# Sekrit night-mode
+my $night = defined($cgi->param('night'));
+
 my $dbh = nms::db_connect();
 
 GD::Image->trueColor(1);
+my ($img, $text_img);
+
 $img = GD::Image->new('bg07.png');
+if ($night) {
+       my ($width, $height) = ($img->width, $img->height); 
+
+       $img = GD::Image->new($width, $height);
+       $img->alphaBlending(0);
+       $img->saveAlpha(1);
+       my $blank = $img->colorAllocateAlpha(0, 0, 0, 127);
+       $img->filledRectangle(0, 0, $img->width - 1, $img->height - 1, $blank);
+
+       $text_img = GD::Image->new($width, $height);
+       $text_img->alphaBlending(0);
+       $text_img->saveAlpha(1);
+       my $blank = $text_img->colorAllocateAlpha(0, 0, 0, 127);
+       $text_img->filledRectangle(0, 0, $text_img->width - 1, $text_img->height - 1, $blank);
+} else {
+       $img = GD::Image->new('snmp-bg.png');
+       $text_img = $img;
+}
 
 my $blk = $img->colorResolve(0, 0, 0);
 
 for my $y (42..236) {
-       my $i = 2.0 * ($y - 236.0) / (42.0 - 237.0);
+       my $i = 4.0 * ($y - 236.0) / (42.0 - 237.0);
        my $clr = get_color($i);
        
-       $img->filledRectangle(32,$y,53,$y+1,$clr);
+       $img->filledRectangle(12, $y, 33, $y+1, $clr);
+       $text_img->filledRectangle(12, $y, 33, $y+1, $clr);
 }
 
+$text_img->rectangle(12,42,33,236,$blk);
+
+my $tclr = $night ? $text_img->colorResolve(255, 255, 255) : $blk;
+$text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*0.0/4.0, "100 Gbit/sec");
+$text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*1.0/4.0, "10 Gbit/sec");
+$text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*2.0/4.0, "1 Gbit/sec");
+$text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*3.0/4.0, "100 Mbit/sec");
+$text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*4.0/4.0, "10 Mbit/sec");
+$text_img->stringFT($tclr, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 1000, 620, "NMS (C) 2005-2006 Tech:Server");
+
 my $q = $dbh->prepare('select * from switches natural join placements natural left join
-( select switch,sum(bytes_in)/count(*) as
-bytes_in,sum(bytes_out)/count(*) as bytes_out from get_datarate() group
-by switch ) t1 where ip<>\'127.0.0.1\'');
+( select switch,sum(bytes_in) as bytes_in,sum(bytes_out) as bytes_out from get_datarate() group
+by switch ) t1 order by zorder');
 $q->execute();
 while (my $ref = $q->fetchrow_hashref()) {
 
        # for now:
-       # 100kbit/port = all green
-       # 1gbit/port = all red
+       # 10Mbit/switch = green
+       # 100Mbit/switch = yellow
+       # 1Gbit/switch = red
+       # 10Gbit/switch = white
        
        my $clr;
 
@@ -37,12 +73,12 @@ while (my $ref = $q->fetchrow_hashref()) {
                my $intensity = 0.0;
                my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'};  # average and convert to bits (should be about the same in practice)
 
-               my $max = 20_000_000.0;   # 10mbit
-               my $min =    100_000.0;   # 100kbit
+               my $max = 10_000_000_000.0;   # 10Gbit
+               my $min =     10_000_000.0;   # 10Mbit
                if ($traffic >= $min) {
-                       $intensity = 2.0 * (log($traffic / $min) / log(10)) / (log($max / $min) / log(10));
-                       $intensity = 2.0 if ($intensity > 2.0);
-               }       
+                       $intensity = log($traffic / $min) / log(10);
+                       $intensity = 3.0 if ($intensity > 3.0);
+               }
                $clr = get_color($intensity);
        } else {
                $clr = $img->colorResolve(0, 0, 255);
@@ -50,18 +86,44 @@ while (my $ref = $q->fetchrow_hashref()) {
        
        $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
        $img->filledRectangle($3,$4,$1,$2,$clr);
+       $text_img->filledRectangle($3,$4,$1,$2,$clr);
+
        $img->rectangle($3,$4,$1,$2,$blk);
-        $img->stringUp(gdSmallFont,$3,$2-3,$ref->{'sysname'},$blk);
+       $text_img->rectangle($3,$4,$1,$2,$blk);
+        $text_img->stringUp(gdSmallFont,$3,$2-3,$ref->{'sysname'},$blk);
 }
 $dbh->disconnect;
 
 print $cgi->header(-type=>'image/png');
-print $img->png;
+if ($night) {
+       my $magick = Image::Magick->new;
+       $magick->BlobToImage($img->png);
+       $magick->Blur(sigma=>10.0, channels=>'All');
+       $magick->Gamma(gamma=>1.90);
+
+       my $m2 = Image::Magick->new;
+       $m2->Read('snmp-bg.png');
+       $m2->Negate();
+       $m2->Composite(image=>$magick, compose=>'Atop');
+
+       my $m3 = Image::Magick->new;
+       $m3->BlobToImage($text_img->png);
+       $m2->Composite(image=>$m3, compose=>'Atop');
+       
+       $img = $m2->ImageToBlob();
+       print $img;
+} else {       
+       print $img->png;
+}
 
 sub get_color {
        my $intensity = shift;
        my $gamma = 1.0/1.90;
-       if ($intensity > 1.0) {
+       if ($intensity > 3.0) {
+               return $img->colorResolve(255.0 * ((4.0 - $intensity) ** $gamma), 255.0 * ((4.0 - $intensity) ** $gamma), 255.0 * ((4.0 - $intensity) ** $gamma));
+       } elsif ($intensity > 2.0) {
+               return $img->colorResolve(255.0, 255.0 * (($intensity - 2.0) ** $gamma), 255.0 * (($intensity - 2.0) ** $gamma));
+       } elsif ($intensity > 1.0) {
                return $img->colorResolve(255.0, 255.0 * ((2.0 - $intensity) ** $gamma), 0);
        } else {
                return $img->colorResolve(255.0 * ($intensity ** $gamma), 255, 0);
index 1e2832ecd157aa8e7c36b0c9fe70af5a54fe72c1..10436fd72746e61c774405c711b1559dc9ba4924 100755 (executable)
@@ -14,13 +14,20 @@ $img = GD::Image->new('bg07.png');
 my $blk = $img->colorResolve(0, 0, 0);
 
 for my $y (42..236) {
-       my $i = 2.0 * ($y - 236.0) / (42.0 - 237.0);
+       my $i = 3.0 * ($y - 236.0) / (42.0 - 237.0);
        my $clr = get_color($i);
        
-       $img->filledRectangle(32,$y,53,$y+1,$clr);
+       $img->filledRectangle(12,$y,33,$y+1,$clr);
 }
 
-my $q = $dbh->prepare('select switch,port,bytes_in,bytes_out,placement,switchtype from switches natural join placements natural join get_current_datarate() where switchtype in (\'es3024\')');
+$img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*0.0/3.0, "1 Gbit/sec");
+$img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*1.0/3.0, "100 Mbit/sec");
+$img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*2.0/3.0, "10 Mbit/sec");
+$img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 40, 47 + (236-42)*3.0/3.0, "1 Mbit/sec");
+$img->stringFT($blk, "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf", 10, 0, 1000, 620, "NMS (C) 2005-2006 Tech:Server");
+
+my $q = $dbh->prepare('select switch,port,bytes_in,bytes_out,placement,switchtype from switches natural join placements natural join get_datar
+ate() where switchtype in (\'es3024\')');
 $q->execute();
 while (my $ref = $q->fetchrow_hashref()) {
 
@@ -34,11 +41,11 @@ while (my $ref = $q->fetchrow_hashref()) {
                my $intensity = 0.0;
                my $traffic = 4.0 * $ref->{'bytes_in'} + $ref->{'bytes_out'};  # average and convert to bits (should be about the same in practice)
 
-               my $max = 20_000_000.0;   # 100mbit
-               my $min =    100_000.0;   # 100kbit
+               my $max = 1_000_000_000.0;   # 1Gbit
+               my $min =     1_000_000.0;   # 1Mbit
                if ($traffic >= $min) {
-                       $intensity = 2.0 * (log($traffic / $min) / log(10)) / (log($max / $min) / log(10));
-                       $intensity = 2.0 if ($intensity > 2.0);
+                       $intensity = log($traffic / $min) / log(10);
+                       $intensity = 3.0 if ($intensity > 3.0);
                }
                $clr = get_color($intensity);
        } else {
@@ -64,7 +71,9 @@ print $img->png;
 sub get_color {
        my $intensity = shift;
        my $gamma = 1.0/1.90;
-       if ($intensity > 1.0) {
+       if ($intensity > 2.0) {
+               return $img->colorResolve(255.0, 255.0 * (($intensity - 2.0) ** $gamma), 255.0 * (($intensity - 2.0) ** $gamma));
+       } elsif ($intensity > 1.0) {
                return $img->colorResolve(255.0, 255.0 * ((2.0 - $intensity) ** $gamma), 0);
        } else {
                return $img->colorResolve(255.0 * ($intensity ** $gamma), 255, 0);
index ed783b2fa915b245f821f92c9d19675416df061c..de7e1b8d134d4df33b69b99bfae02d59e7c810fd 100755 (executable)
@@ -4,6 +4,7 @@ use strict;
 use CGI;
 use DBI;
 use Data::Dumper;
+use Switch;
 use lib '../include';
 use nms;
 
@@ -28,15 +29,15 @@ sub parse_range($) {
 
        my @rangecomma = split(/\s*,\s*/, $switches);
        foreach (@rangecomma) {
-               my ($first, $drop1, $last, $drop2) = $_ =~ /(e\d+\-[123456])(sw)?\s*\-\s*(e\d+\-[123456])?(sw)?/;
-               if (!defined($first) && $_ =~ /e\d+\-[123456]/) {
+               my ($first, $last) = $_ =~ /(e\d+\-(?:sw)?[123456])\s*\-\s*(e\d+\-(?:sw)?[123456])?/;
+               if (!defined($first) && $_ =~ /e\d+\-(sw)?[123456]/) {
                        $first = $_;
                }
                if (!defined($first)) {
                        print "<font color=\"red\">Parse error in: $_</font><br>\n";
                        next;
                }
-               my ($rowstart, $placestart) = $first =~ /e(\d+)\-([123456])/;
+               my ($rowstart, $placestart) = $first =~ /e(\d+)\-(?:sw)?([123456])/;
                if (!defined($rowstart) || !defined($placestart)) {
                        print "<font color=\"red\">Parse error in: $_</font><br>\n";
                        next;
@@ -47,7 +48,7 @@ sub parse_range($) {
                        $placeend = $placestart;
                }
                else {
-                       ($rowend, $placeend) = $last =~ /e(\d+)\-([123456])/;
+                       ($rowend, $placeend) = $last =~ /e(\d+)\-(?:sw)?([123456])/;
                }
                if (!defined($rowend) || !defined($placeend)) {
                        print "<font color=\"red\">Parse error in: $_</font><br>\n";
@@ -64,7 +65,7 @@ sub parse_range($) {
                        }
                        for (my $j = $dostart; $j <= 6; $j++) {
                                last if ($i == $rowend && $j > $placeend);
-                               push(@range, "e$i-$j");
+                               push(@range, "e$i-sw$j");
                        }
                }
        }
@@ -77,9 +78,9 @@ sub parse_range($) {
 sub get_addr_from_switchnum($) {
        my ($sysname) = @_;
 
-       $sgetip->execute($sysname."sw");
+       $sgetip->execute($sysname);
        if ($sgetip->rows() < 1) {
-               print "Could not get the ip for: ".$sysname."sw";
+               print "Could not get the ip for: ".$sysname;
                return undef;
        }
        my $row = $sgetip->fetchrow_hashref();
index bae9511e84dbc267f4fbac1672b7318d6fe0707d..b840ac8a70a1b940e0951d8f7b2dfe24b64de3fd 100755 (executable)
@@ -110,9 +110,6 @@ if (defined($cgi->param('agid'))) {
        my $gid = $cgi->param('gid');
        if (!defined($gid)) {
                print "<font color=\"red\">Du har ikke valgt en gid å slette.</font>\n";
-       }
-       if ($cgi->param('agid') eq 'Disable') {
-               $sdisablegid->execute($gid);
                print "<p>gid: ".$cgi->param('gid')." har blitt disablet.\n";
        }
        else {