Guest User

Untitled

a guest
Mar 8th, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. user="xxxxxxx"
  2. host="hoge.foo.bar.com"
  3. password="secret"
  4. port=12345
  5.  
  6. threshold=1.5
  7. from="hoge@foo.bar.com"
  8. to=["bar@hoge.honya.com"].to_java("String")
  9.  
  10. newJSch.withSession(user,host,:password=>password,:port=>port) {|session|
  11. session.exec("w") {|is|
  12. @load_average = is.gets.gsub(/.+load average: /, "").split(",").collect{|num|num.to_f}
  13. }
  14. }
  15. if @load_average[2] >= threshold
  16. if defined?(MailSupport)
  17. msg = createJisMailMessage
  18. msg.subject = "監視アラート from matoi"
  19. msg.text = "#{host}の 15分平均CPU使用率が#{threshold}を超過(#{@load_average[2]})"
  20. msg.from = from
  21. msg.to = to
  22. sendMailMessage(msg)
  23. end
  24. end
  25. @load_average[2].to_s.toByteArray.download("text/plain")
Add Comment
Please, Sign In to add comment