-
Notifications
You must be signed in to change notification settings - Fork 31
/
postfix_status.rb
executable file
·31 lines (26 loc) · 1.11 KB
/
postfix_status.rb
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
#!/usr/bin/env ruby
# a) checks if postfix is running. critical if it is not
# b) warns if there are messages in postfix's queue
# c) status ok if postfix is running and b) is 0
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <[email protected]> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return
# ----------------------------------------------------------------------------
postqueue=`which postqueue`.chomp
running=`ps axf |grep postfix |grep -v grep`.chomp
if ( running =~ /^\s*(\d+)\s+(pts|tty|\?)/ )
pid=$1
messages=`#{postqueue} -p |grep -v "Mail queue is empty" |wc -l`.chomp.to_i
if ( messages > 0 )
puts "status warn #{messages} messages in the postfix queue"
puts "metric postfix_queue_size int #{messages}"
else
puts "status ok postfix running on pid #{pid} with no pending messages"
puts "metric postfix_queue_size int #{messages}"
end
else
puts "status err postfix not running!"
exit 2
end