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_connections
126 lines (99 loc) · 2.4 KB
/
powermta_connections
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
119
120
121
122
123
124
125
126
#!/usr/bin/env ruby
pod=<<-POD
=head1 NAME
powermta_connections
Munin plugin that monitors the number of inbound connections to and
outbound connections from PowerMTA.
=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_connections \
/etc/munin/plugins/powermta_connections
=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 connections
graph_order in out
graph_vlabel active connections in (-) / out (+)
graph_args --base 1000
graph_scale no
in.label connections_in
in.graph no
in.min 0
out.label connections
out.negative in
out.min 0
EOF
end
def fetch
begin
rsp = get_powermta_stats
stat = get_powermta_stat(rsp, "//conn/smtpOut/cur")
puts "out.value #{stat}\n"
stat = get_powermta_stat(rsp, "//conn/smtpIn/cur")
puts "in.value #{stat}"
rescue Exception => e
$stderr.puts e
exit 1
end
end
def get_powermta_stats
url = "#{PMTA_URL}/status?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 status from #{url}"
end
rsp = REXML::XPath.first(xml, "//rsp")
if rsp.nil?
raise "Not a valid PowerMTA status page"
end
return rsp
end
def get_powermta_stat(rsp, stat)
result = REXML::XPath.first(rsp, stat)
if stat.nil?
raise "Unable to locate statistic for #{stat}"
end
return result.text
end
if ARGV[0] == "config"
config
elsif ARGV[0] == "autoconf"
autoconf
else
fetch
end