-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-nagios.rb
56 lines (42 loc) · 937 Bytes
/
check-nagios.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
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
#!/usr/bin/ruby
# 2010 Ron Sweeney, Health Neutral
# Ensemble Nagios Plug In
# requirements:
# ruby
# Enslib.TCP.StatusService instance running in a target Ensemble
# production.
require 'socket'
# set debug flag
if ARGV.last == "-debug"
ARGV.pop
debug = true
end
# check input
if !(ARGV.size == 3)
puts "Usage: #{$0} CONFIGITEM HOST PORT [-debug]"
exit 1
end
# connect to Enslib.TCP.StatusService
s = TCPSocket.open(ARGV[1],ARGV[2])
s.puts "configitemstatus #{ARGV[0]}"
# get the response
# example: "1 job listening | Inactive | found a job with status = 'running'\n"
response = s.gets
#close the socket.
s.close
# check for error
if !(response =~ /running/)
puts response if debug
print "#{ARGV[0]} Down"
exit 2
end
# check for success
if (response =~ /running/)
puts response if debug
print "#{ARGV[0]} Running"
exit 0
# no idea what happened
else
print "Script failure"
exit 3
end