Sha256: 688ffc417dcc949504c8b46f8dad9823e78b93024ea3dc2846d20f4ece6f8da4

Contents?: true

Size: 1015 Bytes

Versions: 3

Compression:

Stored size: 1015 Bytes

Contents

# -*- coding: utf-8 -*-

require 'rubygems'
require 'keystone'
require 'pit'

include Keystone::Batch::Base

ENV["EDITOR"] = "vi" unless ENV.key?("EDITOR")

config = Pit.get("disk_size_check", :require => {
        "smtp_addr" => "smtp_server_address",
        "mailto" => "mailto",
        "mailfrom" => "mailfrom"
})

SMTP_ADDR = config["smtp_addr"]
MAIL_TO = [config["mailto"]]
ERROR_MAIL_TO = MAIL_TO
MAIL_FROM = config["mailfrom"]

@os = Keystone::Os.get()

def send_alert_mail(additional_body = "")
  title = 'disk size alert'
  body  = <<-BODY
disk size alert at #{@os.hostname}(#{@os.ip_address.join(" , ")})
#{@df_result}
#{additional_body}
BODY

  Keystone::Mail::Send.send(
    MAIL_FROM,
    MAIL_TO,
    title,
    body,
    {:smtp_addr=>SMTP_ADDR,:retry_cnt=>3}
  )
end

execute() do
  limit = 80
  limit = Integer(ARGV[0]) if ARGV.size > 0

  @df_result = @os.disk
  @df_result.gsub(/(\d+)%/){|s|
    if $1.to_i >= limit
      warn 'log size alert'
      send_alert_mail
      break
    end
  }
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
keystone-0.0.32 util/bin/disk_size_check.rb
keystone-0.0.31 util/bin/disk_size_check.rb
keystone-0.0.30 util/bin/disk_size_check.rb