Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / snmp / snmp_room_alert_ @ b0b39b01

Historique | Voir | Annoter | Télécharger (2,78 ko)

1
#!/usr/bin/env ruby
2
# encoding: utf-8
3

    
4
# Plugin to monitor Room Alert 11E environmental units.
5
# Requires ruby and the ruby SNMP library.
6
#
7
# Written by Phil Gold <phil_g@pobox.com>.
8
#
9
# Usage: Copy or link into /etc/munin/node.d/.  End word can be either
10
#        "temperature" or "humidity".
11
#
12
# Parameters:
13
#
14
# 	config   (required)
15
# 	autoconf (optional - used by munin-config)
16
#
17
# Config variables:
18
#
19
#       units     - DNS names of environmental units
20
#       community - Community to use to access the Room Alert unit
21
#                   Defaults to 'public'.
22
#       variables of the form label_<unit>_<num>, where dots and dashes in the
23
#         unit names are replaced with underscores - labels for specific sensors
24
#         in the unit.
25
#         e.g. env.label_192_168_1_115_2 Main Unit
26
#
27
# Example config:
28
#
29
#       [room_alert_*]
30
#       env.units unit1.example.com unit2.example.com
31
#       env.community private
32
#       env.label_unit1_example_com_2 Main Unit
33
#       env.label_unit1_example_com_3 Rack 2 Sensor
34

    
35
require 'snmp'
36

    
37
base_oid = "enterprises.20916.1.3.1"
38

    
39
case $0.match('[^_]+$')[0]
40
when "temperature"
41
  subchannel = 1
42
  name = "temperature"
43
  label = "°C"
44
  letter = "t"
45
when "humidity"
46
  subchannel = 3
47
  name = "humidity"
48
  label = "% Relative Humidity"
49
  letter = "h"
50
else
51
  exit 1
52
end
53

    
54
def is_vb_valid(vb, subchannel)
55
  return (vb.name[-1] == 0 and vb.name[-2] == subchannel and vb.value > 1)
56
end
57

    
58
def field_name(unit, vb, letter)
59
  clean_unit = unit.gsub(/[.-]/, '_')
60
  sensor = vb.name[-3].to_s
61
  return "#{clean_unit}_#{letter}#{sensor}"
62
end
63

    
64
def label(unit, vb)
65
  clean_unit = unit.gsub(/[.-]/, '_')
66
  sensor = vb.name[-3].to_s
67
  label = "#{unit} " + (ENV["label_#{clean_unit}_#{sensor}"] || "sensor #{sensor}")
68
end
69

    
70
units = (ENV['units'] || "").split(/\s+/)
71
community = ENV['community'] || "public"
72

    
73
case ARGV[0]
74
when "autoconf"
75
  puts "no"
76
  exit 0
77
when "config"
78
  puts "graph_title Room Alert 11E units (#{name} probes)"
79
  puts "graph_vlabel #{label}"
80
  puts "graph_category sensors"
81
  if name == "humidity"
82
    puts "graph_args --lower-limit 0 --upper-limit 100"
83
  end
84
  units.each do |unit|
85
    SNMP::Manager.open(:Host => unit,
86
                       :Community => community,
87
                       :Version => :SNMPv1) do |manager|
88
      manager.walk(base_oid) do |vb|
89
        if not is_vb_valid(vb, subchannel)
90
          next
91
        end
92

    
93
        puts "#{field_name(unit, vb, letter)}.label #{label(unit, vb)}"
94
      end
95
    end
96
  end
97
  exit 0
98
end
99

    
100
units.each do |unit|
101
  SNMP::Manager.open(:Host => unit,
102
                     :Community => community,
103
                     :Version => :SNMPv1) do |manager|
104
    manager.walk(base_oid) do |vb|
105
      if not is_vb_valid(vb, subchannel)
106
        next
107
      end
108

    
109
      puts "#{field_name(unit, vb, letter)}.value #{vb.value.to_f / 100}"
110
    end
111
  end
112
end