notifdtest.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 833 行 · 第 1/3 页

JAVA
833
字号
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2005 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.                                                            //// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//    // For more information contact: //   OpenNMS Licensing       <license@opennms.org>//   http://www.opennms.org///   http://www.opennms.com///// Tab Size = 8package org.opennms.netmgt.notifd;import java.io.IOException;import java.sql.ResultSet;import java.sql.SQLException;import java.text.DateFormat;import java.util.Arrays;import java.util.Collection;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import junit.framework.TestCase;import org.exolab.castor.xml.MarshalException;import org.exolab.castor.xml.ValidationException;import org.opennms.core.utils.TimeConverter;import org.opennms.netmgt.EventConstants;import org.opennms.netmgt.config.DatabaseConnectionFactory;import org.opennms.netmgt.config.NotificationCommandManager;import org.opennms.netmgt.config.NotificationManager;import org.opennms.netmgt.config.groups.Group;import org.opennms.netmgt.config.notifications.Notification;import org.opennms.netmgt.config.users.Contact;import org.opennms.netmgt.config.users.User;import org.opennms.netmgt.mock.MockDatabase;import org.opennms.netmgt.mock.MockEventIpcManager;import org.opennms.netmgt.mock.MockInterface;import org.opennms.netmgt.mock.MockNetwork;import org.opennms.netmgt.mock.MockNode;import org.opennms.netmgt.mock.MockService;import org.opennms.netmgt.mock.MockUtil;import org.opennms.netmgt.notifd.mock.MockDestinationPathManager;import org.opennms.netmgt.notifd.mock.MockGroupManager;import org.opennms.netmgt.notifd.mock.MockNotifdConfigManager;import org.opennms.netmgt.notifd.mock.MockNotification;import org.opennms.netmgt.notifd.mock.MockNotificationCommandManager;import org.opennms.netmgt.notifd.mock.MockNotificationManager;import org.opennms.netmgt.notifd.mock.MockNotificationStrategy;import org.opennms.netmgt.notifd.mock.MockUserManager;import org.opennms.netmgt.notifd.mock.NotificationAnticipator;import org.opennms.netmgt.utils.RowProcessor;import org.opennms.netmgt.xml.event.Event;/** * @author david * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */public class NotifdTest extends TestCase {    private Notifd m_notifd;    private MockEventIpcManager m_eventMgr;    private MockNotifdConfigManager m_notifdConfig;    private MockGroupManager m_groupManager;    private MockUserManager m_userManager;    private NotificationManager m_notificationManager;    private NotificationCommandManager m_notificationCommandManger;    private MockDestinationPathManager m_destinationPathManager;    private static String NOTIFD_CONFIG_MANAGER = "<?xml version=\"1.0\"?>\n" +             "<notifd-configuration \n" +             "        status=\"on\"\n" +             "        pages-sent=\"SELECT * FROM notifications\"\n" +             "        next-notif-id=\"SELECT nextval(\'notifynxtid\')\"\n" +             "        next-group-id=\"SELECT nextval(\'notifygrpid\')\"\n" +             "        service-id-sql=\"SELECT serviceID from service where serviceName = ?\"\n" +             "        outstanding-notices-sql=\"SELECT notifyid FROM notifications where notifyId = ? AND respondTime is not null\"\n" +             "        acknowledge-id-sql=\"SELECT notifyid FROM notifications WHERE eventuei=? AND nodeid=? AND interfaceid=? AND serviceid=?\"\n" +             "        acknowledge-update-sql=\"UPDATE notifications SET answeredby=?, respondtime=? WHERE notifyId=?\"\n" +             "   match-all=\"false\">\n" +             "        \n" +             "   <auto-acknowledge notify = \"true\" uei=\"uei.opennms.org/nodes/serviceResponsive\" \n" +             "                          acknowledge=\"uei.opennms.org/nodes/serviceUnresponsive\">\n" +             "                          <match>nodeid</match>\n" +             "                          <match>interfaceid</match>\n" +             "                          <match>serviceid</match>\n" +             "        </auto-acknowledge>\n" +             "   \n" +             "        <auto-acknowledge uei=\"uei.opennms.org/nodes/nodeRegainedService\" \n" +             "                          acknowledge=\"uei.opennms.org/nodes/nodeLostService\">\n" +             "                          <match>nodeid</match>\n" +             "                          <match>interfaceid</match>\n" +             "                          <match>serviceid</match>\n" +             "        </auto-acknowledge>\n" +             "        \n" +             "        <auto-acknowledge uei=\"uei.opennms.org/nodes/interfaceUp\" \n" +             "                          acknowledge=\"uei.opennms.org/nodes/interfaceDown\">\n" +             "                          <match>nodeid</match>\n" +             "                          <match>interfaceid</match>\n" +             "        </auto-acknowledge>\n" +             "        \n" +             "        <auto-acknowledge uei=\"uei.opennms.org/nodes/nodeUp\" \n" +             "                          acknowledge=\"uei.opennms.org/nodes/nodeDown\">\n" +             "                          <match>nodeid</match>\n" +             "        </auto-acknowledge>\n" +             "        \n" +             "        <queue>\n" +             "                <queue-id>default</queue-id>\n" +             "                <interval>100ms</interval>\n" +             "                <handler-class>\n" +             "                        <name>org.opennms.netmgt.notifd.DefaultQueueHandler</name>\n" +             "                </handler-class>\n" +             "        </queue>\n" +             "</notifd-configuration>";            private static final String NOTIFICATION_MANAGER = "<?xml version=\"1.0\"?>\n" +             "<notifications xmlns=\"http://xmlns.opennms.org/xsd/notifications\">\n" +             "    <header>\n" +             "        <rev>1.2</rev>\n" +             "        <created>Wednesday, February 6, 2002 10:10:00 AM EST</created>\n" +             "        <mstation>localhost</mstation>\n" +             "    </header>\n" +             "    <notification name=\"nodeDown\" status=\"on\">\n" +             "        <uei>uei.opennms.org/nodes/nodeDown</uei>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>NoEscalate</destinationPath>\n" +             "        <text-message>All services are down on node %nodeid%.</text-message>\n" +             "        <subject>node %nodeid% down.</subject>\n" +             "        <numeric-message>111-%noticeid%</numeric-message>\n" +             "    </notification>\n" +             "    <notification name=\"nodeUp\" status=\"on\">\n" +             "        <uei>uei.opennms.org/nodes/nodeUp</uei>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>UpPath</destinationPath>\n" +             "        <text-message>The node which was previously down is now up.</text-message>\n" +             "        <subject>node %nodeid% up.</subject>\n" +             "        <numeric-message>111-%noticeid%</numeric-message>\n" +             "    </notification>\n" +             "    <notification name=\"interfaceDown\" status=\"on\">\n" +             "        <uei>uei.opennms.org/nodes/interfaceDown</uei>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>Escalate</destinationPath>\n" +             "        <text-message>All services are down on interface %interface%, %ifalias%.</text-message>\n" + //          "        <text-message>All services are down on interface %interface%.</text-message>\n" +             "        <subject>interface %interface% down.</subject>\n" +             "        <numeric-message>222-%noticeid%</numeric-message>\n" +             "    </notification>\n" +             "    <notification name=\"interfaceUp\" status=\"on\">\n" +             "        <uei>uei.opennms.org/nodes/interfaceUp</uei>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>UpPath</destinationPath>\n" +             "        <text-message>The interface which was previously down is now up.</text-message>\n" +             "        <subject>interface %interface% up.</subject>\n" +             "        <numeric-message>222-%noticeid%</numeric-message>\n" +             "    </notification>\n" +             "    <notification name=\"nodeLostService\" status=\"on\">\n" +             "        <uei>uei.opennms.org/nodes/nodeLostService</uei>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>Intervals</destinationPath>\n" +             "        <text-message>Service %service% is down on interface %interface%.</text-message>\n" +             "        <subject>service %service% on %interface% down.</subject>\n" +             "        <numeric-message>333-%noticeid%</numeric-message>\n" +             "    </notification>\n" +             "    <notification name=\"nodeRegainedService\" status=\"on\">\n" +             "        <uei>uei.opennms.org/nodes/nodeRegainedService</uei>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>UpPath</destinationPath>\n" +             "        <text-message>Service %service% on interface %interface% has come back up.</text-message>\n" +             "        <subject>service %service% on %interface% up.</subject>\n" +             "        <numeric-message>333-%noticeid%</numeric-message>\n" +             "    </notification>\n" +             "     <notification name=\"SNMP High disk Threshold Exceeded\" status=\"on\">\n" +             "        <uei>uei.opennms.org/threshold/highThresholdExceeded</uei>\n" +             "        <description>high disk threshold exceeded on snmp interface</description>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>NoEscalate</destinationPath>\n" +             "        <text-message>High disk Threshold exceeded on %interface%, %parm[ds]% with %parm[value]%%%</text-message>\n" +             "        <subject>Notice #%noticeid%, High disk Threshold exceeded</subject>\n" +             "        <varbind>\n" +             "            <vbname>ds</vbname>\n" +             "            <vbvalue>dsk-usr-pcent</vbvalue>\n" +             "        </varbind>\n" +             "    </notification>\n" +             "    <notification name=\"SNMP High loadavg5 Threshold Exceeded\" status=\"on\">\n" +             "        <uei>uei.opennms.org/threshold/highThresholdExceeded</uei>\n" +             "        <description>high loadavg5 threshold exceeded on snmp interface</description>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>NoEscalate</destinationPath>\n" +             "        <text-message>High loadavg5 Threshold exceeded on %interface%, %parm[ds]% with %parm[value]%%%</text-message>\n" +             "        <subject>High loadavg5 Threshold exceeded</subject>\n" +             "        <varbind>\n" +             "            <vbname>ds</vbname>\n" +             "            <vbvalue>loadavg5</vbvalue>\n" +             "        </varbind>\n" +             "    </notification>" +            "    <notification name=\"nodeTimeTest\" status=\"on\">\n" +             "        <uei>uei.opennms.org/tests/nodeTimeTest</uei>\n" +             "        <rule>IPADDR IPLIKE *.*.*.*</rule>\n" +             "        <destinationPath>NoEscalate</destinationPath>\n" +             "        <text-message>Timestamp: %time%.</text-message>\n" +             "        <subject>time %time%.</subject>\n" +             "        <numeric-message>333-%noticeid%</numeric-message>\n" +             "    </notification>\n" +             "</notifications>\n" +             "";        public static final String GROUP_MANAGER = "<?xml version=\"1.0\"?>\n" +             "<groupinfo>\n" +             "    <header>\n" +             "        <rev>1.3</rev>\n" +             "        <created>Wednesday, February 6, 2002 10:10:00 AM EST</created>\n" +             "        <mstation>dhcp-219.internal.opennms.org</mstation>\n" +             "    </header>\n" +             "    <groups>\n" +             "        <group>\n" +             "            <name>InitialGroup</name>\n" +             "            <comments>The group that gets notified first</comments>\n" +             "            <user>admin</user>" +             "            <user>brozow</user>" +             "        </group>\n" +             "        <group>\n" +             "            <name>EscalationGroup</name>\n" +             "            <comments>The group things escalate to</comments>\n" +            "            <user>brozow</user>" +             "            <user>david</user>" +             "        </group>\n" +             "        <group>\n" +             "            <name>UpGroup</name>\n" +             "            <comments>The group things escalate to</comments>\n" +            "            <user>upUser</user>" +             "        </group>\n" +             "    </groups>\n" +             "</groupinfo>\n" +             "";    public static final String USER_MANAGER = "<?xml version=\"1.0\"?>\n" +             "<userinfo xmlns=\"http://xmlns.opennms.org/xsd/users\">\n" +             "   <header>\n" +             "       <rev>.9</rev>\n" +             "           <created>Wednesday, February 6, 2002 10:10:00 AM EST</created>\n" +             "       <mstation>master.nmanage.com</mstation>\n" +             "   </header>\n" +             "   <users>\n" +             "       <user>\n" +             "           <user-id>brozow</user-id>\n" +             "           <full-name>Mathew Brozowski</full-name>\n" +             "           <user-comments>Test User</user-comments>\n" +            "           <password>21232F297A57A5A743894A0E4A801FC3</password>\n" +            "           <contact type=\"email\" info=\"brozow@opennms.org\"/>\n" +             "       </user>\n" +             "       <user>\n" + 

⌨️ 快捷键说明

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