Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'rubygems'
- require 'pg'
- require 'timeout'
- require 'nagios-probe'
- def master_connection_string
- {:user => 'nagios', :dbname => 'nagios', :host => 'master', :password => 'nagios'}
- end
- def slave_connection_string
- {:user => 'nagios', :dbname => 'nagios', :host => 'slave', :password => 'nagios'}
- end
- $stamp = Random.rand(100)
- class ReplicationProbe< Nagios::Probe
- def check_crit
- conn = PG.connect( master_connection_string )
- conn.transaction do |conn|
- conn.exec("drop table if exists lag_table; create table lag_table (stamp integer); insert into lag_table VALUES( '#{$stamp}' );")
- end
- status = Timeout::timeout(60) {
- slave_stamp = -1
- sleep 1 #ERROR: could not open relation with OID
- while (slave_stamp != $stamp)
- conn = PG.connect( slave_connection_string )
- conn.transaction do |conn|
- slave_stamp = conn.exec("select stamp from lag_table limit 1;").first["stamp"].to_i
- end
- sleep 1 #Timeout probe
- end
- }
- end
- def check_warn
- false
- end
- def crit_message
- "Lag is critical!"
- end
- def warn_message
- "nothing to message"
- end
- def ok_message
- "nothing to see here"
- end
- end
- begin
- options = { }
- probe = ReplicationProbe.new(options)
- probe.run
- rescue Exception => e
- puts "unknown: #{e}"
- exit Nagios::UNKNOWN
- end
- puts probe.message
- exit probe.retval
Add Comment
Please, Sign In to add comment