Skip to content

Configure email reports with Observium

by Patrick Durante on April 11th, 2014

Find the graph that you want to get in an email report. Click RRD COMMAND in the top right to get the code to create the graph on the command line. An example:


rrdtool graph /tmp/k93ewPFhVr6kIgGy.png --alt-autoscale --rigid -E --start 1397210793 --end 1397232393 --width 1159 --height 300 -c BACK#EEEEEE00 -c SHADEA#EEEEEE00 -c SHADEB#EEEEEE00 -c FONT#000000 -c CANVAS#FFFFFF00 -c GRID#a5a5a5 -c MGRID#FF9999 -c FRAME#5e5e5e -c ARROW#5e5e5e -R normal --font LEGEND:8:'DejaVuSansMono' --font AXIS:7:'DejaVuSansMono' --font-render-mode normal COMMENT:'Bits/s Now Avg Max 95th \n' DEF:outoctets=/opt/observium/rrd/asa5505/port-15.rrd:OUTOCTETS:AVERAGE DEF:inoctets=/opt/observium/rrd/asa5505/port-15.rrd:INOCTETS:AVERAGE DEF:outoctets_max=/opt/observium/rrd/asa5505/port-15.rrd:OUTOCTETS:MAX DEF:inoctets_max=/opt/observium/rrd/asa5505/port-15.rrd:INOCTETS:MAX CDEF:octets=inoctets,outoctets,+ CDEF:doutoctets=outoctets,-1,* CDEF:outbits=outoctets,8,* CDEF:outbits_max=outoctets_max,8,* CDEF:doutoctets_max=outoctets_max,-1,* CDEF:doutbits=doutoctets,8,* CDEF:doutbits_max=doutoctets_max,8,* CDEF:inbits=inoctets,8,* CDEF:inbits_max=inoctets_max,8,* VDEF:totin=inoctets,TOTAL VDEF:totout=outoctets,TOTAL VDEF:tot=octets,TOTAL VDEF:95thin=inbits,95,PERCENT VDEF:95thout=outbits,95,PERCENT VDEF:d95thout=doutbits,5,PERCENT AREA:inbits#92B73F LINE1.25:inbits#4A8328:'In ' GPRINT:inbits:LAST:%6.2lf%s GPRINT:inbits:AVERAGE:%6.2lf%s GPRINT:inbits_max:MAX:%6.2lf%s GPRINT:95thin:%6.2lf%s\\n AREA:doutbits#7075B8 LINE1.25:doutbits#323B7C:'Out' GPRINT:outbits:LAST:%6.2lf%s GPRINT:outbits:AVERAGE:%6.2lf%s GPRINT:outbits_max:MAX:%6.2lf%s GPRINT:95thout:%6.2lf%s\\n GPRINT:tot:'Total %6.2lf%s' GPRINT:totin:'(In %6.2lf%s' GPRINT:totout:'Out %6.2lf%s)\\l' LINE1:95thin#aa0000 LINE1:d95thout#aa0000

Create a bash script to and set the start and stop time of the graph you want to create. Input them as variables for –start and –end at the beginning of the RRD command. Example:

Save the following as dailybw.sh


#!/bin/bash

current_time=`date +%s`
#Graph Length is old time, it is currently set for 6 hours.
old_time=$((current_time-21600))
echo $old_time

rrdtool graph /tmp/dailybandwidth.png --alt-autoscale --rigid -E --start $old_time --end $current_time --width 1159 --height 300 -c BACK#EEEEEE00 -c SHADEA#EEEEEE00 -c SHADEB#EEEEEE00 -c FONT#000000 -c CANVAS#FFFFFF00 -c GRID#a5a5a5 -c MGRID#FF9999 -c FRAME#5e5e5e -c ARROW#5e5e5e -R normal --font LEGEND:8:'DejaVuSansMono' --font AXIS:7:'DejaVuSansMono' --font-render-mode normal COMMENT:'Bits/s Now Avg Max 95th \n' DEF:outoctets=/opt/observium/rrd/naphrtrbr01/port-8.rrd:OUTOCTETS:AVERAGE DEF:inoctets=/opt/observium/rrd/naphrtrbr01/port-8.rrd:INOCTETS:AVERAGE DEF:outoctets_max=/opt/observium/rrd/naphrtrbr01/port-8.rrd:OUTOCTETS:MAX DEF:inoctets_max=/opt/observium/rrd/naphrtrbr01/port-8.rrd:INOCTETS:MAX CDEF:octets=inoctets,outoctets,+ CDEF:doutoctets=outoctets,-1,* CDEF:outbits=outoctets,8,* CDEF:outbits_max=outoctets_max,8,* CDEF:doutoctets_max=outoctets_max,-1,* CDEF:doutbits=doutoctets,8,* CDEF:doutbits_max=doutoctets_max,8,* CDEF:inbits=inoctets,8,* CDEF:inbits_max=inoctets_max,8,* VDEF:totin=inoctets,TOTAL VDEF:totout=outoctets,TOTAL VDEF:tot=octets,TOTAL VDEF:95thin=inbits,95,PERCENT VDEF:95thout=outbits,95,PERCENT VDEF:d95thout=doutbits,5,PERCENT AREA:inbits#92B73F LINE1.25:inbits#4A8328:'In ' GPRINT:inbits:LAST:%6.2lf%s GPRINT:inbits:AVERAGE:%6.2lf%s GPRINT:inbits_max:MAX:%6.2lf%s GPRINT:95thin:%6.2lf%s\\n AREA:doutbits#7075B8 LINE1.25:doutbits#323B7C:'Out' GPRINT:outbits:LAST:%6.2lf%s GPRINT:outbits:AVERAGE:%6.2lf%s GPRINT:outbits_max:MAX:%6.2lf%s GPRINT:95thout:%6.2lf%s\\n GPRINT:tot:'Total %6.2lf%s' GPRINT:totin:'(In %6.2lf%s' GPRINT:totout:'Out %6.2lf%s)\\l' LINE1:95thin#aa0000 LINE1:d95thout#aa0000

I used the following perl script which will take the graph as an inline html doc. I first execute the bash script to generate the graph and then email it.


use strict;
use warnings;
use MIME::Lite;

system("/bin/bash /usr/local/src/dailybw.sh");

my $msg = MIME::Lite->new(
                 To      =>'emailaddress@email.com',
                 From    =>'server@server.com',
                 Subject =>'6AM Daily Bandwidth Report',
                 Type    =>'multipart/related'
                 );
    $msg->attach(Type => 'text/html',
                 Data => qq{ <body>
                            <br>6AM Daily Bandwidth Report<br>
                            <br>Daily<br>
                             <img src="cid:dailybandwidth.png">
                             </body> }
                 );
    $msg->attach(Type => 'image/png',
                 Id   => 'dailybandwidth.png',
                 Path => '/tmp/dailybandwidth.png',
                 );
    $msg->send();

From → Uncategorized

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS

 

WP-SpamFree by Pole Position Marketing