class CheckTungstenBackups

Private Instance Methods

configure() click to toggle source
Calls superclass method
# File bin/tungsten_nagios_backups, line 117
def configure
  super()
  
  description("Check all local datasources to make sure one of them has a backup younger than the max allowed age")
  
  add_option(:service, {
    :on => "--service String",
    :help => "The replication service or cluster to check"
  })
  
  add_option(:max_backup_age, {
    :on => "--max-backup-age String",
    :help => "Maximum allowed age in seconds of a backup on any machine",
    :parse => method(:parse_integer_option),
    :default => 86400
  })
end
main() click to toggle source
# File bin/tungsten_nagios_backups, line 33
def main
  if TI.is_commercial?()
    unless TI.is_manager?()
      critical("The server is not a Continuent Tungsten Manager")
    end

    unless TI.is_running?("manager")
      critical("The Continuent Tungsten Manager is not running")
    end
  else
    unless TI.is_replicator?()
      critical("The server is not a Tungsten Replicator")
    end

    unless TI.is_running?("replicator")
      critical("The Tungsten Replicator is not running")
    end
  end
  
  opt_default(:service, TI.default_dataservice())
  if opt(:service) == nil
    critical("The --service option was not given")
  end
  
  status = TI.status(opt(:service))
  
  # When running Continuent Tungsten, this will only run on the coordinator
  if TI.is_commercial?()
    unless status.coordinator() == TI.hostname()
      ok("Not running check because this node is not the coordinator")
    end
  end
  
  seconds_since_epoch = TU.cmd_result("date +%s").to_i()
  most_recent_backup = nil
  
  if TI.is_commercial?()
    hosts = status.replicators()
  else
    hosts = [TI.hostname()]
  end
  hosts.each{
    |ds|
    begin
      # Find the replication storage directory on the host
      key = "#{HOSTS}.#{TU.to_identifier(ds)}.repl_backup_directory"
      raw = TU.ssh_result("#{TI.base_path()}/tools/tpm query values #{key}", ds, TI.user())
      dir = JSON.parse(raw)[key]
      
      # Look for backup files in that directory
      TU.ssh_result("stat -c\"%n %Y\" #{dir}/store*.properties 2>/dev/null", ds, TI.user()).split("\n").each{
        |line|
        stored_backup=line.split(" ")
        stored_backup[1] = stored_backup[1].to_i()
        
        if most_recent_backup == nil || stored_backup[1] > most_recent_backup[:seconds]
          most_recent_backup = {
            :hostname => ds,
            :filename => stored_backup[0],
            :seconds => stored_backup[1]
          }
        end
      }
    rescue CommandError
    rescue JSON::ParserError
    end
  }
  
  if most_recent_backup == nil
    if TI.is_commercial?()
      critical("Unable to find a backup on any datasource")
    else
      critical("Unable to find a backup")
    end
  end
  
  age = seconds_since_epoch-most_recent_backup[:seconds]
  if age > @options[:max_backup_age]
    critical("#{most_recent_backup[:hostname]}:#{most_recent_backup[:filename]} [#{age}s] is older than #{@options[:max_backup_age]}s")
  else
    ok("The most recent backup is #{most_recent_backup[:hostname]}:#{most_recent_backup[:filename]} [#{age}s]")
  end
end
script_name() click to toggle source
# File bin/tungsten_nagios_backups, line 135
def script_name
  "tungsten_nagios_backups"
end