mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
F #3859: Run all probes at startup
This commit is contained in:
parent
8f60f6feca
commit
213dada892
@ -174,9 +174,25 @@ class ProbeRunner
|
||||
# rubocop:enable Lint/SuppressedException
|
||||
|
||||
# Singleton call for run_probes method
|
||||
def self.run_once(hyperv, path, stdin)
|
||||
runner = ProbeRunner.new(hyperv, path, stdin)
|
||||
runner.run_probes
|
||||
def self.run_once(hyperv, probes, stdin)
|
||||
rc = 0
|
||||
ret = '<MONITOR_MESSAGES>'
|
||||
|
||||
probes.each do |name, probe|
|
||||
next if name == :beacon_host_udp
|
||||
|
||||
runner = ProbeRunner.new(hyperv, probe[:path], stdin)
|
||||
rc, dt = runner.run_probes
|
||||
|
||||
dt64 = Base64.encode64(dt).gsub("\n", '')
|
||||
ret += "<#{probe[:elem_name]}>#{dt64}</#{probe[:elem_name]}>\n"
|
||||
|
||||
return rc, ret if rc == -1
|
||||
end
|
||||
|
||||
ret+='</MONITOR_MESSAGES>'
|
||||
|
||||
[rc, ret]
|
||||
end
|
||||
|
||||
# Executes the probes in the directory in a loop. The block is called after
|
||||
@ -242,21 +258,25 @@ begin
|
||||
probes = {
|
||||
:system_host_udp => {
|
||||
:period => config.elements['PROBES_PERIOD/SYSTEM_HOST'].text.to_s,
|
||||
:elem_name => 'SYSTEM_HOST',
|
||||
:path => 'host/system'
|
||||
},
|
||||
|
||||
:monitor_host_udp => {
|
||||
:period => config.elements['PROBES_PERIOD/MONITOR_HOST'].text.to_s,
|
||||
:elem_name => 'MONITOR_HOST',
|
||||
:path => 'host/monitor'
|
||||
},
|
||||
|
||||
:state_vm_tcp => {
|
||||
:period => config.elements['PROBES_PERIOD/STATE_VM'].text.to_s,
|
||||
:elem_name => 'STATE_VM',
|
||||
:path => 'vm/status'
|
||||
},
|
||||
|
||||
:monitor_vm_udp => {
|
||||
:period => config.elements['PROBES_PERIOD/MONITOR_VM'].text.to_s,
|
||||
:elem_name => 'MONITOR_VM',
|
||||
:path => 'vm/monitor'
|
||||
},
|
||||
|
||||
@ -293,8 +313,7 @@ end
|
||||
|
||||
client = MonitorClient.new(host, port, hostid, :pubkey => pubkey)
|
||||
|
||||
rc, dt = ProbeRunner.run_once(hyperv, probes[:system_host_udp][:path], xml_txt)
|
||||
|
||||
rc, dt = ProbeRunner.run_once(hyperv, probes, xml_txt)
|
||||
puts dt
|
||||
|
||||
STDOUT.flush
|
||||
|
@ -107,6 +107,11 @@ public:
|
||||
return _type_str._to_str(_type);
|
||||
}
|
||||
|
||||
static const std::string& type_str(E t)
|
||||
{
|
||||
return _type_str._to_str(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Status of the message, can't contain blanks.
|
||||
* Depends on message type, could contain result of
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "HostMonitorManager.h"
|
||||
#include "OneMonitorDriver.h"
|
||||
|
||||
#include "MonitorDriverMessages.h"
|
||||
|
||||
HostMonitorManager * MonitorDriverProtocol::hm = nullptr;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -97,7 +99,8 @@ void MonitorDriverProtocol::_monitor_vm(message_t msg)
|
||||
|
||||
if (it == vms_templ.end())
|
||||
{
|
||||
vms_templ.insert(make_pair(std::move(uuid), make_pair(id, std::move(mon_tmpl))));
|
||||
vms_templ.insert(make_pair(std::move(uuid),
|
||||
make_pair(id, std::move(mon_tmpl))));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -184,7 +187,17 @@ void MonitorDriverProtocol::_state_vm(message_t msg)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* Format of the START_MONITOR response message is:
|
||||
* <MONITOR_MESSAGES>
|
||||
* <MONITOR_VM>
|
||||
* ...
|
||||
* </MONITOR_VM>
|
||||
* ...
|
||||
* </MONITOR_MESSAGES>
|
||||
*
|
||||
* It includes all messages that may be sent by probes, defined in
|
||||
* MonitorDriverMessages. This message is constructed in monitord_client.rb
|
||||
*/
|
||||
void MonitorDriverProtocol::_start_monitor(message_t msg)
|
||||
{
|
||||
NebulaLog::ddebug("MDP", "Received start monitor for host " +
|
||||
@ -200,8 +213,71 @@ void MonitorDriverProtocol::_start_monitor(message_t msg)
|
||||
return;
|
||||
}
|
||||
|
||||
auto oned = hm->get_oned_driver();
|
||||
oned->host_system_info(msg->oid(), msg->status(), msg->payload());
|
||||
ObjectXML msg_xml;
|
||||
|
||||
if ( msg_xml.update_from_str(msg->payload()) != 0 )
|
||||
{
|
||||
hm->start_monitor_failure(msg->oid());
|
||||
|
||||
NebulaLog::warn("MDP", "Error parsing start message for host " +
|
||||
to_string(msg->oid()) + ": " + msg->payload());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const std::vector<MonitorDriverMessages> stypes = {
|
||||
MonitorDriverMessages::MONITOR_VM,
|
||||
MonitorDriverMessages::BEACON_HOST,
|
||||
MonitorDriverMessages::MONITOR_HOST,
|
||||
MonitorDriverMessages::SYSTEM_HOST,
|
||||
MonitorDriverMessages::STATE_VM
|
||||
};
|
||||
|
||||
for (const auto& it : stypes)
|
||||
{
|
||||
std::string payload64, payload;
|
||||
|
||||
std::string xpath = "/MONITOR_MESSAGES/" +
|
||||
Message<MonitorDriverMessages>::type_str(it);
|
||||
|
||||
if ( msg_xml.xpath(payload64, xpath.c_str(), "") != 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
base64_decode(payload64, payload);
|
||||
|
||||
message_t m(new Message<MonitorDriverMessages>);
|
||||
|
||||
m->type(it);
|
||||
|
||||
m->oid(msg->oid());
|
||||
|
||||
m->status("SUCCESS");
|
||||
|
||||
m->payload(payload);
|
||||
|
||||
switch(it)
|
||||
{
|
||||
case MonitorDriverMessages::MONITOR_VM:
|
||||
_monitor_vm(std::move(m));
|
||||
break;
|
||||
case MonitorDriverMessages::BEACON_HOST:
|
||||
_beacon_host(std::move(m));
|
||||
break;
|
||||
case MonitorDriverMessages::MONITOR_HOST:
|
||||
_monitor_host(std::move(m));
|
||||
break;
|
||||
case MonitorDriverMessages::SYSTEM_HOST:
|
||||
_system_host(move(m));
|
||||
break;
|
||||
case MonitorDriverMessages::STATE_VM:
|
||||
_state_vm(move(m));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
hm->start_monitor_success(msg->oid());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user