[BACK]Return to envstat2mrtg CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / net / mrtg / files

File: [cvs.NetBSD.org] / pkgsrc / net / mrtg / files / envstat2mrtg (download)

Revision 1.4, Tue Oct 27 20:32:14 2015 UTC (5 years, 11 months ago) by bsiegert
Branch: MAIN
CVS Tags: pkgsrc-2021Q3-base, pkgsrc-2021Q3, pkgsrc-2021Q2-base, pkgsrc-2021Q2, pkgsrc-2021Q1-base, pkgsrc-2021Q1, pkgsrc-2020Q4-base, pkgsrc-2020Q4, pkgsrc-2020Q3-base, pkgsrc-2020Q3, pkgsrc-2020Q2-base, pkgsrc-2020Q2, pkgsrc-2020Q1-base, pkgsrc-2020Q1, pkgsrc-2019Q4-base, pkgsrc-2019Q4, pkgsrc-2019Q3-base, pkgsrc-2019Q3, pkgsrc-2019Q2-base, pkgsrc-2019Q2, pkgsrc-2019Q1-base, pkgsrc-2019Q1, pkgsrc-2018Q4-base, pkgsrc-2018Q4, pkgsrc-2018Q3-base, pkgsrc-2018Q3, pkgsrc-2018Q2-base, pkgsrc-2018Q2, pkgsrc-2018Q1-base, pkgsrc-2018Q1, pkgsrc-2017Q4-base, pkgsrc-2017Q4, pkgsrc-2017Q3-base, pkgsrc-2017Q3, pkgsrc-2017Q2-base, pkgsrc-2017Q2, pkgsrc-2017Q1-base, pkgsrc-2017Q1, pkgsrc-2016Q4-base, pkgsrc-2016Q4, pkgsrc-2016Q3-base, pkgsrc-2016Q3, pkgsrc-2016Q2-base, pkgsrc-2016Q2, pkgsrc-2016Q1-base, pkgsrc-2016Q1, pkgsrc-2015Q4-base, pkgsrc-2015Q4, HEAD
Changes since 1.3: +3 -3 lines

Remove -n0 from envstat invocations, PR pkg/50352.

#! @PREFIX@/bin/perl
#	$NetBSD: envstat2mrtg,v 1.4 2015/10/27 20:32:14 bsiegert Exp $

if (@ARGV == 1)
{
	open(CMDOUT, "envstat -s '@ARGV[0]'|");
	$line = <CMDOUT>;
	chop $line;
	if ($line =~ m|^[\s\t]+(\w+)$|)
	{
		print "$1\n";
	}
	elsif ($line =~ m|^[\s\t]+(\w+\.\w+)$|)
	{
		$val = $1  * 100;
		print "$val\n";
	}
	else
	{
		print "0\n";
	}
	print "0\n";
	&end();
}

if (@ARGV == 2)
{
	open(CMDOUT, "envstat -s '@ARGV[0],@ARGV[1]'|");
	$line = <CMDOUT>;
	if ($line =~ m|^[\s\t]+(\w+)[\s\t]+(\w+)$|)
	{
		print "$1\n";
		print "$2\n";
	}
	elsif ($line =~ m|^[\s\t]+(\w+\.\w+)[\s\t]+(\w+\.\w+)$|)
	{
		$val = $1 * 100;
		print "$val\n";
		$val = $2 * 100;
		print "$val\n";
	}
	else
	{
		print "0\n";
		print "0\n";
	}
	&end();
}

print STDERR
	"usage: envstat2mrtg sens1 [sens2]\n";
exit(1);

sub end
{
	open(UP, "uptime|");
	while($line = <UP>)
	{
		chop $line;
		if ($line =~ m|^.*up\s+(.+),\s+\d+\suser.*|)
		{
			print "$1\n";
		}
	}
	close(UP);
	open(HOST, "hostname|");
	while (<HOST>)
	{
		s/\..*//;
		print $_;
	}
	exit(0);
}