[smokeping-users] Re: Smokeping interface integration with mrtg
Jon Diamond
diamondj at suncup.com
Fri Dec 15 19:34:03 MET 2006
Sorry about the long delay in responding, I've been touring the
purgatory of system upgrades.
jd
>>>>>>How to use Server Side Includes to modify Smokeping web pages<<<<<<<
>>>>>Introduction:
Here are some hints on a way to modify the content of the Smokeping
web pages without hacking on the smokeping perl code. It requires that
you make a small change to the configuration of your web server and
some changes to your smokeping basepage.html. This assumes some
familarity with Apache, html & perl.
hth,
jd
>>>>>Environment:
Linux Fedora FC4 & Apache 2.0 & Smokeping 2.0.7
My Smokeping config has several levels like so:
+Enterprise
++Division1
+++Office1
++++host1
++++host2
+++Office2
++++host1
++++host2
... etc.
At the Enterprise level, I run some code that displays the uptime of
some important systems
At the Division1 level, I run some code that displays summary graphs
of packet loss for some hosts
>>>>Method:
1. Enable SSI for smokeping. On my system I added a file to the
/etc/httpd/conf.d directory.
# file /etc/httpd/conf.d/ZZsmokeping.conf
#
# Change options for /var/www/html/playground/smokeping.cgi
# allow Includes processing for output of this program
#
<Location /cgi-bin/smokeping.cgi>
Options +Includes
AddOutputFilterByType INCLUDES text/html
</Location>
2. Make some perl that conditionally emits html based on the value of
QUERY_STRING. I have two of these: getUpTime.pl & div-summary.pl. These
are appended to the end of this post.
3. Modify your smokeping basepage to run these files. Here's an
excerpt from my basepage showing some comments and conditional
execution of the perl scripts:
<TR>
<TD class="menubar" align="left" width="130" valign="top">
<P></P>
<P><B>SmokePing Targets:</B> </P>
<P><##menu##></P>
<br/>
</td>
<TD rowspan="2"></TD>
<TD rowspan="2" valign="top">
<H1><##title##></H1>
<!-- A couple of conditional includes! see Apache mod_include docs. -->
<!--#if expr="$QUERY_STRING = /=Enterprise\$/" --> <!-- top level -->
<!--#include virtual="/cgi-bin/getUpTime.pl?$QUERY_STRING" -->
<!--#elif expr="$QUERY_STRING = /=Enterprise.Division1\$/" --> <!--
Division level -->
<!--#include virtual="/cgi-bin/div-summary.pl?$QUERY_STRING" -->
<!--#endif -->
<P><##remark##></P>
<P><##overview##></P>
<P><##body##></P>
</TD>
</TR>
>>>>>Included perl script #1
#!/usr/bin/perl
##############################################################
# getUpTime.pl
#
# if in the right section
# emit a table w/uptime
#
# requires
# 1. mods to basepage.html
# 2. making httpd filter the output of smokeping.cgi for
# include files - see /etc/httpd/conf.d/ZZsmokeping.conf
# 4. put this program in cgi-bin
#
##############################################################
($junk,$target) = split(/=/,$ENV{QUERY_STRING},2);
print "Content-type: text/html\n\n";
if ($target =~ m/Enterprise$/) {
$fwtime = `snmpget -v1 -c public -Ov 10.10.11.2 system.sysUpTime.0`;
$switchtime = `snmpget -v1 -c public -Ov 10.10.11.7 system.sysUpTime.0`;
print <<TAB1;
<table border=\"1\"">
<tr><th> <th>system.sysUpTime
<tr><td>EnterpriseFirewall<td>$fwtime
<tr><td>DC-switch1<td>$switchtime
</table>
TAB1
}
exit(0);
>>>>>Included perl script #2
#!/usr/bin/perl
##############################################################
# div-summary.pl
#
# if in the right section
# process the config file
# create a tuple of graph info
# stuff the tuple into a hash record,
# stuff the hash into an array
# process the array, outputting rows of a table
# and making the graphs
#
# requires
# 1. mods to basepage.html to include this file
# 2. making httpd filter the output of smokeping.cgi for
# include files - see /etc/httpd/conf.d/ZZsmokeping.conf
# 3. put this program in cgi-bin
#
##############################################################
use lib "/usr/local/lib/perl";
use RRDs;
use lib qw(/usr/local/smokeping/lib);
use Smokeping 2.000007;
print "Content-type: text/html\n\n";
$Width = 450;
$Height = 14;
$cfgfile = "/usr/local/etc/smokeping.config";
$start = "now-3h";
$end = "now-1min";
#print "<b>output from included perl program</b>\n";
($junk,$target) = split(/=/,$ENV{QUERY_STRING},2);
if ($target =~ m/Enterprise.Office1$/) {
@GS = (); # an array !
$parser = Smokeping::get_parser;
$cfg = Smokeping::get_config $parser, $cfgfile;
$datadir = $cfg->{General}{datadir};
$imgcache = $cfg->{General}{imgcache};
$imgurl = $cfg->{General}{imgurl};
$cgiurl = $cfg->{General}{cgiurl};
@rrds = split ( /\n/,list_rrds($cfg->{Targets},"","") );
foreach $file (@rrds) {
if ($file =~ m/PC/) { # a "naming convention"
$hr = {}; # a hashref
$hr->{label} = MakeLabel($file);
$hr->{rrdfile} = $datadir.$file.".rrd";
$hr->{pngfile} = $imgcache.$file."-dash.png";
$hr->{imguri} = $hr->{pngfile};
$hr->{imguri} =~ s|/var/www/html||;
$hr->{uri} = "/cgi-bin/smokeping.cgi?target=".MakeURI($file);
push @GS, $hr;
} # if m/PC/
} # foreach
$nr = scalar(@GS);
print <<TAB1;
<table border=\"1\" rules=\"all\">
<tr><th><th>Packet Loss summary
TAB1
for ($i=0; $i < $nr; $i++) {
# print "$i:$GS[$i]->{label}\n";
# print "$i:$GS[$i]->{rrdfile}\n";
# print "$i:$GS[$i]->{pngfile}\n";
# print "$i:$GS[$i]->{uri}\n";
if ($i < ( $nr - 1)) {
print "<tr><td>$GS[$i]->{label}<td>";
print "<a class=\"grlink\" href=\"$GS[$i]->{uri}\">\n";
MakeBGraph($GS[$i]->{rrdfile}, $GS[$i]->{pngfile}, $start, $end);
print " ";
print "<img src=\"$GS[$i]->{imguri}\" alt=\"image here\"> </a>\n";
} else {
print "<tr><td>$GS[$i]->{label}<td><a href=\"$GS[$i]->{uri}\">\n";
MakeLGraph($GS[$i]->{rrdfile}, $GS[$i]->{pngfile}, $start, $end);
print "<img src=\"$GS[$i]->{imguri}\" alt=\"image here\"> </a>\n";
}
} # for
print "</table>\n";
}
exit(0);
############################################################################
#
#
#
#
############################################################################
sub MakeLabel {
my ($path) = @_;
my @bits = split(/\//,$path);
my $nbits = scalar(@bits);
my $label;
if ($nbits > 2) { $label = ucfirst($bits[3]); }
if ($nbits > 3) { $label .= " ".ucfirst($bits[4]); }
$label =~ s/PC//;
# hacks
return($label);
}
############################################################################
#
#
#
#
############################################################################
sub MakeURI {
my ($path) = @_;
my @bits = split(/\//,$path);
my $uri;
my $nbits = scalar(@bits);
for ($i=1; $i< ($nbits - 1); $i++) {
$uri .= $bits[$i];
if ($i< ($nbits - 2)) { $uri .= "."; }
}
return($uri);
}
############################################################################
#
#
#
#
############################################################################
sub list_rrds($$$);
sub list_rrds($$$) {
# List the RRD's used by this configuration
my $tree = shift;
my $path = shift;
my $print = shift;
my $prline;
foreach my $rrds (keys %{$tree}) {
if (ref $tree->{$rrds} eq 'HASH'){
$prline .= list_rrds( $tree->{$rrds}, $path."/$rrds", $print );
}
if ($rrds eq 'host') {
$prline .= $path."\n";
}
}
return $prline;
}
############################################################################
# make a skinny graph with an X-axis & a legend
#
#
#
############################################################################
sub MakeLGraph() {
my ($rrdfile, $pngfile, $gstart, $gend) = @_;
RRDs::graph(
$pngfile,
"--imgformat", "PNG",
"--width", $Width, "--height", $Height,
"--start", "$gstart",
"--end", "$gend",
"--y-grid", "none",
"--lazy",
"DEF:loss=$rrdfile:loss:AVERAGE",
"CDEF:loss0=loss,.01,LT,INF,UNKN,IF",
"CDEF:loss1=loss,.01,GT,INF,UNKN,IF",
"CDEF:loss2=loss,2,GT,INF,UNKN,IF",
"CDEF:loss3=loss,3,GT,INF,UNKN,IF",
"CDEF:loss4=loss,4,GT,INF,UNKN,IF",
"CDEF:loss5=loss,5,GT,INF,UNKN,IF",
"CDEF:loss9=loss,9,GT,INF,UNKN,IF",
"COMMENT: ",
"AREA:loss0#26ff00:0",
"AREA:loss1#00b8ff:1/10",
"AREA:loss2#0059ff:2/10",
"AREA:loss3#5e00ff:3/10",
"AREA:loss4#7e00ff:4/10",
"AREA:loss5#dd00ff:5/10",
"AREA:loss9#ff0000:9/10"
);
$ERR = RRDs::error;
print "ERROR while making graph: $ERR\n" if $ERR;
}
############################################################################
# make a skinny colored bar w/no labeling at all
#
#
#
############################################################################
sub MakeBGraph() {
my ($rrdfile, $pngfile, $gstart, $gend) = @_;
RRDs::graph(
$pngfile,
"--imgformat", "PNG",
"--width", $Width, "--height", $Height,
"--start", "$gstart",
"--end", "$gend",
"--y-grid", "none",
"--lazy",
"--only-graph",
"DEF:loss=$rrdfile:loss:AVERAGE",
"CDEF:loss0=loss,.01,LT,INF,UNKN,IF",
"CDEF:loss1=loss,.01,GT,INF,UNKN,IF",
"CDEF:loss2=loss,2,GT,INF,UNKN,IF",
"CDEF:loss3=loss,3,GT,INF,UNKN,IF",
"CDEF:loss4=loss,4,GT,INF,UNKN,IF",
"CDEF:loss5=loss,5,GT,INF,UNKN,IF",
"CDEF:loss9=loss,9,GT,INF,UNKN,IF",
"AREA:loss0#26ff00:0",
"AREA:loss1#00b8ff:1/10",
"AREA:loss2#0059ff:2/10",
"AREA:loss3#5e00ff:3/10",
"AREA:loss4#7e00ff:4/10",
"AREA:loss5#dd00ff:5/10",
"AREA:loss9#ff0000:9/10"
);
$ERR = RRDs::error;
print "ERROR while making graph: $ERR\n" if $ERR;
}
Bee Hock Goh wrote:
> Hi JD,
>
> Yes, I am certainly interested in what you have done. Do let me where to look for.
>
> A custom script could also to for display mrtg & smokeping & rrd files but that will be reinventing the wheel.
>
> I like the interface of smokeping a lot. :) Tobi suggestion in creating a pesudo probe seem very idea.
>
> regards,
> Bee Hock.
>
>
>> ----- Original Message -----
>> From: "Jon Diamond" <diamondj at suncup.com>
>> To: "Bee Hock Goh" <beehock at mail.com>
>> Subject: Re: [smokeping-users] Smokeping interface integration with mrtg
>> Date: Sun, 26 Nov 2006 10:54:26 -0800
>>
>>
>> If you have control over the configuration of your webserver you
>> can embed server-side includes into the smokeping template that can
>> run arbitrary programs and display the results within the smokeping
>> pages. I made some perl programs that 1) do snmp queries & display
>> the results at the top level of the smokeping hierarchy and 2) make
>> some summary graphs from the smokeping rrd's which get displayed at
>> an intermediate level. If there is interest, I can post an example
>> in a few days. I'll have to go back and remember/decipher how I did
>> this.
>> hth,
>> jd
>>
>>
>> Bee Hock Goh wrote:
>>
>>> Hi Tobi/Niko,
>>>
>>> I have been thinking of integrating mrtg graph into smokeping
>>> interface. Is it too much to ask if its possible for smokeping to
>>> support non-poll url linkage? Sort of like a normal host
>>> connection maybe host=DISPLAY and it will probably call an
>>> external program to create the png from rrd and display like a
>>> normal smokeping host with the same naming convention.
>>>
>>> thanks, Bee Hock.
>>>
>>>
>>>
>
>
>
>
>
--
Unsubscribe mailto:smokeping-users-request at list.ee.ethz.ch?subject=unsubscribe
Help mailto:smokeping-users-request at list.ee.ethz.ch?subject=help
Archive http://lists.ee.ethz.ch/smokeping-users
WebAdmin http://lists.ee.ethz.ch/lsg2.cgi
More information about the smokeping-users
mailing list