TWaver Forums
http://twaver.servasoft.com/forum/

subnetwork 显示当前子网中,有告警的设备总数
http://twaver.servasoft.com/forum/viewtopic.php?f=17&t=5343
Page 1 of 1

Author:  cati_zheng [ 2015-09-14 19:25 ]
Post subject:  subnetwork 显示当前子网中,有告警的设备总数

目前,子网中有10个设备,有2个设备有告警,告警条数分别为4条、5条。想在子网上,直接显示有告警的设备数,也就是2。
我想到的解决办法就是统计子网下的设备数2个,然后根据设备数生成2条告警,再挂到子网上。
有没有其他方法实现?

Author:  Chao [ 2015-09-17 10:50 ]
Post subject:  Re: subnetwork 显示当前子网中,有告警的设备总数

您好,您的需求就是子网向上传播告警的时候,换一种显示方式,而不是用原来默认的加边框的形式吧?这种新的显示方式需要能标注其告警子节点的数量?

Author:  cati_zheng [ 2015-09-22 9:38 ]
Post subject:  Re: subnetwork 显示当前子网中,有告警的设备总数

Chao wrote:
您好,您的需求就是子网向上传播告警的时候,换一种显示方式,而不是用原来默认的加边框的形式吧?这种新的显示方式需要能标注其告警子节点的数量?

嗯,就是这个效果。怎么方便实现

Author:  paul [ 2015-09-22 10:35 ]
Post subject:  Re: subnetwork 显示当前子网中,有告警的设备总数

还有个疑问是如果父亲本身也有告警,那孩子累计的告警数和自己的告警数要叠加,还是怎么处理?
下面的实现是直接用孩子累计的告警覆盖了父亲的告警,通过重写twaver.AlarmStatePropagator.prototype.propagateToParent实现:
Code:
      twaver.AlarmStatePropagator.prototype.propagateToParent = function (child, parent) {
        var result = null,
          count = 0;
        if (parent.hasChildren()) {
          parent.getChildren().forEach(function (child) {
            if (child.getAlarmState().getHighestNativeAlarmSeverity() != null) {
              count ++;
            }
            var severity = child.getAlarmState().getHighestOverallAlarmSeverity();
            if (twaver.AlarmSeverity.compare(severity, result) > 0) {
              result = severity;
            }
          });
          parent.getAlarmState().clear();
          if (result != null) {
            parent.getAlarmState().setNewAlarmCount(result, count);
          }
        }
      }

Attachment:
Screen Shot 2015-09-22 at 10.34.47 AM.png
Screen Shot 2015-09-22 at 10.34.47 AM.png [ 19.1 KiB | Viewed 22943 times ]

完整代码:
Code:
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="pragma" content="no-cache">
  <meta charset="UTF-8">
  <title></title>
  <script type="text/javascript" src="../twaver.js"></script>
  <script type="text/javascript">
   
    var box = new twaver.ElementBox();
    var network = new twaver.vector.Network(box);
    var toolbar = document.createElement('div');
   
    function init () {
      twaver.Styles.setStyle('select.style', 'border');
      initToolbar();
      var pane = new twaver.controls.BorderPane(network, toolbar);
      pane.setTopHeight(25);
      var view = pane.getView();
      view.style.left = '0px';
      view.style.top = '0px';
      view.style.right = '0px';
      view.style.bottom = '0px';
      document.body.appendChild(view);
      window.onresize = function () {
        pane.invalidate();
      };
   
      twaver.AlarmStatePropagator.prototype.propagateToParent = function (child, parent) {
        var result = null,
          count = 0;
        if (parent.hasChildren()) {
          parent.getChildren().forEach(function (child) {
            if (child.getAlarmState().getHighestNativeAlarmSeverity() != null) {
              count ++;
            }
            var severity = child.getAlarmState().getHighestOverallAlarmSeverity();
            if (twaver.AlarmSeverity.compare(severity, result) > 0) {
              result = severity;
            }
          });
          parent.getAlarmState().clear();
          if (result != null) {
            parent.getAlarmState().setNewAlarmCount(result, count);
          }
        }
      }
      initBox();
    }
   
    function initBox () {
      var group = new twaver.Group();
      group.setExpanded(true);
      box.add(group);

      var from = new twaver.Node();
      from.setName('From');
      from.getAlarmState().increaseNewAlarm(twaver.AlarmSeverity.CRITICAL);
      from.setLocation(100, 100);
      group.addChild(from);
      box.add(from);
     
      var to = new twaver.Group();
      to.setName('To');
      to.getAlarmState().increaseNewAlarm(twaver.AlarmSeverity.MAJOR);
      to.setLocation(300, 300);
      group.addChild(to);
      box.add(to);
     
      var link = new twaver.Link(from, to);
      link.setName('Link');
      group.addChild(link);
      box.add(link);
    }
   
    function initToolbar() {
      addButton(toolbar, 'Zoom In', function () {
        network.zoomIn();
      });
      addButton(toolbar, 'Zoom Out', function () {
        network.zoomOut();
      });
      addButton(toolbar, 'Zoom Overview', function () {
        network.zoomOverview();
      });
      addButton(toolbar, 'Zoom Reset', function () {
        network.zoomReset();
      });
    }
   
    function addButton(toolbar, label, handler) {
      var button = document.createElement('input');
      button.type = 'button';
      button.value =  label;
      button.onclick = handler;
      toolbar.appendChild(button);
    }
   
  </script>
</head>
<body onload="init()">
</body>
</html>

Author:  paul [ 2015-09-22 10:54 ]
Post subject:  Re: subnetwork 显示当前子网中,有告警的设备总数

抱歉,上面是HTML5的实现,.Net实现如下,替换demo中的PSTNDemo:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Demo;
using Demo.Topology.PSTN;
using TWaver;
using TWaver.Network;
using System.Windows.Threading;

namespace Demo.Topology
{
    public partial class PSTNDemo : UserControl, IDemo
    {
        private const string BLINK = "blink";

        private ElementBox box;
        private Network network;
        private Overview overview;

        public PSTNDemo()
        {
            InitializeComponent();
            InitBox();
            DemoUtils.InitToolbar(this.network, Toolbar);
            this.LayoutRoot.Children.Add(this.network);
            this.overview = DemoUtils.InitOverview(this.network, this.LayoutRoot);
        }

        private void InitBox()
        {
            this.network = new Network();
            this.box = this.network.ElementBox;

            box.AlarmStatePropagator.IsEnable = false;
            new CustomAlarmStatePropagator(box).IsEnable = true;

            var group = new Group();
            group.IsExpanded = true;
            box.Add(group);

            var from = new Node();
            from.Name = "From";
            from.AlarmState.IncreaseNewAlarm(AlarmSeverity.CRITICAL);
            from.SetLocation(100, 100);
            group.AddChild(from);
            box.Add(from);
     
            var to = new Group();
            to.Name = "To";
            to.AlarmState.IncreaseNewAlarm(AlarmSeverity.MAJOR);
            to.SetLocation(300, 300);
            group.AddChild(to);
            box.Add(to);
     
            var link = new Link(from, to);
            link.Name = "Link";
            group.AddChild(link);
            box.Add(link);
        }

        private void Tick()
        {
           
        }

        public Network Network
        {
            get { return this.network; }
        }

        public void OnShown()
        {
            this.overview.SetVisible(true);
        }

        public void OnHidden()
        {
            this.overview.SetVisible(false);
        }
    }

    public class CustomAlarmStatePropagator : AlarmStatePropagator
    {
        public CustomAlarmStatePropagator(ElementBox elementBox)
            :base(elementBox)
        {

        }

        protected override void PropagateToParent(IElement child, IElement parent)
        {
            AlarmSeverity result = null;
            uint count = 0;
            if (parent.HasChildren)
            {
                foreach (IData c in parent.Children)
                {
                    IElement element = (IElement)c;
                    if (element.AlarmState.HighestNativeAlarmSeverity != null)
                    {
                        count++;
                    }
                    var severity = element.AlarmState.HighestOverallAlarmSeverity;
                    if (AlarmSeverity.Compare(severity, result) > 0)
                    {
                        result = severity;
                    }
                }
                parent.AlarmState.Clear();
                if (result != null)
                {
                    parent.AlarmState.SetNewAlarmCount(result, count);
                }
            }
        }
    }
}

Author:  cati_zheng [ 2015-09-22 14:53 ]
Post subject:  Re: subnetwork 显示当前子网中,有告警的设备总数

paul wrote:
还有个疑问是如果父亲本身也有告警,那孩子累计的告警数和自己的告警数要叠加,还是怎么处理?
下面的实现是直接用孩子累计的告警覆盖了父亲的告警,通过重写twaver.AlarmStatePropagator.prototype.propagateToParent实现:
Code:
      twaver.AlarmStatePropagator.prototype.propagateToParent = function (child, parent) {
        var result = null,
          count = 0;
        if (parent.hasChildren()) {
          parent.getChildren().forEach(function (child) {
            if (child.getAlarmState().getHighestNativeAlarmSeverity() != null) {
              count ++;
            }
            var severity = child.getAlarmState().getHighestOverallAlarmSeverity();
            if (twaver.AlarmSeverity.compare(severity, result) > 0) {
              result = severity;
            }
          });
          parent.getAlarmState().clear();
          if (result != null) {
            parent.getAlarmState().setNewAlarmCount(result, count);
          }
        }
      }

Attachment:
The attachment Screen Shot 2015-09-22 at 10.34.47 AM.png is no longer available

完整代码:
Code:
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="pragma" content="no-cache">
  <meta charset="UTF-8">
  <title></title>
  <script type="text/javascript" src="../twaver.js"></script>
  <script type="text/javascript">
   
    var box = new twaver.ElementBox();
    var network = new twaver.vector.Network(box);
    var toolbar = document.createElement('div');
   
    function init () {
      twaver.Styles.setStyle('select.style', 'border');
      initToolbar();
      var pane = new twaver.controls.BorderPane(network, toolbar);
      pane.setTopHeight(25);
      var view = pane.getView();
      view.style.left = '0px';
      view.style.top = '0px';
      view.style.right = '0px';
      view.style.bottom = '0px';
      document.body.appendChild(view);
      window.onresize = function () {
        pane.invalidate();
      };
   
      twaver.AlarmStatePropagator.prototype.propagateToParent = function (child, parent) {
        var result = null,
          count = 0;
        if (parent.hasChildren()) {
          parent.getChildren().forEach(function (child) {
            if (child.getAlarmState().getHighestNativeAlarmSeverity() != null) {
              count ++;
            }
            var severity = child.getAlarmState().getHighestOverallAlarmSeverity();
            if (twaver.AlarmSeverity.compare(severity, result) > 0) {
              result = severity;
            }
          });
          parent.getAlarmState().clear();
          if (result != null) {
            parent.getAlarmState().setNewAlarmCount(result, count);
          }
        }
      }
      initBox();
    }
   
    function initBox () {
      var group = new twaver.Group();
      group.setExpanded(true);
      box.add(group);

      var from = new twaver.Node();
      from.setName('From');
      from.getAlarmState().increaseNewAlarm(twaver.AlarmSeverity.CRITICAL);
      from.setLocation(100, 100);
      group.addChild(from);
      box.add(from);
     
      var to = new twaver.Group();
      to.setName('To');
      to.getAlarmState().increaseNewAlarm(twaver.AlarmSeverity.MAJOR);
      to.setLocation(300, 300);
      group.addChild(to);
      box.add(to);
     
      var link = new twaver.Link(from, to);
      link.setName('Link');
      group.addChild(link);
      box.add(link);
    }
   
    function initToolbar() {
      addButton(toolbar, 'Zoom In', function () {
        network.zoomIn();
      });
      addButton(toolbar, 'Zoom Out', function () {
        network.zoomOut();
      });
      addButton(toolbar, 'Zoom Overview', function () {
        network.zoomOverview();
      });
      addButton(toolbar, 'Zoom Reset', function () {
        network.zoomReset();
      });
    }
   
    function addButton(toolbar, label, handler) {
      var button = document.createElement('input');
      button.type = 'button';
      button.value =  label;
      button.onclick = handler;
      toolbar.appendChild(button);
    }
   
  </script>
</head>
<body onload="init()">
</body>
</html>

感谢你的回答。最终要的效果已经实现。subnetwork(父)下有无限层的subnetwork(父),最终我需要的是node(子)类型的告警统计。

Attachments:
jietu.png
jietu.png [ 17.87 KiB | Viewed 22941 times ]

Author:  Jeff.Fu [ 2015-10-08 17:30 ]
Post subject:  Re: subnetwork 显示当前子网中,有告警的设备总数

:love:

Page 1 of 1 All times are UTC + 8 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/