3 * @brief snmp function common header.
5 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6 * Copyright (C) 2010 NTT COMWARE Corporation.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 #ifndef __SNMP_INFO_H__
24 #define __SNMP_INFO_H__
27 #include<boost/asio.hpp>
35 enum SNMP_OPTION_FLAG_TAG {
36 SNMP_ENABLE_OPTION_FLAG = 0x0001,
37 SNMP_LOGTRAP_OPTION_FLAG = 0x0002,
38 SNMP_LOGTRAP_LEVEL_OPTION_FLAG = 0x0004,
39 SNMP_INTERVAL_OPTION_FLAG = 0x0008,
40 SNMP_REFRESH_OPTION_FLAG = 0x0010,
41 SNMP_REFRESH_ALL_OPTION_FLAG = 0x0020,
42 SNMP_TCP_SERVICE_OPTION_FLAG = 0x0040,
43 SNMP_PROTOCOL_MODULE_OPTION_FLAG = 0x0080
46 unsigned int logtrap_enabled;
47 LOG_LEVEL_TAG logtrap_level;
48 unsigned int interval;
50 time_t request_last_date;
51 time_t trap_last_date;
52 unsigned long long snmp_get_requests;
53 unsigned long long snmp_set_requests;
54 unsigned long long snmp_trap_count;
55 boost::asio::ip::tcp::endpoint vs_endpoint;
59 snmp_info() : enabled(0), logtrap_enabled(0), logtrap_level(LOG_LV_NONE),
60 interval(0), start_date(0),
61 request_last_date(0), trap_last_date(0),
62 snmp_get_requests(0ull), snmp_set_requests(0ull), snmp_trap_count(0ull), option_set_flag(0) {}
63 snmp_info(const snmp_info &in)
64 : enabled(in.enabled),
65 logtrap_enabled(in.logtrap_enabled),
66 logtrap_level(in.logtrap_level),
67 interval(in.interval),
68 start_date(in.start_date),
69 request_last_date(in.request_last_date),
70 trap_last_date(in.trap_last_date),
71 snmp_get_requests(in.snmp_get_requests),
72 snmp_set_requests(in.snmp_set_requests),
73 snmp_trap_count(in.snmp_trap_count),
74 vs_endpoint(in.vs_endpoint),
75 protocol(in.protocol),
76 option_set_flag(in.option_set_flag) {}
77 snmp_info &operator=(const snmp_info &in) {
79 logtrap_enabled = in.logtrap_enabled;
80 logtrap_level = in.logtrap_level;
81 interval = in.interval;
82 start_date = in.start_date;
83 request_last_date = in.request_last_date;
84 trap_last_date = in.trap_last_date;
85 snmp_get_requests = in.snmp_get_requests;
86 snmp_set_requests = in.snmp_set_requests;
87 snmp_trap_count = in.snmp_trap_count;
88 vs_endpoint = in.vs_endpoint;
89 protocol = in.protocol;
90 option_set_flag = in.option_set_flag;
94 template <typename Elem, typename Traits>
95 friend std::basic_ostream<Elem, Traits>& operator<<(
96 std::basic_ostream<Elem, Traits>& os,
97 const snmp_info &info) {
98 static const int MAX_TIME_LEN = 20;
99 char start_date[MAX_TIME_LEN] = {0};
100 char request_last_date[MAX_TIME_LEN] = {0};
101 char trap_last_date[MAX_TIME_LEN] = {0};
102 strftime(start_date, sizeof(start_date),
103 "%Y-%m-%d %H:%M:%S", gmtime(&(info.start_date)));
104 strftime(request_last_date, sizeof(request_last_date),
105 "%Y-%m-%d %H:%M:%S", gmtime(&(info.request_last_date)));
106 strftime(trap_last_date, sizeof(trap_last_date),
107 "%Y-%m-%d %H:%M:%S", gmtime(&(info.trap_last_date)));
110 os << boost::format("flag=%d; "
115 "request_last_date = %s; "
116 "trap_last_date = %s ;"
117 "snmp_get_requests = %d ;"
118 "snmp_set_requests = %d ;"
119 "snmp_trap_count= %d; "
120 "vs_endpoint= %s:%d; "
122 "option_set_flag = %x }")
124 % info.logtrap_enabled
127 % (info.start_date == 0 ? "none" : start_date)
128 % (info.request_last_date == 0 ? "none" : request_last_date)
129 % (info.trap_last_date == 0 ? "none" : trap_last_date)
130 % info.snmp_get_requests
131 % info.snmp_set_requests
132 % info.snmp_trap_count
133 % info.vs_endpoint.address().to_string()
134 % info.vs_endpoint.port()
136 % info.option_set_flag;
141 friend class boost::serialization::access;
142 template <class Archive > void serialize(Archive &ar, const unsigned int version) {
148 ar &request_last_date;
150 ar &snmp_get_requests;
151 ar &snmp_set_requests;
175 #endif //__SNMP_INFO_H__