#!/usr/bin/perl
#
# aoserv-mrtg - MRTG configured by the AOServ Platform.
# Copyright (C) 2016, 2018  AO Industries, Inc.
#     support@aoindustries.com
#     7262 Bull Pen Cir
#     Mobile, AL 36695
#
# This file is part of aoserv-mrtg.
#
# aoserv-mrtg is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# aoserv-mrtg 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with aoserv-mrtg.  If not, see <http://www.gnu.org/licenses/>.
#

$device=$ARGV[0];
open PROC, "/proc/net/dev";
while(<PROC>) {
	chop($_);
	if(substr($_, 0, 5) ne 'Inter') {
		($iface, $inbytes, $outbytes)=($_=~ /\s+(\S+):\s*(\S+)\s+(?:\S+\s+){7}(\S+)/sm);
		if($iface eq $device) {
			printf "%.0f\n%.0f\n1\n", $inbytes*8, $outbytes*8;
			last;
		}
	}
}
close PROC;
