HT for Web 电信扩展手册

索引


告警

告警用于描述电信网管中网元的异常和错误信息。HT中网元有告警状态属性(ht.Data#getAlarmState(),类型为ht.AlarmState), 用于描述网元的告警信息。告警状态中记录了新发告警和确认告警对应于每一种告警级别(ht.AlarmSeverity)的告警数量。

告警级别

告警级别(ht.AlarmSeverity)用于描述告警的严重程度,具有如下属性:

默认告警级别

HT预定义了如下告警级别:

自定义告警级别

除了HT提供的默认告警级别,可以用如下方法添加自定义告警级别:

AlarmSeverity.add(value, name, nickName, color, displayName)

示例:

var trivial = ht.AlarmSeverity.add(50, 'Trivial', 'T', '#20B2AA');
console.assert(trivial === ht.AlarmSeverity.getByName('Trivial'),
	"trivial === ht.AlarmSeverity.getByName('Trivial')");

另外,ht.AlarmSeverity提供了如下Class方法和属性:

AlarmSeverity.severities
AlarmSeverity.each(callbackFunction, [scope])

循环所有告警级别,执行指定函数

AlarmSeverity.getSortFunction()

返回AlarmSeverity.setSortFunction(sortFunction)设置的告警级别排序函数,如果未设置,则返回默认的告警级别排序函数(按告警级别的value从小到大排序)

AlarmSeverity.setSortFunction(sortFunction)

设置告警级别排序函数

AlarmSeverity.remove(name)

按名称删除指定的告警级别

AlarmSeverity.isClearedAlarmSeverity(severity)
AlarmSeverity.getByName(name)
AlarmSeverity.getByValue(value)
AlarmSeverity.clear()

清空所有告警级别

AlarmSeverity.compare(severity1, severity2)

比较指定的两个告警级别

告警状态

告警状态(ht.AlarmState)是HT中网元的属性(Data#getAlarmState())。告警分新发告警(New Alarm)和确认告警(Acknowledged Alarm), 告警状态中记录了新发告警和确认告警对应于每一种告警级别(ht.AlarmSeverity)的告警数量。此外,告警状态还记录了传播告警级别(传播告警指网元所有孩子的最高告警级别)。

如果有新发告警,GraphView上样式note2被替换成新发告警信息,填充色为最高新发告警级别的颜色,文字为最高新发告警级别的数量和别名:

ht.GraphView.prototype.getNote2 = function (data) {
	var severity = data.getAlarmState().getHighestNewAlarmSeverity();
	if (severity) {
		var label = data.getAlarmState().getNewAlarmCount(severity) + severity.nickName;
		if (data.getAlarmState().hasLessSevereNewAlarms()) {
			label += "+";
		}
		return label;
	}
	return data.getStyle('note2');
};
ht.GraphView.prototype.getNote2Background = function (data) {
    var severity = data.getAlarmState().getHighestNewAlarmSeverity();
    if (severity) {
        return severity.color;
    }
    return data.getStyle('note2.background');
};

如果有确认告警,网元的填充色变为最高新发或确认告警级别的颜色:

ht.GraphView.prototype.getBodyColor = function (data) {
	var severity = data.getAlarmState().getHighestNativeAlarmSeverity();
	if (severity) {
		return severity.color;
	}
	return data.getStyle('body.color');
};

如果有传播告警,网元的边框颜色变为传播告警的颜色:

ht.GraphView.prototype.getBorderColor = function (data) {
	var severity = data.getAlarmState().getPropagateSeverity();
	if (severity) {
		return severity.color;
	}
	return data.getStyle('border.color');
};

示例:

操作

AlarmState#increaseNewAlarm(severity, [increment])

增加指定数量和级别的新发告警

AlarmState#decreaseNewAlarm(severity, [decrement])

减少指定数量和级别的新发告警

AlarmState#setNewAlarmCount(severity, count)

设置指定级别的新发告警数量

AlarmState#removeAllNewAlarms(severity)

清除所有新发告警

AlarmState#acknowledgeAlarm(severity)

确认一条指定级别的新发告警

AlarmState#acknowledgeAllAlarms([severity])

确认指定级别的所有新发告警,如果severity参数省略,则确认所有级别的新发告警

AlarmState#increaseAcknowledgedAlarm(severity, [increment])

增加指定数量和级别的确认告警

AlarmState#decreaseAcknowledgedAlarm(severity, [decrement])

减少指定数量和级别的确认告警

AlarmState#setAcknowledgedAlarmCount(severity, count)

设置指定级别的确认告警数量

AlarmState#removeAllAcknowledgedAlarms(severity)

清除所有确认告警

AlarmState#clear()

清除所有新发和确认告警

AlarmState#setPropagateSeverity(severity)

设置传播告警级别

AlarmState#setEnablePropagation(value)

设置是否启用告警传播,默认值为true

查询

AlarmState#getHighestAcknowledgedAlarmSeverity()
AlarmState#getHighestNewAlarmSeverity()
AlarmState#getHighestNativeAlarmSeverity()
AlarmState#getPropagateSeverity()
AlarmState#getHighestOverallAlarmSeverity()
AlarmState#hasLessSevereNewAlarms()
AlarmState#getNewAlarmCount(severity)
AlarmState#getAcknowledgedAlarmCount(severity)
AlarmState#getAlarmCount(severity)
AlarmState#isEmpty()
AlarmState#isEnablePropagation()

告警传播

HT中,告警传播ht.AlarmStatePropagator会将底层网元的告警往上层网元传播,比如GroupSubGraph中所有孩子的最高级别告警会传播到GroupSubGraph。 默认告警传播未开启,需要调用ht.DataModel#setEnableAlarmStatePropagator(true)开启告警传播。

自定义告警传播

默认告警传播是从孩子传播到父亲,可以重写ht.AlarmStatePropagatorpropagateToTop方法改变传播机制,下面例子演示了告警沿着host传播:

先关闭数据容器的告警传播(ht.DataModel#setEnableAlarmStatePropagator(false)),然后创建新的ht.AlarmStatePropagator对象,再重写 AlarmStatePropagator#handleDataPropertyChange(e)AlarmStatePropagator#propagateToTop(data)方法:

propagator.handleDataPropertyChange = function (e) {
	ht.AlarmStatePropagator.prototype.handleDataPropertyChange.call(this, e);
	if (e.property === 'host') {
    	var oldHost = e.oldValue;
		if (oldHost) {
			this.propagate(oldHost);
		}
		this.propagate(e.data);
	}
};
propagator.propagateToTop = function (data) {
	this.propagateToHost(null, data);
	while (data && data.getHost()) {
		this.propagateToHost(data, data.getHost());
		data = data.getHost();
	}
};
propagator.propagateToHost = function (attach, host) {
	var result = null;
	if (host.getAttaches()) {
		host.getAttaches().each(function (attach) {
			var severity = attach.getAlarmState().getHighestOverallAlarmSeverity();
			if (ht.AlarmSeverity.compare(severity, result) > 0) {
				result = severity;
			}
			});
		}
		host.getAlarmState().setPropagateSeverity(result);
	};

AlarmStatePropagator包含如下方法:

AlarmStatePropagator(dataModel)

构造函数,构建告警传播

AlarmStatePropagator#getDataModel()
AlarmStatePropagator#isEnable()
AlarmStatePropagator#setEnable(enable)

设置是否启用告警传播

AlarmStatePropagator#handleDataModelChange(e)

数据容器更改回调函数,处理告警传播

AlarmStatePropagator#handleDataPropertyChange(e)

数据属性更改回调函数,处理告警传播

AlarmStatePropagator#propagate(data)

传播告警

AlarmStatePropagator#propagateToTop(data)

传播告警到上层

AlarmStatePropagator#propagateToParent(data)

传播告警到父亲

告警统计

告警统计(ht.AlarmStateStatistics)用于统计数据容器中所有数据的各告警级别的新发、确认以及总数量。

AlarmStateStatistics(dataModel)

构造函数,创建告警统计对象

AlarmStateStatistics#getDataModel()
AlarmStateStatistics#setDataModel(dataModel)
AlarmStatePropagator#dispose()

销毁告警统计,删除对数据容器和数据的监听

AlarmStateStatistics#handleDataModelChange(e)

数据容器更改回调函数,重新统计告警数量

AlarmStateStatistics#handleDataPropertyChange(e)

数据属性更改回调函数,重新统计告警数量

AlarmStateStatistics#fireAlarmStateChange()

重新统计告警数量,派发alarmState更改事件

AlarmStateStatistics#getNewAlarmCount([severity])
AlarmStateStatistics#getAcknowledgedAlarmCount([severity])
AlarmStateStatistics#getTotalAlarmCount([severity])
AlarmStateStatistics#getSumInfo(severity)
AlarmStateStatistics#increase(data)

增加指定数据的告警

AlarmStateStatistics#decrease(data)

减少指定数据的告警

AlarmStateStatistics#reset()

重新统计告警数量

AlarmStateStatistics#getFilterFunc()
AlarmStateStatistics#setFilterFunc(value)

设置过滤函数,过滤不参与统计的数据

自定义告警统计面板

下面的例子演示了用矢量实现告警统计面板:

告警在树上的展示

默认树上节点的图标填充色是数据的最高新发或确认告警级别的颜色,如果有传播告警,树节点图标会加上颜色为传播告警级别颜色的边框:

ht.widget.TreeView.prototype.getIcon = ht.widget.TreeTableView.prototype.getIcon = function (data) {
	return '__alarmIcon__';
};
ht.Default.setImage('__alarmIcon__', {
    width: 18,
    height: 18,
    comps: [
        {
            type: 'image',
            name: {
                func: function (data) { return data.getIcon(); }
            },
            color: {
                func: function (data) {
                    var severity = data.getAlarmState().getHighestNativeAlarmSeverity();
                    if (severity) {
                        return severity.color;
                    }
                    return data.getStyle('body.color');
                }
            },
            rect: [1, 1, 16, 16]
        },
        {
            type: 'rect',
            borderWidth: 2,
            borderColor: {
                func: function (data) {
                    var severity = data.getAlarmState().getPropagateSeverity();
                    if (severity) {
                        return severity.color;
                    }
                    return data.getStyle('border.color');
                }
            },
            visible: {
                func: function (data) {
                    return !!data.getAlarmState().getPropagateSeverity() || !!data.getStyle('border.color');
                },
            },
            rect: [1, 1, 16, 16]
        }
    ]
});

下面的例子在树节点图标的左下角加上了小圆圈,代表最高级别的新发告警:

ht.Default.getImage('__alarmIcon__').comps.push({
    type: 'circle',
    gradient: 'radial.center',
    gradientColor: '#FFFFFF',
    background: {
        func: function (data) {
            var severity = data.getAlarmState().getHighestNewAlarmSeverity();
            if (severity) {
                return severity.color;
            }
            return null;
        }
    },
    visible: {
        func: function (data) {
            return !!data.getAlarmState().getHighestNewAlarmSeverity();
        },
    },
    rect: [1, 8, 8, 8]
});

欢迎交流 service@hightopo.com