Files
one/src/monitor/include/MonitorDriver.h
T
Ruben S. Montero 44e44b47a8 F #3859: New monitoring architecture
co-authored-by: Pavel Czerny <pczerny@opennebula.systems>
  co-authored-by: Daniel Clavijo Coca <dclavijo@opennebula.systems>
2020-03-04 16:05:57 +01:00

93 lines
3.2 KiB
C++

/* -------------------------------------------------------------------------- */
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#ifndef MONITOR_DRIVER_H_
#define MONITOR_DRIVER_H_
#include "Monitor.h"
#include "Driver.h"
#include "Message.h"
#include "MonitorDriverMessages.h"
#include "MonitorDriverProtocol.h"
#include <cstdarg>
class MonitorDriver : public Driver<MonitorDriverMessages>
{
public:
using message_t = Message<MonitorDriverMessages>;
MonitorDriver(const std::string& c, const std::string& a, int ct):
Driver<MonitorDriverMessages>(c, a, ct)
{
register_action(MonitorDriverMessages::UNDEFINED,
&MonitorDriverProtocol::_undefined);
register_action(MonitorDriverMessages::MONITOR_VM,
&MonitorDriverProtocol::_monitor_vm);
register_action(MonitorDriverMessages::MONITOR_HOST,
&MonitorDriverProtocol::_monitor_host);
register_action(MonitorDriverMessages::SYSTEM_HOST,
&MonitorDriverProtocol::_system_host);
register_action(MonitorDriverMessages::STATE_VM,
&MonitorDriverProtocol::_state_vm);
register_action(MonitorDriverMessages::START_MONITOR,
&MonitorDriverProtocol::_start_monitor);
register_action(MonitorDriverMessages::LOG,
&MonitorDriverProtocol::_log);
};
void start_monitor(int oid, const std::string& host_xml)
{
message_t msg;
NebulaService& ns = Monitor::instance();
msg.type(MonitorDriverMessages::START_MONITOR);
msg.oid(oid);
msg.payload(format_message(host_xml + ns.get_configuration_xml()));
write(msg);
}
void stop_monitor(int oid, const std::string& host_xml)
{
message_t msg;
NebulaService& ns = Monitor::instance();
msg.type(MonitorDriverMessages::STOP_MONITOR);
msg.oid(oid);
msg.payload(format_message(host_xml + ns.get_configuration_xml()));
write(msg);
}
private:
string format_message(const std::string& value) const
{
return "<MONITOR_DRIVER_ACTION>" + value + "</MONITOR_DRIVER_ACTION>";
}
};
#endif // MONITOR_DRIVER_H_