⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editoutage.jsp

📁 opennms得相关源码 请大家看看
💻 JSP
📖 第 1 页 / 共 3 页
字号:
<%@page language="java" contentType="text/html" session="true"   import="java.util.*,  org.opennms.core.resource.Vault,  org.opennms.netmgt.config.*,  org.opennms.netmgt.config.poller.*,  org.opennms.web.element.*,  org.opennms.netmgt.EventConstants,  org.opennms.netmgt.xml.event.Event,  org.opennms.netmgt.utils.*,java.net.*,  java.io.*" %><%!//A singleton instance of a "Match-any" interface, which can be used for generic tests/removals etc.private static org.opennms.netmgt.config.poller.Interface matchAnyInterface;{	matchAnyInterface=new org.opennms.netmgt.config.poller.Interface();	matchAnyInterface.setAddress("match-any");}public void sendOutagesChangedEvent() throws ServletException {	Event event = new Event();	event.setSource("Web UI");	event.setUei(EventConstants.SCHEDOUTAGES_CHANGED_EVENT_UEI);	try {		event.setHost(InetAddress.getLocalHost().getHostName());	} catch (UnknownHostException uhE) {		event.setHost("unresolved.host");	}		event.setTime(EventConstants.formatToString(new java.util.Date()));	try {		Vault.createEventProxy().send(event);	} catch (Exception e) {		throw new ServletException("Could not send event " + event.getUei(), e);	}}%><%HashMap shortDayNames=new HashMap();shortDayNames.put("sunday","Sun");shortDayNames.put("monday","Mon");shortDayNames.put("tuesday","Tue");shortDayNames.put("wednesday","Wed");shortDayNames.put("thursday","Thu");shortDayNames.put("friday","Fri");shortDayNames.put("saturday","Sat");shortDayNames.put("1","1st");shortDayNames.put("2","2nd");shortDayNames.put("3","3rd");shortDayNames.put("4","4th");shortDayNames.put("5","5th");shortDayNames.put("6","6th");shortDayNames.put("7","7th");shortDayNames.put("8","8th");shortDayNames.put("9","9th");shortDayNames.put("10","10th");shortDayNames.put("11","11th");shortDayNames.put("12","12th");shortDayNames.put("13","13th");shortDayNames.put("14","14th");shortDayNames.put("15","15th");shortDayNames.put("16","16th");shortDayNames.put("17","17th");shortDayNames.put("18","18th");shortDayNames.put("19","19th");shortDayNames.put("20","20th");shortDayNames.put("21","21st");shortDayNames.put("22","22nd");shortDayNames.put("23","23rd");shortDayNames.put("24","24th");shortDayNames.put("25","25th");shortDayNames.put("26","26th");shortDayNames.put("27","27th");shortDayNames.put("28","28th");shortDayNames.put("29","29th");shortDayNames.put("30","30th");shortDayNames.put("31","31st");   PollOutagesConfigFactory.init(); //Only init - do *not* reload   PollOutagesConfigFactory pollFactory=PollOutagesConfigFactory.getInstance();   Outage theOutage;   String nameParam=request.getParameter("name");	if(nameParam!=null) {		//first time in - name is passed as a param.  Find the outage, copy it, and shove it in the session		//Also keep a copy of the name, for later saving (replacing the original with the edited copy)   		Outage tempOutage=pollFactory.getOutage(nameParam);		CharArrayWriter writer=new CharArrayWriter();		tempOutage.marshal(writer);		theOutage=Outage.unmarshal(new CharArrayReader(writer.toCharArray()));		request.getSession().setAttribute("opennms.editoutage",theOutage);		request.getSession().setAttribute("opennms.editoutage.origname", nameParam);	} else if("true".equals(request.getParameter("addNew"))) {		theOutage=new Outage();		//Nuke whitespace - it messes with all sorts of things		theOutage.setName(request.getParameter("newName").trim());		theOutage.setType("specific");		request.getSession().setAttribute("opennms.editoutage",theOutage);		request.getSession().removeAttribute("opennms.editoutage.origname");	} else {		//Neither starting the edit, nor adding a new outage.  		theOutage=(Outage)request.getSession().getAttribute("opennms.editoutage");		if(theOutage==null) {			//No name, and no outage in the session.  Give up			%> No outage name parameter, nor outage stored in the session.  Cannot edit!<BR>			</body></html>			<%			return;					}	}   //Load the initial set of enabled outages from the external configuration   // This will be overridden by a formSubmission to use the form values, but is necessary for the initial load of the page   //It is more efficient to piggy back on this initial setup setp (creating the hashmaps) than doing it separately   Set enabledOutages=new HashSet();   // ******* Notification outages config *********   Collection notificationOutages=NotifdConfigFactory.getInstance().getConfiguration().getOutageCalendarCollection();   if(notificationOutages.contains(theOutage.getName())) {	enabledOutages.add("notifications");   }   // ******* Threshd outages config *********   ThreshdConfigFactory.init();   Map thresholdOutages=new HashMap();   org.opennms.netmgt.config.threshd.Package[] thresholdingPackages=ThreshdConfigFactory.getInstance().getConfiguration().getPackage();   for(int i=0; i<thresholdingPackages.length; i++) {	org.opennms.netmgt.config.threshd.Package thisPackage=thresholdingPackages[i];	thresholdOutages.put(thisPackage, thisPackage.getOutageCalendarCollection());	if(thisPackage.getOutageCalendarCollection().contains(theOutage.getName())) {		enabledOutages.add("threshold-"+thisPackage.getName());	}	   }// ******* Polling outages config *********   PollerConfigFactory.init();   Map pollingOutages=new HashMap();   org.opennms.netmgt.config.poller.Package[] pollingPackages=PollerConfigFactory.getInstance().getConfiguration().getPackage();   for(int i=0; i<pollingPackages.length; i++) {	org.opennms.netmgt.config.poller.Package thisPackage=pollingPackages[i];	pollingOutages.put(thisPackage, thisPackage.getOutageCalendarCollection());	if(thisPackage.getOutageCalendarCollection().contains(theOutage.getName())) {		enabledOutages.add("polling-"+thisPackage.getName());	}	   }// ******* Collectd outages config *********   CollectdConfigFactory.init();   Map collectionOutages=new HashMap();   org.opennms.netmgt.config.collectd.Package[] collectionPackages=CollectdConfigFactory.getInstance().getConfiguration().getPackage();   for(int i=0; i<collectionPackages.length; i++) {	org.opennms.netmgt.config.collectd.Package thisPackage=collectionPackages[i];	collectionOutages.put(thisPackage, thisPackage.getOutageCalendarCollection());	if(thisPackage.getOutageCalendarCollection().contains(theOutage.getName())) {		enabledOutages.add("collect-"+thisPackage.getName());	}	   }      String isFormSubmission=request.getParameter("formSubmission");   if("true".equals(isFormSubmission)) {	//Process the form submission - yeah, this should be a servlet, but this is a quick and dirty hack for now	//It can be tidied up later	//First, process any changes to the editable inputs	theOutage.setType(request.getParameter("outageType"));			//Process the notifications status.  NB: we keep an in-memory copy initially, and only save when the save button is clicked	if("on".equals(request.getParameter("notifications"))) {		//Want to turn it on.		enabledOutages.add("notifications");	} else {		//Want to turn off (missing, or set to something other than "on")		enabledOutages.remove("notifications");	}	Iterator keys=pollingOutages.keySet().iterator();	while(keys.hasNext()) {		org.opennms.netmgt.config.poller.Package thisKey=(org.opennms.netmgt.config.poller.Package)keys.next();		String name="polling-"+thisKey.getName();		System.out.println("Checking "+name);		if("on".equals(request.getParameter(name))) {			System.out.println(" is on - adding to enabledOutages");			enabledOutages.add(name);		} else {			enabledOutages.remove(name);		}	}		keys=thresholdOutages.keySet().iterator();        while(keys.hasNext()) {                org.opennms.netmgt.config.threshd.Package thisKey=(org.opennms.netmgt.config.threshd.Package)keys.next();		String name="threshold-"+thisKey.getName();		System.out.println("Checking "+name);                if("on".equals(request.getParameter(name))) {			enabledOutages.add(name);                } else {			enabledOutages.remove(name);                }        }	keys=collectionOutages.keySet().iterator();        while(keys.hasNext()) {                org.opennms.netmgt.config.collectd.Package thisKey=(org.opennms.netmgt.config.collectd.Package)keys.next();		String name="collect-"+thisKey.getName();		System.out.println("Checking "+name);                if("on".equals(request.getParameter(name))) {			enabledOutages.add(name);                } else {			enabledOutages.remove(name);                }        }	//Now handle any buttons that were clicked.  There should be only one	//If there is more than one, we use the first and ignore the rest.	if(request.getParameter("saveButton")!=null) {		//Save was clicked - save 			//Check if the outage is a new one, or an edited old one		String origname=(String)request.getSession().getAttribute("opennms.editoutage.origname");		if(origname==null) {			//A new outage - just plonk it in place			pollFactory.addOutage(theOutage);		} else {			//An edited outage - replace the old one			pollFactory.replaceOutage(pollFactory.getOutage(origname), theOutage);		}		//Push the enabledOutages into the actual configuration of the various packages		//Don't do until after we've successfully put the outage into the polloutages configuration (for coherency)		if(enabledOutages.contains("notifications")) {			if(!notificationOutages.contains(theOutage.getName())) {				NotifdConfigFactory.getInstance().getConfiguration().addOutageCalendar(theOutage.getName());			}		} else {			if(notificationOutages.contains(theOutage.getName())) {				NotifdConfigFactory.getInstance().getConfiguration().removeOutageCalendar(theOutage.getName());			} 		}			keys=pollingOutages.keySet().iterator();		while(keys.hasNext()) {			org.opennms.netmgt.config.poller.Package thisKey=(org.opennms.netmgt.config.poller.Package)keys.next();			Collection pollingPackage=(Collection)pollingOutages.get(thisKey);			String name="polling-"+thisKey.getName();			if(enabledOutages.contains(name)) {				if(!pollingPackage.contains(theOutage.getName())) {					thisKey.addOutageCalendar(theOutage.getName());				}			} else {				if(pollingPackage.contains(theOutage.getName())) {					thisKey.removeOutageCalendar(theOutage.getName());				}			}		}		keys=thresholdOutages.keySet().iterator();	        while(keys.hasNext()) {	                org.opennms.netmgt.config.threshd.Package thisKey=(org.opennms.netmgt.config.threshd.Package)keys.next();	                Collection thresholdPackage=(Collection)thresholdOutages.get(thisKey);			String name="threshold-"+thisKey.getName();			if(enabledOutages.contains(name)) {	                        if(!thresholdPackage.contains(theOutage.getName())) {	                                thisKey.addOutageCalendar(theOutage.getName());	                        }	                } else {	                        if(thresholdPackage.contains(theOutage.getName())) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -