summaryrefslogtreecommitdiffstats
path: root/src/snmp_trap.hpp
blob: 4555e659b2941330e900eef2a26ecdc12b2eed76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "callback.hpp"

namespace phosphor
{
namespace dbus
{
namespace monitoring
{
/** @class Trap
 *  @brief Raises SNMP trap
 */
class Trap
{
  public:
    Trap() = default;
    Trap(const Trap&) = delete;
    Trap(Trap&&) = default;
    Trap& operator=(const Trap&) = delete;
    Trap& operator=(Trap&&) = default;
    virtual ~Trap() = default;
    /** @brief Raise SNMP trap by parsing the sdbus message.
     *  @param[in] msg - sdbus message.
     */
    virtual void trap(sdbusplus::message::message& msg) const = 0;
};

/** @class ErrorTrap
 *  @brief Sends SNMP trap for the elog error
 */
class ErrorTrap : public Trap
{
  public:
    ErrorTrap() = default;
    ErrorTrap(const ErrorTrap&) = delete;
    ErrorTrap(ErrorTrap&&) = default;
    ErrorTrap& operator=(const ErrorTrap&) = delete;
    ErrorTrap& operator=(ErrorTrap&&) = default;
    ~ErrorTrap() = default;

    /** @brief Raise SNMP trap by parsing the sdbus message.
     *  @param[in] msg - sdbus message.
     */
    void trap(sdbusplus::message::message& msg) const override;
};

/** @class SNMPTrap
 *  @brief SNMP trap callback implementation.
 */
template <typename T>
class SNMPTrap : public Callback
{
  public:
    SNMPTrap(const SNMPTrap&) = delete;
    SNMPTrap(SNMPTrap&&) = default;
    SNMPTrap& operator=(const SNMPTrap&) = delete;
    SNMPTrap& operator=(SNMPTrap&&) = default;
    virtual ~SNMPTrap() = default;
    SNMPTrap() : Callback()
    {
    }

    /** @brief Callback interface implementation.
     *  @param[in] ctc - context.
     */
    void operator()(Context ctx)
    {
    }

    /** @brief Callback interface implementation.
     *  @param[in] ctc - context.
     *  @param[in] msg - sdbus message.
     */
    void operator()(Context ctx, sdbusplus::message::message& msg)
    {
        event.trap(msg);
    }

  private:
    T event;
};

} // namespace monitoring
} // namespace dbus
} // namespace phosphor
OpenPOWER on IntegriCloud