This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpowermta_domain_queues
118 lines (95 loc) · 2.39 KB
/
powermta_domain_queues
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env ruby
pod=<<-POD
=head1 NAME
powermta_domain_queues
Munin plugin that monitors the number of messages queued up for each domain.
=head1 CONFIGURATION
The PowerMTA HTTP status interface must be enabled.
Options:
env.url http://localhost:8080 # URL to PowerMTA monitor interface
env.auth_user [empty] # HTTP auth username for stats, if any
env.auth_pass [empty] # HTTP auth password for stats, if any
ln -s /usr/share/munin/plugins/powermta_domain_queues \
/etc/munin/plugins/powermta_domain_queues
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
1.0
=head1 AUTHOR
Chris Boulton <[email protected]>
http://chrisboulton.net/
http://github.com/chrisboulton/munin-powermta
=head1 LICENSE
BSD
POD
require 'pathname'
require 'net/http'
require 'rexml/document'
PMTA_URL = ENV['url'] || 'http://localhost:8080'
PMTA_USER = ENV['auth_user'] || ''
PMTA_PASS = ENV['auth_pass'] || ''
SCRIPT_NAME = File.basename(Pathname.new(__FILE__).realpath)
STAT_TYPE = File.basename($0).gsub(SCRIPT_NAME, '');
def autoconf
begin
get_powermta_stats
rescue Exception => e
puts "no (#{e})"
end
puts "yes"
exit 0
end
def config
puts <<-EOF
graph_category PowerMTA
graph_title PowerMTA queue size by domain
graph_vlabel number of messages
graph_args --base 1000
EOF
begin
rsp = get_powermta_domain_stats
REXML::XPath.each(rsp, '//domain') { |domain|
name = domain.elements['name'].text
key = name.gsub(/[\.\/\-]/, "_")
puts "#{key}.label #{name}\n"
}
rescue Exception => e
$stderr.puts e
exit 1
end
end
def fetch
begin
rsp = get_powermta_domain_stats
REXML::XPath.each(rsp, '//domain') { |domain|
key = domain.elements['name'].text.gsub(/[\.\/\-]/, "_")
value = domain.elements['rcp'].text
puts "#{key}.value #{value}\n"
}
rescue Exception => e
$stderr.puts e
exit 1
end
end
def get_powermta_domain_stats
url = "#{PMTA_URL}/domains?format=xml"
begin
response = Net::HTTP.get_response(URI.parse(url)).body
xml = REXML::Document.new(response)
rescue Exception => e
raise "Unable to fetch PowerMTA domains from #{url}"
end
rsp = REXML::XPath.first(xml, "//rsp")
if rsp.nil?
raise "Not a valid PowerMTA status page"
end
return rsp
end
if ARGV[0] == "config"
config
elsif ARGV[0] == "autoconf"
autoconf
else
fetch
end