Class: AbstractMonitor
- Inherits:
-
Object
- Object
- AbstractMonitor
- Defined in:
- lib/monitor_agent.rb
Direct Known Subclasses
AppMasterMonitor, AppMonitor, DbMasterMonitor, DbSlaveMonitor, SoloMonitor, UtilMonitor
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #check ⇒ Object
- #check_ssh ⇒ Object
-
#initialize(host, token) ⇒ AbstractMonitor
constructor
A new instance of AbstractMonitor.
- #role ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(host, token) ⇒ AbstractMonitor
Returns a new instance of AbstractMonitor.
69 70 71 72 73 |
# File 'lib/monitor_agent.rb', line 69 def initialize(host, token) @host = host @token = token @result = {} end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
67 68 69 |
# File 'lib/monitor_agent.rb', line 67 def host @host end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
67 68 69 |
# File 'lib/monitor_agent.rb', line 67 def result @result end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
67 68 69 |
# File 'lib/monitor_agent.rb', line 67 def token @token end |
Instance Method Details
#check ⇒ Object
79 80 81 82 |
# File 'lib/monitor_agent.rb', line 79 def check @result = check_ssh self end |
#check_ssh ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/monitor_agent.rb', line 90 def check_ssh Utils::LOG.info "checking ssh: #{host}" result = {} begin Net::SSH.start(host, "root", :keys => ["/root/.ssh/awsm"], :paranoid => false, :timeout => 10) do |ssh| begin # ignore any STDOUT and only grab the final json from the scripts output script_output = ssh.exec!("bash -lc \"ey-agent\"").split("\n").last result = JSON.parse(script_output) result['ssh'] = 'up' rescue JSON::ParserError Utils::LOG.error '*' * 80 Utils::LOG.error "#{host}>>>>>>>>>>>\n#{script_output}" result['ey-agent'] = 'down' end end rescue Net::SSH::HostKeyMismatch => e e.remember_host! retry end result rescue SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Timeout::Error, Net::SSH::AuthenticationFailed result['ssh'] = 'down' result end |
#role ⇒ Object
75 76 77 |
# File 'lib/monitor_agent.rb', line 75 def role self.class.name.snake_case.chomp("_monitor") end |
#to_hash ⇒ Object
84 85 86 87 88 |
# File 'lib/monitor_agent.rb', line 84 def to_hash {"host" => host, "result" => result, "timestamp" => Utils.epoch_time, 'token' => token, 'role' => role} end |