root / plugins / snmp / snmp__cyberpower @ 56bcc8cd
Historique | Voir | Annoter | Télécharger (4,05 ko)
| 1 | 56bcc8cd | Kai | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | |||
| 3 | =head1 NAME |
||
| 4 | |||
| 5 | Monitor CyberPower UPS Battery Status. |
||
| 6 | |||
| 7 | |||
| 8 | =head1 AUTHOR |
||
| 9 | |||
| 10 | Kai Boenke |
||
| 11 | |||
| 12 | =head1 LICENSE |
||
| 13 | |||
| 14 | Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) |
||
| 15 | |||
| 16 | =back |
||
| 17 | |||
| 18 | |||
| 19 | ##### |
||
| 20 | # Enable SNMP-Discovery |
||
| 21 | ### |
||
| 22 | =head1 MAGIC MARKERS |
||
| 23 | #%# family=snmpauto |
||
| 24 | #%# capabilities=snmpconf |
||
| 25 | =cut |
||
| 26 | if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
|
||
| 27 | print "require 1.3.6.1.2.1.33.1.2.4.0\n"; |
||
| 28 | exit 0; |
||
| 29 | } |
||
| 30 | |||
| 31 | |||
| 32 | ##### |
||
| 33 | # Initialize |
||
| 34 | ### |
||
| 35 | use strict; |
||
| 36 | use Munin::Plugin::SNMP; |
||
| 37 | my $session = Munin::Plugin::SNMP->session(); |
||
| 38 | |||
| 39 | |||
| 40 | ##### |
||
| 41 | # Declare OIDs |
||
| 42 | ### |
||
| 43 | use constant oid_cps_battery_runtime => ".1.3.6.1.2.1.33.1.2.3.0"; |
||
| 44 | use constant oid_cps_battery_charge => ".1.3.6.1.2.1.33.1.2.4.0"; |
||
| 45 | use constant oid_cps_input_voltage => ".1.3.6.1.2.1.33.1.3.3.1.3.1"; |
||
| 46 | use constant oid_cps_output_voltage => ".1.3.6.1.2.1.33.1.4.4.1.2.1"; |
||
| 47 | use constant oid_cps_output_load => ".1.3.6.1.2.1.33.1.4.4.1.5.1"; |
||
| 48 | use constant oid_cps_env_temp => ".1.3.6.1.4.1.3808.1.1.4.2.1.0"; |
||
| 49 | use constant oid_cps_env_humidity => ".1.3.6.1.4.1.3808.1.1.4.3.1.0"; |
||
| 50 | |||
| 51 | |||
| 52 | ##### |
||
| 53 | # Config |
||
| 54 | ### |
||
| 55 | if (defined $ARGV[0] and $ARGV[0] eq "config") {
|
||
| 56 | my ($host) = Munin::Plugin::SNMP->config_session(); |
||
| 57 | print "host_name $host\n" unless $host eq 'localhost'; |
||
| 58 | print "multigraph cyberpower_load |
||
| 59 | graph_title CyberPower UPS Status |
||
| 60 | graph_info This graph shows battery status information. |
||
| 61 | graph_category ups |
||
| 62 | graph_vlabel % |
||
| 63 | graph_args --upper-limit 100 -l 0 |
||
| 64 | graph_scale no |
||
| 65 | "; |
||
| 66 | print "load.label Total load |
||
| 67 | load.draw AREA |
||
| 68 | load.type GAUGE |
||
| 69 | load.min 0 |
||
| 70 | load.max 100 |
||
| 71 | "; |
||
| 72 | print "charge.label Battery charge |
||
| 73 | charge.draw LINE1 |
||
| 74 | charge.type GAUGE |
||
| 75 | charge.min 0 |
||
| 76 | charge.max 100 |
||
| 77 | "; |
||
| 78 | |||
| 79 | print "multigraph cyberpower_runtime |
||
| 80 | graph_title CyberPower UPS Runtime |
||
| 81 | graph_info This graph shows expected runtime informatiom. |
||
| 82 | graph_category ups |
||
| 83 | graph_vlabel minutes |
||
| 84 | "; |
||
| 85 | print "runtime.label Expected runtime |
||
| 86 | runtime.draw AREA |
||
| 87 | runtime.type GAUGE |
||
| 88 | "; |
||
| 89 | |||
| 90 | print "multigraph cyberpower_voltage |
||
| 91 | graph_title CyberPower UPS Voltages |
||
| 92 | graph_info This graph shows voltage information. |
||
| 93 | graph_category ups |
||
| 94 | graph_vlabel V |
||
| 95 | "; |
||
| 96 | print "input.label Input voltage |
||
| 97 | input.draw LINE2 |
||
| 98 | input.type GAUGE |
||
| 99 | "; |
||
| 100 | print "output.label Output voltage |
||
| 101 | output.draw LINE1 |
||
| 102 | output.type GAUGE |
||
| 103 | "; |
||
| 104 | |||
| 105 | if(oidExists(oid_cps_env_temp) && oidExists(oid_cps_env_humidity)){
|
||
| 106 | print "multigraph cyberpower_environment |
||
| 107 | graph_title CyberPower UPS Environment |
||
| 108 | graph_info This graph shows environmental status information. |
||
| 109 | graph_category ups |
||
| 110 | graph_vlabel F/% |
||
| 111 | "; |
||
| 112 | print "temp.label Temperature |
||
| 113 | temp.draw LINE2 |
||
| 114 | temp.type GAUGE |
||
| 115 | "; |
||
| 116 | print "humidity.label Humidity |
||
| 117 | humidity.draw LINE1 |
||
| 118 | humidity.type GAUGE |
||
| 119 | humidity.min 0 |
||
| 120 | humidity.max 100 |
||
| 121 | "; |
||
| 122 | } |
||
| 123 | |||
| 124 | exit 0; |
||
| 125 | } |
||
| 126 | |||
| 127 | |||
| 128 | ##### |
||
| 129 | # Get Values |
||
| 130 | ### |
||
| 131 | |||
| 132 | print "multigraph cyberpower_load\n"; |
||
| 133 | my $load = $session->get_single(oid_cps_output_load); |
||
| 134 | my $charge = $session->get_single(oid_cps_battery_charge); |
||
| 135 | if($load ne 'U'){
|
||
| 136 | print "load.value ", $load, "\n"; |
||
| 137 | } |
||
| 138 | if($charge ne 'U'){
|
||
| 139 | print "charge.value ", $charge, "\n"; |
||
| 140 | } |
||
| 141 | |||
| 142 | print "multigraph cyberpower_runtime\n"; |
||
| 143 | my $runtime = $session->get_single(oid_cps_battery_runtime); |
||
| 144 | if($runtime ne 'U'){
|
||
| 145 | print "runtime.value ", $runtime, "\n"; |
||
| 146 | } |
||
| 147 | |||
| 148 | print "multigraph cyberpower_voltage\n"; |
||
| 149 | my $input = $session->get_single(oid_cps_input_voltage); |
||
| 150 | my $output = $session->get_single(oid_cps_output_voltage); |
||
| 151 | if($input ne 'U'){
|
||
| 152 | print "input.value ", $input, "\n"; |
||
| 153 | } |
||
| 154 | if($output ne 'U'){
|
||
| 155 | print "output.value ", $output, "\n"; |
||
| 156 | } |
||
| 157 | |||
| 158 | if(oidExists(oid_cps_env_temp) && oidExists(oid_cps_env_humidity)){
|
||
| 159 | print "multigraph cyberpower_environment\n"; |
||
| 160 | my $temp = $session->get_single(oid_cps_env_temp); |
||
| 161 | my $humidity = $session->get_single(oid_cps_env_humidity); |
||
| 162 | if($temp ne 'U'){
|
||
| 163 | $temp /= 10; |
||
| 164 | print "temp.value ", $temp, "\n"; |
||
| 165 | } |
||
| 166 | if($humidity ne 'U'){
|
||
| 167 | print "humidity.value ", $humidity, "\n"; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | ##### |
||
| 172 | # Subroutines |
||
| 173 | ### |
||
| 174 | sub oidExists {
|
||
| 175 | if(not defined $_[0]) {
|
||
| 176 | exit 0; |
||
| 177 | } |
||
| 178 | my $oid = $_[0]; |
||
| 179 | my $val = $session->get_single($oid); |
||
| 180 | |||
| 181 | if(!length $val || $val eq 'noSuchInstance' || $val eq 'U'){
|
||
| 182 | return(0); |
||
| 183 | }else{
|
||
| 184 | return(1); |
||
| 185 | } |
||
| 186 | } |
