AdrianOnTech.net

MRTG, modified alias names template for TP-LINK TL-SG2424

December 06, 2016

MRTG, modified alias names template for TP-LINK TL-SG2424

This perl code snip replaces the builtin messy template within MRTG cfgmaker, with one that cleanly shows alias names and interface speed alongside the activity chart for each port.



1. Save the following as cfgtemplate.

$target_lines .= <<ECHO;

Target[$target_name]: $if_ref:$router_connect
SetEnv[$target_name]: MRTG_INT_IP="$if_ip" MRTG_INT_DESCR="$if_snmp_descr"
ECHO
if ($directory_name) {
$target_lines .= "Directory[$target_name]: $directory_name\n";
}

$target_lines .= <<ECHO;
MaxBytes[$target_name]: $if_speed
Title[$target_name]: $html_if_title_desc
PageTop[$target_name]: <h1>Port $if_index -- $html_if_snmp_alias @ $if_speed_str</h1>
<div id="sysdetails">
<table>
<tr>
<td>System:</td>
<td>$sysname in $html_syslocation</td>
</tr>
<tr>
<td>Maintainer:</td>
<td>$html_syscontact</td>
</tr>
<tr>
<td>Description:</td>
<td>$html_if_description</td>
</tr>
<tr>
<td>ifType:</td>
<td>$html_if_type_desc ($if_type_num)</td>
</tr>
<tr>
<td>ifName:</td>
<td>$html_if_snmp_name</td>
</tr>
ECHO

$target_lines .= <<ECHO if defined $if_port_name;
<tr>
<td>Port Name:</td>
<td>$if_port_name</td>
</tr>
ECHO

$target_lines .= <<ECHO if defined $if_pp_port_name;
<tr>
<td>Port Name:</td>
<td>$if_pp_port_name</td>
</tr>
ECHO

$target_lines .= <<ECHO;
<tr>
<td>Max Speed:</td>
<td>$if_speed_str</td>
</tr>
ECHO

$target_lines .= <<ECHO if $if_ip;
<tr>
<td>Ip:</td>
<td>$if_ip ($if_dns_name)</td>
</tr>
ECHO

$target_lines .= <<ECHO;
</table>
</div>
ECHO

2. Use this script to build the /etc/mrtg.cfg configuration file and HTML index structure.

#!/bin/bash

cfgmaker \
--global "options[_]: growright,bits" \
--global 'WorkDir: /var/www/mrtg' \
--if-template=/home/john/Documents/mrtg-setup/cfgtemplate \
--ifref=nr \
--ifdesc=alias \
--no-down \
--nodefaultglobal \
--zero-speed=100000000 \
--output=/etc/mrtg.cfg \
inside@switch.lan

indexmaker \
--title="Traffic graphs for switch.lan" \
--subtitle="Green is device output (or switch input) traffic." \
--columns=3 /etc/mrtg.cfg > /var/www/mrtg/index.html


No comments :

Post a Comment

Image Overlay