Esempio n. 1
0
        /// <summary>
        /// 在m_NMAlarms中放一个空告警,其告警级别设置为sev
        /// </summary>
        /// <param name="omcname"></param>
        /// <param name="obj"></param>
        /// <param name="name"></param>
        /// <param name="sev"></param>
        public void DeclareNMMonitorObjects(string omcname, string obj, string name, string sev)
        {
            lock (m_NMAlarms)
            {
                if (!m_NMAlarms.ContainsKey(omcname))
                {
                    m_NMAlarms.Add(omcname, new Dictionary <string, Dictionary <string, NMAlarm> >());
                }

                if (!m_NMAlarms[omcname].ContainsKey(obj))
                {
                    m_NMAlarms[omcname].Add(obj, new Dictionary <string, NMAlarm>());
                }

                NMAlarm alarm = new NMAlarm(UniteTKActiveTable, UniteTKResumeTable);
                alarm.Severity = sev;

                m_NMAlarms[omcname][obj][name] = alarm;
            }
        }
Esempio n. 2
0
        public void ClearAllNMAlarms()
        {
            lock (m_NMAlarms)
            {
                foreach (Dictionary <string, Dictionary <string, NMAlarm> > omcalarms in m_NMAlarms.Values)
                {
                    foreach (Dictionary <string, NMAlarm> objalarms in omcalarms.Values)
                    {
                        try
                        {
                            foreach (NMAlarm a in objalarms.Values)
                            {
                                if (a.TKSn != "" && a.ClearTime == "") //未恢复的告警应发至服务器恢复之
                                {
                                    //a.ClearTime = DateTime.Now.ToString();
                                    ClearNMAlarm(a.SourceOMC, a.Object, a.AlarmName, DateTime.Now);
                                    //TKAlarm tkalarm = ConvertNMToTKAlarm(a);
                                    //SendAlarm(tkalarm);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SendLog(ex.ToString()); // 监控模块产生的异常无法再作为告警处理
                        }

                        string[] keys = new string[objalarms.Count];
                        objalarms.Keys.CopyTo(keys, 0);
                        foreach (string alarmname in keys)
                        {
                            NMAlarm alarm = new NMAlarm(UniteTKActiveTable, UniteTKResumeTable);
                            alarm.Severity       = objalarms[alarmname].Severity;
                            objalarms[alarmname] = alarm;
                        }
                    }
                }
            } // endlock
        }
Esempio n. 3
0
        public TKAlarm ConvertNMToTKAlarm(NMAlarm a)
        {
            TKAlarm tkalarm = new TKAlarm();

            tkalarm.OMCName      = NMAlarm.OMCName;
            tkalarm.Manufacturer = NMAlarm.Manufacturer;
            tkalarm.BusinessType = NMAlarm.BusinessType;

            tkalarm.NeName    = a.SourceOMC;
            tkalarm.ObjName   = a.Object;
            tkalarm.AlarmName = tkalarm.Redefinition = a.AlarmName;
            tkalarm.OccurTime = a.OccurTime;
            tkalarm.Reserved2 = a.LastOccurTime;
            tkalarm.ClearTime = a.ClearTime;
            tkalarm.Location  = tkalarm.NeName + "//" + tkalarm.ObjName;

            if (a.Detail.Length > 120)
            {
                tkalarm.Reserved3 = a.Detail.Substring(0, 120);
            }
            else
            {
                tkalarm.Reserved3 = a.Detail;
            }

            tkalarm.Severity = a.Severity;

            if (a.TKSn == "")
            {
                a.TKSn = AllocateTKSN().ToString();
            }

            tkalarm.TKSn = a.TKSn;

            return(tkalarm);
        }
Esempio n. 4
0
        /// <summary>
        /// 更新界面状态
        /// </summary>
        /// <param name="sourceomc"></param>
        /// <param name="obj"></param>
        /// <param name="name"></param>
        /// <param name="detail"></param>
        /// <param name="occurtime"></param>
        /// <returns></returns>
        public bool RaiseNMAlarm(string sourceomc, string obj, string name, string detail, DateTime occurtime)
        {
            TKAlarm tkalarm = null;

            try
            {
                lock (m_NMAlarms)
                {
                    if (!m_NMAlarms.ContainsKey(sourceomc))
                    {
                        return(false);
                    }

                    if (!m_NMAlarms[sourceomc].ContainsKey(obj))
                    {
                        return(false);
                    }

                    if (!m_NMAlarms[sourceomc][obj].ContainsKey(name))
                    {
                        return(false);
                    }

                    NMAlarm a = m_NMAlarms[sourceomc][obj][name];
                    if (a.TKSn != "" && a.ClearTime == "")
                    {
                        a.LastOccurTime = occurtime.ToString();
                        return(false); // 告警已经发生过,尚未恢复
                    }

                    a.SourceOMC     = sourceomc;
                    a.Object        = obj;
                    a.AlarmName     = name;
                    a.OccurTime     = occurtime.ToString();
                    a.LastOccurTime = occurtime.ToString();
                    a.ClearTime     = "";
                    a.Detail        = detail;
                    a.TKSn          = "";
                    a.ActiveTable   = UniteTKActiveTable;
                    a.ResumeTable   = UniteTKResumeTable;

                    tkalarm = ConvertNMToTKAlarm(a);

                    try
                    {
                        TempStorageHelper.Instance().Store <NMAlarm>(Convert.ToInt64(a.TKSn), a);
                        SqlHelper.ExecuteNonQuery(Connstr, CommandType.Text, a.GetSql());
                        TempStorageHelper.Instance().Clear <NMAlarm>(Convert.ToInt64(a.TKSn));
                    }
                    catch (Exception ex)
                    {
                        // 存储网管告警出异常不再发出告警
                        // 不继续抛出告警, 允许继续往服务器发送告警
                        SendLog(ex.ToString());
                    }
                }

                try
                {
                    if (tkalarm != null)
                    {
                        SendAlarm(tkalarm);
                    }
                }
                catch (Exception ex)
                {
                    // 向服务器发送告警失败,只记录日志,不影响程序运行
                    SendLog(ex.ToString());
                    return(false);
                }
            }
            catch (Exception ex)
            {
                SendLog(ex.ToString());
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        virtual protected void _checkNMActiveConsistency(string omcName, string omcConn)
        {
            // A - B
            string q = "select * from " + UniteTKActiveTable + " where SourceOMC='" + omcName + "'";

            q += " and TKSn not in (select TKSn from " + UniteActiveTable + " where OMCName='" + NMAlarm.OMCName + "')"; // OMCName也是全局唯一,不追加使用Manufacturer

            DataSet ds = new DataSet();

            try
            {
                SqlHelper.FillDataset(Connstr, CommandType.Text, q, ds, new string[] { "temp" });

                ClearNMAlarm(omcName, Constants.MO_SYSDB, Constants.TKALM_SYSDBALM, DateTime.Now);
            }
            catch (SqlException ex)
            {
                RaiseNMAlarm(omcName, Constants.MO_SYSDB, Constants.TKALM_SYSDBALM, ex.Message, DateTime.Now);
                SendLog(ex.ToString());
            }

            List <TKAlarm> pending = new List <TKAlarm>();

            foreach (DataRow r in ds.Tables["temp"].Rows)
            {
                NMAlarm sourcealarm = new NMAlarm();
                sourcealarm.ActiveTable = UniteTKActiveTable;
                sourcealarm.ResumeTable = UniteTKResumeTable;
                sourcealarm.BuildFromDB(r);

                TKAlarm tkalarm = ConvertNMToTKAlarm(sourcealarm);
                pending.Add(tkalarm);

                if (PendingRunFlag == 0)
                {
                    return;
                }
            }

            // (B-A)
            q  = "select * from " + UniteActiveTable + " where OMCName='" + NMAlarm.OMCName + "' and NEName='" + omcName + "'";
            q += " and TKSn not in (select TKSn from " + UniteTKActiveTable + " where SourceOMC='" + omcName + "')";

            ds.Tables.Clear();
            try
            {
                SqlHelper.FillDataset(Connstr, CommandType.Text, q, ds, new string[] { "temp" });

                ClearNMAlarm(omcName, Constants.MO_SYSDB, Constants.TKALM_SYSDBALM, DateTime.Now);
            }
            catch (Exception ex)
            {
                RaiseNMAlarm(omcName, Constants.MO_SYSDB, Constants.TKALM_SYSDBALM, ex.Message, DateTime.Now);
                SendLog(ex.ToString());
            }

            foreach (DataRow r in ds.Tables["temp"].Rows)
            {
                int tksn = Convert.ToInt32(r["TKSn"]);

                q = "select * from " + UniteTKResumeTable + " where tksn=" + tksn;

                try
                {
                    DataSet temp = new DataSet();
                    SqlHelper.FillDataset(Connstr, CommandType.Text, q, temp, new string[] { "temp" });

                    ClearNMAlarm(omcName, Constants.MO_SYSDB, Constants.TKALM_SYSDBALM, DateTime.Now);

                    if (temp.Tables["temp"].Rows.Count == 0)
                    {
                        // 作为垃圾告警处理
                        TKAlarm tkalarm_garbage = new TKAlarm();
                        tkalarm_garbage.ConvertFromDB(r);
                        tkalarm_garbage.ClearTime = Constants.GARBAGE_CLEARTIME;

                        SendAlarm(tkalarm_garbage);
                    }
                    else
                    {
                        NMAlarm sourcealarm_r = new NMAlarm(UniteActiveTable, UniteResumeTable);
                        //sourcealarm_r.ActiveTable = UniteTKActiveTable;
                        //sourcealarm_r.ResumeTable = UniteTKResumeTable;
                        sourcealarm_r.BuildFromDB(temp.Tables["temp"].Rows[0]);

                        TKAlarm alarm = ConvertNMToTKAlarm(sourcealarm_r);
                        pending.Add(alarm);
                    }
                }
                catch (SqlException ex)
                {
                    RaiseNMAlarm(omcName, Constants.MO_SYSDB, Constants.TKALM_SYSDBALM, ex.Message, DateTime.Now);
                    SendLog(ex.ToString());
                }

                if (PendingRunFlag == 0)
                {
                    return;
                }
            }

            SendAlarms(pending);
        }
Esempio n. 6
0
        /// <summary>
        /// 清楚告警,此处没用到
        /// </summary>
        /// <param name="sourceomc"></param>
        /// <param name="obj"></param>
        /// <param name="name"></param>
        /// <param name="cleartime"></param>
        /// <returns></returns>
        public bool ClearNMAlarm(string sourceomc, string obj, string name, DateTime cleartime)
        {
            try
            {
                TKAlarm tkalarm = null;
                lock (m_NMAlarms)
                {
                    if (!m_NMAlarms.ContainsKey(sourceomc))
                    {
                        return(false);
                    }

                    if (!m_NMAlarms[sourceomc].ContainsKey(obj))
                    {
                        return(false);
                    }

                    if (!m_NMAlarms[sourceomc][obj].ContainsKey(name))
                    {
                        return(false);
                    }

                    NMAlarm a = m_NMAlarms[sourceomc][obj][name];
                    if (a.TKSn == "" || a.ClearTime != "")
                    {
                        return(false); //告警已经恢复,恢复动作无效
                    }
                    a.ClearTime   = cleartime.ToString();
                    a.ActiveTable = UniteTKActiveTable;
                    a.ResumeTable = UniteTKResumeTable;

                    tkalarm = ConvertNMToTKAlarm(a);

                    try
                    {
                        SqlHelper.ExecuteNonQuery(Connstr, CommandType.Text, a.GetSql());
                    }
                    catch (Exception ex)
                    {
                        // 存储网管告警出异常不再发出告警
                        // 不继续抛出告警, 允许继续往服务器发送告警
                        SendLog(ex.ToString());
                    }
                }

                try
                {
                    if (tkalarm != null)
                    {
                        SendAlarm(tkalarm);
                    }
                }
                catch (Exception ex)
                {
                    SendLog(ex.ToString());
                    return(false);
                }
            }
            catch (Exception ex)
            {
                SendLog(ex.ToString());
                return(false);
            }

            return(true);
        }