Projet

Général

Profil

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

root / plugins / sensors / room_alert_ @ e5ce7492

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

1 92e747e9 Phil Gold
#!/usr/bin/ruby
2
3
# Plugin to monitor Room Alert 11E environmental units.
4
# Requires ruby and the ruby SNMP library.
5
#
6
# Written by Phil Gold <phil_g@pobox.com>.
7
#
8
# Usage: Copy or link into /etc/munin/node.d/.  End word can be either
9
#        "temperature" or "humidity".
10
#
11
# Parameters:
12
#
13
# 	config   (required)
14
# 	autoconf (optional - used by munin-config)
15
#
16
# Config variables:
17
#
18
#       units     - DNS names of environmental units
19
#       community - Community to use to access the Room Alert unit
20
#                   Defaults to 'public'.
21
#       variables of the form label_<unit>_<num>, where dots and dashes in the
22
#         unit names are replaced with underscores - labels for specific sensors
23
#         in the unit.
24
#         e.g. env.label_192_168_1_115_2 Main Unit
25
#
26
# Example config:
27
#
28
#       [room_alert_*]
29
#       env.units unit1.example.com unit2.example.com
30
#       env.community private
31
#       env.label_unit1_example_com_2 Main Unit
32
#       env.label_unit1_example_com_3 Rack 2 Sensor
33
34
require 'snmp'
35
36
base_oid = "enterprises.20916.1.3.1"
37
38
case $0.match('[^_]+$')[0]
39
when "temperature"
40
  subchannel = 1
41
  name = "temperature"
42
  label = "°C"
43
  letter = "t"
44
when "humidity"
45
  subchannel = 3
46
  name = "humidity"
47
  label = "% Relative Humidity"
48
  letter = "h"
49
else
50
  exit 1
51
end
52
53
def is_vb_valid(vb, subchannel)
54
  return (vb.name[-1] == 0 and vb.name[-2] == subchannel and vb.value > 1)
55
end
56
57
def field_name(unit, vb, letter)
58
  clean_unit = unit.gsub(/[.-]/, '_')
59
  sensor = vb.name[-3].to_s
60
  return "#{clean_unit}_#{letter}#{sensor}"
61
end
62
63
def label(unit, vb)
64
  clean_unit = unit.gsub(/[.-]/, '_')
65
  sensor = vb.name[-3].to_s
66
  label = "#{unit} " + (ENV["label_#{clean_unit}_#{sensor}"] || "sensor #{sensor}")
67
end
68
69
units = (ENV['units'] || "").split(/\s+/)
70
community = ENV['community'] || "public"
71
72
case ARGV[0]
73
when "autoconf"
74
  puts "no"
75
  exit 1
76
when "config"
77
  puts "graph_title Room Alert 11E units (#{name} probes)"
78
  puts "graph_vlabel #{label}"
79
  puts "graph_category sensors"
80
  if name == "humidity"
81
    puts "graph_args --lower-limit 0 --upper-limit 100"
82
  end
83
  units.each do |unit|
84
    SNMP::Manager.open(:Host => unit,
85
                       :Community => community,
86
                       :Version => :SNMPv1) do |manager|
87
      manager.walk(base_oid) do |vb|
88
        if not is_vb_valid(vb, subchannel)
89
          next
90
        end
91
        puts "#{field_name(unit, vb, letter)}.label #{label(unit, vb)}"
92
      end
93
    end
94
  end
95
  exit 0
96
end
97
98
99
units.each do |unit|
100
  SNMP::Manager.open(:Host => unit,
101
                     :Community => community,
102
                     :Version => :SNMPv1) do |manager|
103
    manager.walk(base_oid) do |vb|
104
      if not is_vb_valid(vb, subchannel)
105
        next
106
      end
107
      puts "#{field_name(unit, vb, letter)}.value #{vb.value.to_f / 100}"
108
    end
109
  end
110
end