Location: PHPKode > projects > LSMS SNMP to MRTG toolset > www/snmpmrtg/lsmsmrtg.php
<?php
// (C)Copyright John Baker 2004/2005/2006
//
// This file is part of lsms2mrtg.
//
// lsms2mrtg is free software;you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation;either version 2 of the License, or
// (at your option) any later version.
//
// lsms2mrtg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with lsms2mrtg;if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// For more informationn please visit http://gnulsms2mrtg.sourceforge.net/
error_reporting(2);
include 'generic.inc';
include 'jbsnmplib.inc';
include 'BrickSNMPlib.inc';


$intspeed=125000000;
echo $htmlheader;

$mrtgtop="$mrtgheader

WorkDir: $mrtglsmsworkdir
RunAsDaemon: yes
Interval: 5
refresh: 300
EnableIPv6: no
NoMib2: Yes

";

$ethername=$HTTP_GET_VARS["ethername"];
if ($ethername =="" ) $ethername = $HTTP_POST_VARS["ethername"];
$intspeed=$HTTP_GET_VARS["intspeed"];
if ($intspeed =="" ) $intspeedy = $HTTP_POST_VARS["intspeed"];
$legendi=$HTTP_GET_VARS["legendi"];
if ($legendi =="" ) $legendiy = $HTTP_POST_VARS["legendi"];
$legendo=$HTTP_GET_VARS["legendo"];
if ($legendo =="" ) $legendoy = $HTTP_POST_VARS["legendo"];
$whattograph=$HTTP_GET_VARS["whattograph"];
if ($whattograph =="" ) $whattography = $HTTP_POST_VARS["whattograph"];

$filewrite="";
$newfilewrite="";


//$brickinterface=(str_replace("Ether_","",$ethername));

$tarrgetname=$brickname."_".$ethername."_".$whattograph;


if (is_numeric($brickinterface)==false) {$brickinterface="0";}

if ($whattograph=="cpu") { $mrtgoptions="noinfo, withzeroes, nolegend, nobanner";
    $runcommand="brickcpu";
    $legendi="CPU Usage";
    $ethername="CPU Usage on $brickname";
    $tarrgetname="Brick_CPU_Usage_On_$brickname";
    $mrtgoptions = "$mrtgoptions ,gauge";
    $intspeed = "100";
}
if ($whattograph=="processed") { $mrtgoptions="noinfo, withzeroes, nolegend, nobanner, nopercent";
    $runcommand="intpro";
    $legendi="Processed Packets";
    $ethername="Processed Packets on ".$ethername;
    $tarrgetname="Brick_Ether_$ethername_ProcPkts_On_".(str_replace("-","_",$brickname));
}
if ($whattograph=="dropped") {
    $runcommand="intdrop";
    $legendi="Dropped Packets";
    $ethername="Dropped Packets on ".$ethername;
    $tarrgetname="Brick_Ether_$ethername_DropPkts_On_".(str_replace("-","_",$brickname));
}
if ($whattograph=="ipsec") {
    $runcommand="intipsec";
    $legendi="IPSEC Packets";
    $ethername="IPSEC Packets on ".$ethername;
    $tarrgetname="Brick_$ethername_PIPSECPkts_On_".(str_replace("-","_",$brickname));
}
if ($whattograph=="brickinterfacecount") {
    $runcommand="brickinterfacecount";
    $legendi="Total Interfaces";
    $legendo="Active Interfaces";
    $ethername="Interface Count on $brickname";
    $tarrgetname="Brick_".(str_replace("-","_",$brickname))."_InterfaceCount";
    $mrtgoptions = "$mrtgoptions ,gauge";
    $intspeed = "16";
}


$legendy=$legendi;

if ($whattograph=="bisio") { 
    $runcommand=$whattograph;
    $legendy="Octets";
    $legendi="Octets";
    $legendo="Octets";
    $ethername="Ethernet Octet Stats for Ether$brickinterface on Brick $brickname";
    $tarrgetname="Brick_".(str_replace("-","_",$brickname))."_Ether".$brickinterface."_Octets";
}

if ($whattograph=="bisunicast") { 
    $runcommand=$whattograph;
    $legendy="Unicast Octets";
    $legendi="Unicast";
    $legendo="Unicast";
    $ethername="Ethernet Unicast Octet Stats for Ether$brickinterface on Brick $Brickname";
    $tarrgetname="Brick_".(str_replace("-","_",$brickname))."_Ether".$brickinterface."_UniCastOctets";
}

if ($whattograph=="bismulticast") {
    $runcommand=$whattograph;
    $legendy="Mcast Octets";
    $legendi="Mcast";
    $legendo="Mcast";
    $ethername="Ethernet Multicast Octet Stats for Ether$brickinterface on Brick $Brickname";
    $tarrgetname="Brick_".(str_replace("-","_",$brickname))."_Ether".$brickinterface."_MultiCastOctets";
}

if ($whattograph=="bisdiscards") { 
    $runcommand=$whattograph;
    $legendy="Discards";
    $legendo="Discards";
    $legendi="Discards";
    $ethername="Ethernet Discard Stats for Ether$brickinterface on Brick $Brickname";
    $tarrgetname="Brick_".(str_replace("-","_",$brickname))."_Ether".$brickinterface."_Discards";
}

if ($whattograph=="biserrors") { 
    $runcommand=$whattograph;
    $legendy="Errors";
    $legendo="Errors";
    $legendi="Errors";
    $ethername="Ethernet Error Stats for Ether$brickinterface on Brick $Brickname";
    $tarrgetname="Brick_".(str_replace("-","_",$brickname))."_Ether".$brickinterface."_Errors";
}

if ($whattograph=="bisbroad") {
    $runcommand=$whattograph;
    $legendy="Broadcasts";
    $legendo="Broadcasts";
    $legendi="Broadcasts";
    $ethername="Ethernet Broadcast Stats for Ether$brickinterface on Brick $Brickname";
    $tarrgetname="Brick_".(str_replace("-","_",$brickname))."_Ether".$brickinterface."_Broadcast";
}

if ($whattograph=="bisunknown") { 
    $runcommand=$whattograph;
    $legendy="Unknown Pro";
    $legendo="Unknown Protocols";
    $ethername="Ethernet Unknown Protocols Stats for Ether$brickinterface on Brick $Brickname";
    $tarrgetname="Brick_".(str_replace("-","_",$brickname))."_Ether".$brickinterface."_Unknown";
}

$filewrite="options[".covfromspace("_",$tarrgetname)."]: $mrtgoptions
Target[".covfromspace("_",$tarrgetname)."]: `$phpexe -q $snmpmrtginstalldir/mrtg.php runcommand=$runcommand host=$host community=$community brickname=$brickname brickinterface=$brickinterface`
MaxBytes[".covfromspace("_",$tarrgetname)."]: $intspeed
Title[".covfromspace("_",$tarrgetname)."]: $ethername
ShortLegend[".covfromspace("_",$tarrgetname)."]: $legendi
YLegend[".covfromspace("_",$tarrgetname)."]: $legendy
LegendI[".covfromspace("_",$tarrgetname)."]: $legendi
LegendO[".covfromspace("_",$tarrgetname)."]: $legendo
PageTop[".covfromspace("_",$tarrgetname)."]: <H1>$ethername</H1>
Background[".covfromspace("_",$tarrgetname)."]: $globalbgcolour

";


if ($whattograph=="activebricks") {
    $runcommand="activebricks";
    $legendi="Bricks";
    $brickname="LSMS_Server";
    $ethername="Active Bricks on LSMS $host";
    $brickname="LSMS_SERVER";
    $tarrgetname="LSMS_".$host."_ActiveBricks";
    $mrtgoptions = "$mrtgoptions ,gauge";
    $intspeed = "100";

$filewrite="options[".covfromspace("_",$tarrgetname)."]: $mrtgoptions
Target[".covfromspace("_",$tarrgetname)."]: .1.3.6.1.4.1.1751.1.56.1.1.2.1.0&.1.3.6.1.4.1.1751.1.56.1.1.2.1.0:$community@$host:
MaxBytes[".covfromspace("_",$tarrgetname)."]: $intspeed
Title[".covfromspace("_",$tarrgetname)."]: $ethername
ShortLegend[".covfromspace("_",$tarrgetname)."]: $legendi
YLegend[".covfromspace("_",$tarrgetname)."]: $legendy
LegendI[".covfromspace("_",$tarrgetname)."]: $legendi
LegendO[".covfromspace("_",$tarrgetname)."]: $legendo
PageTop[".covfromspace("_",$tarrgetname)."]: <H1>$ethername</H1>
Background[".covfromspace("_",$tarrgetname)."]: $globalbgcolour

";

}


$newfilewrite=$mrtgtop.$filewrite;

if (file_exists($lsmsmrtgfile)) {
    // append into file
    if (!$handle = fopen($lsmsmrtgfile, 'a')) {
        print "Cannot open file ($lsmsmrtgfile)";
        fclose ($handle);
        exit;
    }
    if (!fwrite($handle, $filewrite)) {
        print "Cannot write to file ($lsmsmrtgfile)";
        fclose ($handle);
        exit;
    }
    echo "<CENTER><font size=+2><B>File Updated</b></font><BR><BR><HR><B>".$lsmsmrtgfile."<HR>";


}
else
{
    // create new file
    if (!$handle = fopen($lsmsmrtgfile, 'w')) {
        print "Cannot open file ($lsmsmrtgfile)";
        fclose ($handle);
        exit;
    }
    $newfilewrite=$mrtgtop.$filewrite;
    if (!fwrite($handle, $newfilewrite)) {
        print "Cannot write to file ($lsmsmrtgfile)";
        fclose ($handle);
        exit;
    }

    echo "<CENTER><font size=+2><B>File Created</b></font><BR><BR><HR><B>".$lsmsmrtgfile."<HR>";
}
jsbackindow();
?>
Return current item: LSMS SNMP to MRTG toolset