OSDN Git Service

Initial commit
[ultramonkey-l7/l7gui.git] / src / WebContent / log_snmp.jsp
1 <%@ page import="org.ultramonkey.l7.model.*,
2                                  org.ultramonkey.l7.controller.*,
3                                  org.ultramonkey.l7.view.*, java.util.*,
4                                  java.text.SimpleDateFormat,java.text.NumberFormat"
5         language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
6   
7 <%
8     /*
9      * check session
10      */
11     if (session.isNew()) {
12         MessageView error = new MessageView(41290, LogCategorySet.GUI_USER_AUTHENTICATION, Message.INVALID_SESSSION); 
13         session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
14         response.sendRedirect(RedirectPages.LOGIN);
15         return;
16     }
17
18     /*
19      * get result message
20      */
21     MessageView message = (MessageView) session.getAttribute(SessionKeys.RESULT_MESSAGE);
22     String errorMessage = "";
23     int errorNumber = 0;
24     String category = "";
25     String resultJudge = "success";
26     if (message != null) {
27       errorMessage = message.getMessage();
28       errorNumber = message.getErrno();
29       category = message.getCategory();
30       session.setAttribute(SessionKeys.RESULT_MESSAGE, null);
31       if ( errorNumber >= ErrNo.ERRORNUMBER )
32           resultJudge = "error";
33     }
34     
35     /*
36      * get command message
37      */
38     MessageView commandmessage = (MessageView) session.getAttribute(SessionKeys.COMMAND_MESSAGE);
39     String commandMessage = "";
40     int commandNumber = 0;
41     String commandCategory = "";
42     String commandJudge = "success";
43     if (commandmessage != null) {
44       commandMessage = commandmessage.getMessage();
45       commandNumber = commandmessage.getErrno();
46       commandCategory = commandmessage.getCategory();
47       session.setAttribute(SessionKeys.COMMAND_MESSAGE, null);
48       if ( commandNumber >= ErrNo.ERRORNUMBER )
49           commandJudge = "error";
50     }
51     
52     /*
53      * get snmp_log info
54      */
55      L7guiFramework framework = new L7guiFramework();
56      LogData logdata = framework.getLogData();
57      
58      if (logdata == null){
59          MessageView error = new MessageView(41291, LogCategorySet.GUI_LOG, Message.UNEXPECTED_ERROR);
60          session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
61          response.sendRedirect(RedirectPages.LOGIN);
62          return;
63      }
64
65      LogSet data = logdata.snmpLog;
66      
67      if (data == null){
68          MessageView error = new MessageView(41292, LogCategorySet.GUI_LOG, Message.UNEXPECTED_ERROR);
69          session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
70          response.sendRedirect(RedirectPages.LOGIN);
71          return;
72      } 
73
74      Vector<LogFileData> logfiles = data.logFiles;
75      if (logfiles == null){
76          MessageView error = new MessageView(41293, LogCategorySet.GUI_LOG, Message.UNEXPECTED_ERROR);
77          session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
78          response.sendRedirect(RedirectPages.LOGIN);
79          return;
80      }
81      
82      HashMap<LogData.LogCategory, LogData.LogLevel> logcategoryset = data.logLevel;
83      if (logcategoryset == null){
84          MessageView error = new MessageView(41294, LogCategorySet.GUI_LOG, Message.UNEXPECTED_ERROR);
85          session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
86          response.sendRedirect(RedirectPages.LOGIN);
87          return;
88      }
89      
90      /*
91       * get cluster status
92       */
93      ClusterData cd = framework.getClusterData();
94      
95      if (cd == null){
96          MessageView error = new MessageView(41295, LogCategorySet.GUI_IO_COMMAND, Message.CLUSTER_DATA_ERROR);
97          session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
98          response.sendRedirect(RedirectPages.LOGIN);
99      }
100       
101         /*
102          * fix style seat
103          */
104         String cssSeat = "l7gui_single_style.css";
105         if ( cd.self_status == ClusterStatus.ACTIVE ){
106                 cssSeat = "l7gui_act_style.css";
107         }
108         else if ( cd.self_status == ClusterStatus.STANDBY ){
109                 cssSeat = "l7gui_sby_style.css";
110         }
111
112 %>
113 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
114
115 <html>
116   <head>
117     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
118         <meta http-equiv="Pragma" content="no-cache">
119         <meta http-equiv="Cache-Control" content="no-cache">
120         <meta http-equiv="Expires" content="0">                     
121     <meta http-equiv="Content-Script-Type" content="text/javascript" />
122     <meta http-equiv="Content-Style-Type" content="text/css" />
123     <script src="l7gui.js" type="text/javascript"></script>
124     <noscript> 
125          <meta http-equiv="refresh" content="<%= RedirectPages.NOSCRIPT_TIME %>; url=<%= RedirectPages.LOGIN %>"/>
126       </noscript> 
127     <link rel="stylesheet" type="text/css" href="<%=cssSeat %>" />
128     <link rel="shortcut icon" href="images/favicon.ico"/>
129         <title>Log - SNMPAgent -</title>
130     </head>
131     
132
133
134   <body class="normal">
135   <jsp:include page="menu.jsp" flush="false"/>
136   <div id="content">
137
138     <h1>Log - SNMPAgent -</h1>
139           <%
140           if ( (message != null ) && (errorMessage != null) ) {
141           %>
142           
143           <p class="<%=resultJudge %>">[<%=category%>-<%=errorNumber%>]</p>
144           <p class="<%=resultJudge %>"><%=errorMessage%></p>
145           
146           <%
147           } else if ( (commandmessage != null) && (commandMessage != null) ) {
148           %>
149           <p class="<%=commandJudge %>">[<%=commandCategory%>-<%=commandNumber%>]</p>
150           <p class="<%=commandJudge %>"><%=commandMessage%></p>
151           <%
152           }
153           %>
154     
155     <h2> Download Log File</h2>
156     <h4>Please select the following list you would like to download the log file. </h4>
157   
158       <table  class="infotable" cellspacing="0">
159
160       <tr>
161       <th>LogFileName</th><th>LastUpdate</th><th>FileSize(byte)</th>
162       </tr>
163       
164       <%
165                 SimpleDateFormat dfm = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
166                 NumberFormat num = NumberFormat.getInstance();
167         Iterator<LogFileData> i = logfiles.iterator();
168         
169         while ( i.hasNext() ){
170             LogFileData log = (LogFileData) i.next();
171             
172             if ( log != null && log.fileName != null){
173                    out.println("<tr>");
174                    out.println("<td>");
175                    out.println("<a href=\"LogOutputServlet?type=" + LogCategorySet.SNMPAGENT + "&log=" + log.fileName + "\">" + log.fileName + "</a>");
176                    out.println("</td>");
177                    out.println("<td class=\"center\">" + dfm.format(log.time) + "</td>");            
178                    out.println("<td class=\"right\">" + num.format(log.size) + "</td>");               
179                    out.println("</tr>");
180             }
181         }
182       %>
183       
184     </table>      
185
186
187     <br />
188
189     <h2>Change Log Level</h2>
190     <h4>Please select log level you would like to change.</h4>
191
192     <form method="post" action="LogLevelServlet" name="log_snmp">
193     <input type="hidden" name="type" value="<%=LogCategorySet.SNMPAGENT %>">
194       <table  class="infotable" cellspacing="0">  
195
196       <tr>
197         <th>Category</th><th>Level</th>
198       </tr>
199       
200         <% 
201             TreeSet<LogData.LogCategory> tree = new TreeSet<LogData.LogCategory>(logcategoryset.keySet());
202             Iterator<LogData.LogCategory> it = tree.iterator();
203        
204         while (it.hasNext()) {
205             LogData.LogCategory logcategory = (LogData.LogCategory) it.next();
206   
207             if (logcategory != null){
208         %>
209       <tr>
210       <td><%= logcategory %></td>
211       <td>
212       <select id="<%= logcategory %>" name="<%= logcategory %>">
213         <option value="<%=LogData.LogLevel.NONE %>"<%
214                   if ( logcategoryset.get(logcategory) == LogData.LogLevel.NONE)
215                           out.print(" selected");
216                   %>></option>
217         <option value="<%=LogData.LogLevel.DEBUG %>"<%
218                    if ( logcategoryset.get(logcategory) == (LogData.LogLevel.DEBUG)) {
219                        out.print(" selected");
220                    }
221                   %>>DEBUG</option>
222         <option value="<%=LogData.LogLevel.INFO %>"<%
223                   if ( logcategoryset.get(logcategory) == (LogData.LogLevel.INFO)){ 
224                     out.print(" selected");
225                   }
226                   %>>INFO</option>
227         <option value="<%=LogData.LogLevel.ERROR %>"<%
228                   if (logcategoryset.get(logcategory) == (LogData.LogLevel.ERROR)){
229                       out.print(" selected");
230                   }
231                   %>>ERROR</option>          
232         <option value="<%=LogData.LogLevel.WARN %>"<%
233                   if ( logcategoryset.get(logcategory) == (LogData.LogLevel.WARN)){ 
234                     out.print(" selected");
235                   }
236                   %>>WARN</option>
237         <option value="<%=LogData.LogLevel.FATAL %>"<%
238                   if ( logcategoryset.get(logcategory) == (LogData.LogLevel.FATAL)){ 
239                     out.print(" selected");
240                   }
241                   %>>FATAL</option>
242       </select>
243       </td>
244       </tr>
245           <%
246           }
247       }
248       %>
249       </table>
250     
251       <br>
252       <input type="submit" name="button" value="<%= ButtonMode.APPLY %>" onClick="return confirm(log_snmp_apply)" />
253
254       <input type="submit" name="button" value="<%= ButtonMode.SAVE %>" onClick="return confirm(log_snmp_save)" />  
255       <%
256           if (cd.self_status == ClusterStatus.ACTIVE || cd.self_status == ClusterStatus.STANDBY) {
257       %>
258       <input type="submit" name="button" value="<%= ButtonMode.SAVESYNC %>" onClick="return confirm(log_snmp_savesync)" />
259       <%
260           }
261       %>    
262     </form>
263   
264   </div>
265   </body>
266 </html>