首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

告警规约算法 RealTimeAlarm 01

2012-08-21 
告警规则算法 RealTimeAlarm 01import java.util.Iteratorimport java.util.Listimport java.util.Mapi

告警规则算法 RealTimeAlarm 01
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.huawei.ngbss.esbm.notifyhandler.webservice.EsbmIntfServiceStub;
import com.huawei.ngbss.esbm.notifyhandler.webservice.NotifyRequestDocument;
import com.huawei.ngbss.esbm.notifyhandler.webservice.ResultHeaderDocument;
import com.huawei.ngbss.esbm.notifyhandler.webservice.NotifyRequestDocument.NotifyRequest;
import com.huawei.ngbss.esbm.notifyhandler.webservice.NotifyRequestDocument.NotifyRequest.Body;
import com.huawei.ngbss.esbm.notifyhandler.webservice.NotifyRequestDocument.NotifyRequest.Header;

public class RealTimeAlarm
{
    private static Logger logger = Logger.getLogger(RealTimeAlarm.class);

    private RealTimeAlarm()
    {

    }

    public static void realTimecheck(Map<String, String> values)
    {
        logger.debug("realTimecheck flag:" + values.get("flag"));
        boolean result = false;
        String ruleid = null;
        // 检测网络异常以及系统超时情况
        if ("3".equals(values.get("flag")) || "4".equals(values.get("flag")))
        {
            result = true;
            ruleid = "";
        }
        // 如果没有超时
        if (result == false)
        {
            String realValue = null;
            String key_name = null;
            String wsdl = null;
            // 进行规则匹配,遍历规则
            for (Map.Entry<String, List<Rule>> entry : RuleTools.getRuleMap()
                    .entrySet())
            {
                logger.debug("Rule size:" + RuleTools.getRuleMap().size());
                Iterator<Rule> iterator = entry.getValue().iterator();
                Rule ruleCompare = null;
                ruleid = entry.getKey();
                while (iterator.hasNext())
                {
                    ruleCompare = iterator.next();
                    // 真实的数据与规则中的content进行比较
                    key_name = ruleCompare.getKey();
                    // 特殊处理,如果规则条件中有servicename,那么需要将在前面增加wsdl的值还有一个点,
                    // 格式:wsdl.servicename.还有可能是OCS的工单wsdl.servicename.operateid
                    if (key_name.equals("servicename"))
                    {
                        wsdl = values.get("wsdl");
                        wsdl = wsdl == null ? "" : wsdl;
                        realValue = values.get("key_name");
                        realValue=realValue==null?"":realValue;
                        realValue=wsdl+"."+realValue;
                    }
                    else
                    {
                        realValue=values.get(ruleCompare.getKey());
                    }
                    if(logger.isDebugEnabled())
                    {
                        logger.debug("ruleCompare:" + ruleCompare.toString()
                                + " and realValue : " + realValue);
                    }
                    result=ruleCompare.compare(realValue);
                 // 如果规则匹配不成功,不需要发实时告警,直接跳出while循环,下一个规则匹配
                    if(result==false)
                    {
                        break;
                    }
                }
                // 如果已经有规则匹配成功,不需要匹配下个rule
                if(result==true)
                {
                    break;
                }
            }
        }
        logger.debug("The result of realTimecheck is:" + result);
        // 需要发实时告警
        if(result==true)
        {
            logger.debug("Sending real time message to ESBM");
            EsbmIntfServiceStub stup;
            //构造发实时告警消息
            NotifyRequestDocument doc=null;
            try
            {

热点排行