root / plugins / snmp / snmp__apc_ups2_ @ e09d236f
Historique | Voir | Annoter | Télécharger (5,39 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Jean-Samuel Reynaud <js.reynaud@free.fr> |
| 4 |
# base on snmp__if_ from Jimmy Olsen, Dagfinn Ilmari Mannsaaker |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or |
| 7 |
# modify it under the terms of the GNU General Public License |
| 8 |
# as published by the Free Software Foundation; version 2 dated June, |
| 9 |
# 1991. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software |
| 18 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
# |
| 20 |
# |
| 21 |
# Usage: |
| 22 |
# ln -s /usr/share/munin/node/plugins-auto/snmp__ups2_ /etc/munin/node.d/snmp_ups.address.loc_mode |
| 23 |
# with mode : batteryVoltage, batteryTemperature,inputVoltage,inputCurrent,inputFrequency,outputVoltage,outputCurrent,outputPower,outputPercentLoad,ChargeRemaining |
| 24 |
# |
| 25 |
|
| 26 |
#%# family=snmpauto |
| 27 |
#%# capabilities=snmpconf |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
use strict; |
| 32 |
use Net::SNMP; |
| 33 |
|
| 34 |
my $DEBUG = 0; |
| 35 |
|
| 36 |
my $host = $ENV{host} || undef;
|
| 37 |
my $port = $ENV{port} || 161;
|
| 38 |
my $community = $ENV{community} || "public";
|
| 39 |
my $mode = $ENV{mode} || undef;
|
| 40 |
|
| 41 |
my $response; |
| 42 |
|
| 43 |
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") |
| 44 |
{
|
| 45 |
print "require .1.3.6.1.2.1.33.1.2.7 [0-9]\n"; # Bat temp |
| 46 |
exit 0; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_ups2_(.+)$/) |
| 51 |
{
|
| 52 |
$host = $1; |
| 53 |
$mode = $2; |
| 54 |
if ($host =~ /^([^:]+):(\d+)$/) |
| 55 |
{
|
| 56 |
$host = $1; |
| 57 |
$port = $2; |
| 58 |
} |
| 59 |
} |
| 60 |
elsif (!defined($host)) |
| 61 |
{
|
| 62 |
print "# Debug: $0 -- $1 -- $2\n" if $DEBUG; |
| 63 |
die "# Error: couldn't understand what I'm supposed to monitor."; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
my $graphs = {
|
| 69 |
'batteryVoltage' => { 'title' => 'Battery Voltage',
|
| 70 |
'category' => 'network', |
| 71 |
'unit' => 'Volt', |
| 72 |
'value' => '.1.3.6.1.2.1.33.1.2.5'}, |
| 73 |
'batteryTemperature' => { 'title' => 'Battery Temperature',
|
| 74 |
'category' => 'network', |
| 75 |
'unit' => 'DegC', |
| 76 |
'value' => '.1.3.6.1.2.1.33.1.2.7'}, |
| 77 |
'inputVoltage' => { 'title' => 'Input Voltage',
|
| 78 |
'category' => 'network', |
| 79 |
'unit' => 'Volt', |
| 80 |
'list' => '.1.3.6.1.2.1.33.1.3.2', |
| 81 |
'value' => '.1.3.6.1.2.1.33.1.3.3.1.3'}, |
| 82 |
'inputCurrent' => { 'title' => 'Input Current',
|
| 83 |
'category' => 'network', |
| 84 |
'unit' => 'Watt', |
| 85 |
'list' => '.1.3.6.1.2.1.33.1.3.2', |
| 86 |
'value' => '.1.3.6.1.2.1.33.1.3.3.1.4'}, |
| 87 |
'inputFrequency' => { 'title' => 'Input Frequency',
|
| 88 |
'category' => 'network', |
| 89 |
'list' => '.1.3.6.1.2.1.33.1.3.2', |
| 90 |
'unit' => 'Hz', |
| 91 |
'value' => '.1.3.6.1.2.1.33.1.3.3.1.2'}, |
| 92 |
|
| 93 |
'outputVoltage' => { 'title' => 'Output Voltage',
|
| 94 |
'category' => 'network', |
| 95 |
'list' => '.1.3.6.1.2.1.33.1.4.3', |
| 96 |
'unit' => 'Hz', |
| 97 |
'value' => '.1.3.6.1.2.1.33.1.4.4.1.2'}, |
| 98 |
'outputCurrent' => { 'title' => 'Output Current',
|
| 99 |
'category' => 'network', |
| 100 |
'list' => '.1.3.6.1.2.1.33.1.4.3', |
| 101 |
'value' => '.1.3.6.1.2.1.33.1.4.4.1.3'}, |
| 102 |
'outputPower' => { 'title' => 'Output Power',
|
| 103 |
'category' => 'network', |
| 104 |
'list' => '.1.3.6.1.2.1.33.1.4.3', |
| 105 |
'unit' => 'Hz', |
| 106 |
'value' => '.1.3.6.1.2.1.33.1.4.4.1.4'}, |
| 107 |
|
| 108 |
'outputPercentLoad' => { 'title' => 'Output PercentLoad',
|
| 109 |
'category' => 'network', |
| 110 |
'list' => '.1.3.6.1.2.1.33.1.4.3', |
| 111 |
'unit' => '%', |
| 112 |
'value' => '.1.3.6.1.2.1.33.1.4.4.1.5'}, |
| 113 |
|
| 114 |
'ChargeRemaining' => { 'title' => 'Charge remaining',
|
| 115 |
'unit' => 'Seconds', |
| 116 |
'category' => 'network', |
| 117 |
'value' => '.1.3.6.1.2.1.33.1.2.4'} |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
my ($session, $error) = Net::SNMP->session( |
| 122 |
-hostname => $host, |
| 123 |
-community => $community, |
| 124 |
-port => $port |
| 125 |
); |
| 126 |
|
| 127 |
if (!defined ($session)) |
| 128 |
{
|
| 129 |
die "Croaking: $error"; |
| 130 |
} |
| 131 |
|
| 132 |
my $count_data = 1; |
| 133 |
if (defined $graphs->{$mode}->{'list'} &&
|
| 134 |
defined ($response = $session->get_request($graphs->{$mode}->{'list'} . ".0"))) {
|
| 135 |
$count_data = $response->{$graphs->{$mode}->{'list'} . ".0"};
|
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
if ($ARGV[0] and $ARGV[0] eq "config") |
| 140 |
{
|
| 141 |
print "host_name $host\n"; |
| 142 |
printf "graph_title %s \n",$graphs->{$mode}->{'title'};
|
| 143 |
# print "graph_args --base 1000\n"; |
| 144 |
print "graph_category sensors\n"; |
| 145 |
|
| 146 |
|
| 147 |
for(my $i=0;$i<$count_data;$i++) {
|
| 148 |
printf "line%u.label Line %u\n",$i+1,$i+1; |
| 149 |
printf "line%u.type GAUGE\n",$i+1; |
| 150 |
printf "line%u.info %s\n",$i+1,$graphs->{$mode}->{'unit'};
|
| 151 |
} |
| 152 |
exit 0; |
| 153 |
} |
| 154 |
|
| 155 |
for(my $i=0;$i<$count_data;$i++) {
|
| 156 |
my $l_current = $i+1; |
| 157 |
if ($count_data == 1) {
|
| 158 |
$l_current = 0; |
| 159 |
} |
| 160 |
if (defined ($response = $session->get_request($graphs->{$mode}->{'value'} . sprintf(".%u",$l_current)))) {
|
| 161 |
printf "line%u.value %u\n",$i+1,$response->{$graphs->{$mode}->{'value'} . sprintf(".%u",$l_current)};
|
| 162 |
} else {
|
| 163 |
printf "line%u.value U\n",$i+1; |
| 164 |
} |
| 165 |
|
| 166 |
} |
