From 1c9fb9df72fda2bb8126b5d4747b7251cbdf5d56 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sat, 19 Dec 2009 23:26:37 +0100 Subject: [PATCH] use config files --- .gitignore | 2 + apc-with-measureups.conf | 93 +++++++++++++++++++++++++++++++ apc.conf | 79 ++++++++++++++++++++++++++ upsgraph.pl | 116 ++++++++------------------------------- 4 files changed, 196 insertions(+), 94 deletions(-) create mode 100644 .gitignore create mode 100644 apc-with-measureups.conf create mode 100644 apc.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d6e95f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.conf +*.rrd diff --git a/apc-with-measureups.conf b/apc-with-measureups.conf new file mode 100644 index 0000000..5480113 --- /dev/null +++ b/apc-with-measureups.conf @@ -0,0 +1,93 @@ +package UPSGRAPH; + +$host="192.168.34.253"; +$rrdfile="/var/www/usv/.work/ups.rrd"; +$outdir="/var/www/usv/"; +$community="public"; +$step=60; + +@fields = ( 'inputV', 'outputV', 'inputHZ', 'outputHZ', 'battT', 'battC', 'load', 'ambT', 'ambH', 'timeR', 'timeO' ); + +$vars = { + 'inputV' => { + 'name' => 'Input Voltage', + 'oidtext' => 'PowerNet-MIB::upsAdvInputLineVoltage.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.3.2.1.0', + 'min' => '180', + 'max' => '280', + }, + 'outputV' => { + 'name' => 'Output Voltage', + 'oidtext' => 'PowerNet-MIB::upsAdvOutputVoltage.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.1.0', + 'min' => '180', + 'max' => '280', + }, + 'inputHZ' => { + 'name' => 'Input Frequency', + 'oidtext' => 'PowerNet-MIB::upsAdvInputFrequency.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.3.2.4.0', + 'min' => '40', + 'max' => '60', + }, + 'outputHZ' => { + 'name' => 'Output Frequency', + 'oidtext' => 'PowerNet-MIB::upsAdvOutputFrequency.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.2.0', + 'min' => '40', + 'max' => '60', + }, + 'battT' => { + 'name' => 'Battery Temperature', + 'oidtext' => 'PowerNet-MIB::upsAdvBatteryTemperature.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.2.0', + 'min' => '0', + 'max' => '100', + }, + 'battC' => { + 'name' => 'Battery Capacity', + 'oidtext' => 'PowerNet-MIB::upsAdvBatteryCapacity.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.1.0', + 'min' => '0', + 'max' => '110', + }, + 'load' => { + 'name' => 'UPS Load', + 'oidtext' => 'PowerNet-MIB::upsAdvOutputLoad.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.3.0', + 'min' => '0', + 'max' => '110', + }, + 'ambT' => { + 'name' => 'Ambient Temperature', + 'oidtext' => 'PowerNet-MIB::mUpsEnvironAmbientTemperature.0', + 'oid' => '1.3.6.1.4.1.318.1.1.2.1.1.0', + 'min' => '0', + 'max' => '60', + }, + 'ambH' => { + 'name' => 'Ambient Humidity', + 'oidtext' => 'PowerNet-MIB::mUpsEnvironRelativeHumidity.0', + 'oid' => '1.3.6.1.4.1.318.1.1.2.1.2.0', + 'min' => '0', + 'max' => '100', + }, + 'timeR' => { + 'name' => 'Time Remaining', + 'oidtext' => 'PowerNet-MIB::upsAdvBatteryRunTimeRemaining.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.3.0', + 'factor' => 1/6000, + 'min' => '0', + 'max' => '360', + }, + 'timeO' => { + 'name' => 'Time On Battery', + 'oidtext' => 'PowerNet-MIB::upsBasicBatteryTimeOnBattery.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.2.1.2.0', + 'factor' => 1/6000, + 'min' => '0', + 'max' => '360', + }, +}; + +1; diff --git a/apc.conf b/apc.conf new file mode 100644 index 0000000..6d0c895 --- /dev/null +++ b/apc.conf @@ -0,0 +1,79 @@ +package UPSGRAPH; + +$host="10.50.252.253"; +$rrdfile="/var/www/usv/.work/ups.rrd"; +$outdir="/var/www/usv/"; +$community="public"; +$step=60; + +@fields = ( 'inputV', 'outputV', 'inputHZ', 'outputHZ', 'battT', 'battC', 'load', 'timeR', 'timeO' ); + +$vars = { + 'inputV' => { + 'name' => 'Input Voltage', + 'oidtext' => 'PowerNet-MIB::upsAdvInputLineVoltage.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.3.2.1.0', + 'min' => '180', + 'max' => '280', + }, + 'outputV' => { + 'name' => 'Output Voltage', + 'oidtext' => 'PowerNet-MIB::upsAdvOutputVoltage.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.1.0', + 'min' => '180', + 'max' => '280', + }, + 'inputHZ' => { + 'name' => 'Input Frequency', + 'oidtext' => 'PowerNet-MIB::upsAdvInputFrequency.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.3.2.4.0', + 'min' => '40', + 'max' => '60', + }, + 'outputHZ' => { + 'name' => 'Output Frequency', + 'oidtext' => 'PowerNet-MIB::upsAdvOutputFrequency.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.2.0', + 'min' => '40', + 'max' => '60', + }, + 'battT' => { + 'name' => 'Battery Temperature', + 'oidtext' => 'PowerNet-MIB::upsAdvBatteryTemperature.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.2.0', + 'min' => '0', + 'max' => '100', + }, + 'battC' => { + 'name' => 'Battery Capacity', + 'oidtext' => 'PowerNet-MIB::upsAdvBatteryCapacity.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.1.0', + 'min' => '0', + 'max' => '110', + }, + 'load' => { + 'name' => 'UPS Load', + 'oidtext' => 'PowerNet-MIB::upsAdvOutputLoad.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.3.0', + 'min' => '0', + 'max' => '110', + }, + 'timeR' => { + 'name' => 'Time Remaining', + 'oidtext' => 'PowerNet-MIB::upsAdvBatteryRunTimeRemaining.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.3.0', + 'factor' => 1/6000, + 'min' => '0', + 'max' => '360', + }, + 'timeO' => { + 'name' => 'Time On Battery', + 'oidtext' => 'PowerNet-MIB::upsBasicBatteryTimeOnBattery.0', + 'oid' => '1.3.6.1.4.1.318.1.1.1.2.1.2.0', + 'factor' => 1/6000, + 'min' => '0', + 'max' => '360', + }, +}; + +1; diff --git a/upsgraph.pl b/upsgraph.pl index bef10a5..020569f 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -1,110 +1,38 @@ #!/usr/bin/perl -w -if ((@ARGV != 3) && (@ARGV != 4)) { - print STDERR "Syntax: ${0} host /path/to/file.rrd /output/directory/ [uid]\n"; +if ((@ARGV != 1) && (@ARGV != 2)) { + print STDERR "Syntax: ${0} configfile [uid]\n"; exit(1); } -my $host=$ARGV[0]; -my $rrdfile=$ARGV[1]; -my $outdir=$ARGV[2]; -my $community="public"; -my $step=60; - -my @fields = ( 'inputV', 'outputV', 'inputHZ', 'outputHZ', 'battT', 'battC', 'load', 'ambT', 'ambH', 'timeR', 'timeO' ); - -my $vars = { - 'inputV' => { - 'name' => 'Input Voltage', - 'oidtext' => 'PowerNet-MIB::upsAdvInputLineVoltage.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.3.2.1.0', - 'min' => '180', - 'max' => '280', - }, - 'outputV' => { - 'name' => 'Output Voltage', - 'oidtext' => 'PowerNet-MIB::upsAdvOutputVoltage.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.1.0', - 'min' => '180', - 'max' => '280', - }, - 'inputHZ' => { - 'name' => 'Input Frequency', - 'oidtext' => 'PowerNet-MIB::upsAdvInputFrequency.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.3.2.4.0', - 'min' => '40', - 'max' => '60', - }, - 'outputHZ' => { - 'name' => 'Output Frequency', - 'oidtext' => 'PowerNet-MIB::upsAdvOutputFrequency.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.2.0', - 'min' => '40', - 'max' => '60', - }, - 'battT' => { - 'name' => 'Battery Temperature', - 'oidtext' => 'PowerNet-MIB::upsAdvBatteryTemperature.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.2.0', - 'min' => '0', - 'max' => '100', - }, - 'battC' => { - 'name' => 'Battery Capacity', - 'oidtext' => 'PowerNet-MIB::upsAdvBatteryCapacity.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.1.0', - 'min' => '0', - 'max' => '110', - }, - 'load' => { - 'name' => 'UPS Load', - 'oidtext' => 'PowerNet-MIB::upsAdvOutputLoad.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.3.0', - 'min' => '0', - 'max' => '110', - }, - 'ambT' => { - 'name' => 'Ambient Temperature', - 'oidtext' => 'PowerNet-MIB::mUpsEnvironAmbientTemperature.0', - 'oid' => '1.3.6.1.4.1.318.1.1.2.1.1.0', - 'min' => '0', - 'max' => '60', - }, - 'ambH' => { - 'name' => 'Ambient Humidity', - 'oidtext' => 'PowerNet-MIB::mUpsEnvironRelativeHumidity.0', - 'oid' => '1.3.6.1.4.1.318.1.1.2.1.2.0', - 'min' => '0', - 'max' => '100', - }, - 'timeR' => { - 'name' => 'Time Remaining', - 'oidtext' => 'PowerNet-MIB::upsAdvBatteryRunTimeRemaining.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.3.0', - 'factor' => 1/6000, - 'min' => '0', - 'max' => '360', - }, - 'timeO' => { - 'name' => 'Time On Battery', - 'oidtext' => 'PowerNet-MIB::upsBasicBatteryTimeOnBattery.0', - 'oid' => '1.3.6.1.4.1.318.1.1.1.2.1.2.0', - 'factor' => 1/6000, - 'min' => '0', - 'max' => '360', - }, -}; - use Net::SNMP; +$UPSGRAPH::host = ""; +$UPSGRAPH::rrdfile = ""; +$UPSGRAPH::outdir = ""; +$UPSGRAPH::community = "public"; +$UPSGRAPH::step = 60; +@UPSGRAPH::fields = (); +$UPSGRAPH::vars = {}; + +do $ARGV[0] or die "can't read config: $!"; + +my $host = $UPSGRAPH::host; +my $rrdfile = $UPSGRAPH::rrdfile; +my $outdir = $UPSGRAPH::outdir; +my $community = $UPSGRAPH::community; +my $step = $UPSGRAPH::step; +my @fields = @UPSGRAPH::fields; +my $vars = $UPSGRAPH::vars; + if ($> == 0) { - if (@ARGV != 4) { + if (@ARGV != 2) { print STDERR "Running as root, please provide UID as 4th argument!\n"; exit(1); } print "Running as root, switching to ".$ARGV[3]."\n"; - $< = $> = $ARGV[3]; + $< = $> = $ARGV[1]; } if (! -e "${rrdfile}") { -- 2.39.5