OSDN Git Service

Merge pull request #36314 (suigintoh/ultramonkey-l7-v3/fix_signum_cast into master).
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / include / snmp_info.h
1 /*!
2  * @file  snmp_info.h
3  * @brief snmp function common header.
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2010  NTT COMWARE Corporation.
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  */
23 #ifndef __SNMP_INFO_H__
24 #define __SNMP_INFO_H__
25
26
27 #include<boost/asio.hpp>
28 #include <time.h>
29 #include "logger.h"
30
31 namespace l7vs
32 {
33
34 struct snmp_info {
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
44         };
45         unsigned int    enabled;
46         unsigned int    logtrap_enabled;
47         LOG_LEVEL_TAG   logtrap_level;
48         unsigned int    interval;
49         time_t          start_date;
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;
56         std::string           protocol;
57         int                   option_set_flag;
58
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) {
78                 enabled = in.enabled;
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;
91
92                 return *this;
93         }
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)));
108
109                 os << "{";
110                 os << boost::format("flag=%d; "
111                                     "logtrap=%d; "
112                                     "logtrap_level=%s; "
113                                     "interval=%d; "
114                                     "start_date=%s; "
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; "
121                                     "protocol = %s; "
122                                     "option_set_flag = %x }")
123                    % info.enabled
124                    % info.logtrap_enabled
125                    % info.logtrap_level
126                    % info.interval
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()
135                    % info.protocol
136                    % info.option_set_flag;
137                 return os;
138
139         }
140 private:
141         friend class    boost::serialization::access;
142         template <class Archive > void serialize(Archive &ar, const unsigned int version) {
143                 ar &enabled;
144                 ar &logtrap_enabled;
145                 ar &logtrap_level;
146                 ar &interval;
147                 ar &start_date;
148                 ar &request_last_date;
149                 ar &trap_last_date;
150                 ar &snmp_get_requests;
151                 ar &snmp_set_requests;
152                 ar &snmp_trap_count;
153                 ar &vs_endpoint;
154                 ar &protocol;
155                 ar &option_set_flag;
156
157         }
158
159 };
160
161 struct rsdata {
162         int    index;
163         int    vs_index;
164         int    address_type;
165         char   address[128];
166         int    port;
167         int    forward;
168         int    weigth;
169         int    active_conn;
170         int    inactive_conn;
171 };
172
173 }
174
175 #endif //__SNMP_INFO_H__
176