diff --git a/src/im_mad/remotes/common.d/monitord-client.rb b/src/im_mad/remotes/common.d/monitord-client.rb
index 4d808218b7..0161321c11 100644
--- a/src/im_mad/remotes/common.d/monitord-client.rb
+++ b/src/im_mad/remotes/common.d/monitord-client.rb
@@ -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 = ''
+
+ 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+=''
+
+ [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
diff --git a/src/monitor/include/Message.h b/src/monitor/include/Message.h
index 4e2c1a46fc..0057687712 100644
--- a/src/monitor/include/Message.h
+++ b/src/monitor/include/Message.h
@@ -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
diff --git a/src/monitor/src/monitor/MonitorDriverProtocol.cc b/src/monitor/src/monitor/MonitorDriverProtocol.cc
index 024998ea1a..0110ffc544 100644
--- a/src/monitor/src/monitor/MonitorDriverProtocol.cc
+++ b/src/monitor/src/monitor/MonitorDriverProtocol.cc
@@ -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:
+ *
+ *
+ * ...
+ *
+ * ...
+ *
+ *
+ * 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 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::type_str(it);
+
+ if ( msg_xml.xpath(payload64, xpath.c_str(), "") != 0 )
+ {
+ continue;
+ }
+
+ base64_decode(payload64, payload);
+
+ message_t m(new Message);
+
+ 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());
}