索引
告警用于描述电信网管中网元的异常和错误信息。HT
中网元有告警状态属性(ht.Data#getAlarmState()
,类型为ht.AlarmState
),
用于描述网元的告警信息。告警状态中记录了新发告警和确认告警对应于每一种告警级别(ht.AlarmSeverity
)的告警数量。
告警级别(ht.AlarmSeverity
)用于描述告警的严重程度,具有如下属性:
value
值(number
),用于排序告警级别name
名称(string
),用于唯一标识告警级别nickName
别名,一般是一个字符,用于告警冒泡上显示简短的告警级别名称color
颜色(color
),用于告警冒泡的背景填充色displayName
显示名称(string
),用于详细描述告警级别HT
预定义了如下告警级别:
AlarmSeverity.CRITICAL
,严重告警:{value: 500, name: 'Critical', nickName: 'C', color: '#FF0000'}
AlarmSeverity.MAJOR
,主要告警:{value: 400, name: 'Major', nickName: 'M', color: '#FFA000'}
AlarmSeverity.MINOR
,次要告警:{value: 300, name: 'Minor', nickName: 'm', color: '#FFFF00'}
AlarmSeverity.WARNING
,警告告警:{value: 200, name: 'Warning', nickName: 'W', color: '#00FFFF'}
AlarmSeverity.INDETERMINATE
,未知告警:{value: 100, name: 'Indeterminate', nickName: 'N', color: '#C800FF'}
AlarmSeverity.CLEARED
,已清除告警:{value: 0, name: 'Cleared', nickName: 'R', color: '#00FF00'}
除了HT
提供的默认告警级别,可以用如下方法添加自定义告警级别:
AlarmSeverity.add(value, name, nickName, color, displayName)
value
值(number
),用于排序告警级别name
名称(string
),用于唯一标识告警级别nickName
别名,一般是一个字符,用于告警冒泡上显示简短的告警级别名称color
颜色(color
),用于告警冒泡的背景填充色displayName
显示名称(string
),用于详细描述告警级别ht.AlarmSeverity
示例:
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
ht.List
默认和自定义的告警级别都被添加到了这个集合中,其中元素的顺序是按告警级别的value
从小到大排序的AlarmSeverity.each(callbackFunction, [scope])
callbackFunction
function
回调函数scope
object
回调函数里this指向的对象循环所有告警级别,执行指定函数
AlarmSeverity.getSortFunction()
function
排序函数返回AlarmSeverity.setSortFunction(sortFunction)
设置的告警级别排序函数,如果未设置,则返回默认的告警级别排序函数(按告警级别的value
从小到大排序)
AlarmSeverity.setSortFunction(sortFunction)
sortFunction
function
排序函数设置告警级别排序函数
AlarmSeverity.remove(name)
name
string
名称按名称删除指定的告警级别
AlarmSeverity.isClearedAlarmSeverity(severity)
severity
ht.AlarmSeverity
告警级别boolean
如果指定的告警级别value
是0
则返回true
,否则返回false
AlarmSeverity.getByName(name)
name
string
名称ht.AlarmSeverity
按名字查找告警级别AlarmSeverity.getByValue(value)
value
number
值ht.AlarmSeverity
按值查找告警级别AlarmSeverity.clear()
清空所有告警级别
AlarmSeverity.compare(severity1, severity2)
severity1
ht.AlarmSeverity
告警级别1
severity1
ht.AlarmSeverity
告警级别2
number
如果severity1
大于severity2
则返回1
,如果severity1
小于severity2
则返回-1
,如果severity1
等于severity2
则返回0
比较指定的两个告警级别
告警状态(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])
severity
ht.AlarmSeverity
告警级别increment
number
数量,可选,默认值为1
增加指定数量和级别的新发告警
AlarmState#decreaseNewAlarm(severity, [decrement])
severity
ht.AlarmSeverity
告警级别decrement
number
数量,可选,默认值为1
减少指定数量和级别的新发告警
AlarmState#setNewAlarmCount(severity, count)
severity
ht.AlarmSeverity
告警级别count
number
数量设置指定级别的新发告警数量
AlarmState#removeAllNewAlarms(severity)
severity
ht.AlarmSeverity
告警级别清除所有新发告警
AlarmState#acknowledgeAlarm(severity)
severity
ht.AlarmSeverity
告警级别确认一条指定级别的新发告警
AlarmState#acknowledgeAllAlarms([severity])
severity
ht.AlarmSeverity
告警级别,可选确认指定级别的所有新发告警,如果severity
参数省略,则确认所有级别的新发告警
AlarmState#increaseAcknowledgedAlarm(severity, [increment])
severity
ht.AlarmSeverity
告警级别increment
number
数量,可选,默认值为1
增加指定数量和级别的确认告警
AlarmState#decreaseAcknowledgedAlarm(severity, [decrement])
severity
ht.AlarmSeverity
告警级别decrement
number
数量,可选,默认值为1
减少指定数量和级别的确认告警
AlarmState#setAcknowledgedAlarmCount(severity, count)
severity
ht.AlarmSeverity
告警级别count
number
数量设置指定级别的确认告警数量
AlarmState#removeAllAcknowledgedAlarms(severity)
severity
ht.AlarmSeverity
告警级别清除所有确认告警
AlarmState#clear()
清除所有新发和确认告警
AlarmState#setPropagateSeverity(severity)
severity
ht.AlarmSeverity
告警级别设置传播告警级别
AlarmState#setEnablePropagation(value)
value
boolean
否启用告警传播设置是否启用告警传播,默认值为true
AlarmState#getHighestAcknowledgedAlarmSeverity()
ht.AlarmSeverity
返回最高的确认告警级别AlarmState#getHighestNewAlarmSeverity()
ht.AlarmSeverity
返回最高的新发告警级别AlarmState#getHighestNativeAlarmSeverity()
ht.AlarmSeverity
返回最高的确认或新发告警级别AlarmState#getPropagateSeverity()
ht.AlarmSeverity
返回传播告警级别AlarmState#getHighestOverallAlarmSeverity()
ht.AlarmSeverity
返回最高的确认、新发或传播告警级别AlarmState#hasLessSevereNewAlarms()
boolean
返回是否有低于最高新发告警级别的新发告警AlarmState#getNewAlarmCount(severity)
severity
ht.AlarmSeverity
告警级别number
返回指定告警级别的新发告警数量AlarmState#getAcknowledgedAlarmCount(severity)
severity
ht.AlarmSeverity
告警级别number
返回指定告警级别的确认告警数量AlarmState#getAlarmCount(severity)
severity
ht.AlarmSeverity
告警级别number
返回指定告警级别的确认和新发告警数量总和AlarmState#isEmpty()
boolean
返回是否没有新发、确认或传播告警AlarmState#isEnablePropagation()
boolean
返回是否启用告警传播,默认值为true
在HT
中,告警传播ht.AlarmStatePropagator
会将底层网元的告警往上层网元传播,比如Group
或SubGraph
中所有孩子的最高级别告警会传播到Group
或SubGraph
。
默认告警传播未开启,需要调用ht.DataModel#setEnableAlarmStatePropagator(true)
开启告警传播。
默认告警传播是从孩子传播到父亲,可以重写ht.AlarmStatePropagator
的propagateToTop
方法改变传播机制,下面例子演示了告警沿着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)
dataModel
ht.DataModel
数据容器构造函数,构建告警传播
AlarmStatePropagator#getDataModel()
ht.DataModel
返回关联的数据容器AlarmStatePropagator#isEnable()
boolean
返回是否启用告警传播,默认为false
AlarmStatePropagator#setEnable(enable)
enable
boolean
是否启用告警传播设置是否启用告警传播
AlarmStatePropagator#handleDataModelChange(e)
e
object
模型更改事件,包含如下属性:kind
string
取值为add
, remove
, clear
data
ht.Data
当kind
为add
或remove
时,data
属性为添加或删除的数据,当kind
为clear
时,data
属性为null
数据容器更改回调函数,处理告警传播
AlarmStatePropagator#handleDataPropertyChange(e)
e
object
数据更改事件,包含如下属性:property
string
发生变化的属性oldValue
object
旧值newValue
object
新值data
ht.Data
发生属性变化的数据数据属性更改回调函数,处理告警传播
AlarmStatePropagator#propagate(data)
data
ht.Data
数据传播告警
AlarmStatePropagator#propagateToTop(data)
data
ht.Data
数据传播告警到上层
AlarmStatePropagator#propagateToParent(data)
data
ht.Data
数据传播告警到父亲
告警统计(ht.AlarmStateStatistics
)用于统计数据容器中所有数据的各告警级别的新发、确认以及总数量。
AlarmStateStatistics(dataModel)
dataModel
ht.DataModel
数据容器构造函数,创建告警统计对象
AlarmStateStatistics#getDataModel()
ht.DataModel
返回关联的数据容器AlarmStateStatistics#setDataModel(dataModel)
dataModel
ht.DataModel
设置关联的数据容器AlarmStatePropagator#dispose()
销毁告警统计,删除对数据容器和数据的监听
AlarmStateStatistics#handleDataModelChange(e)
e
object
模型更改事件,包含如下属性:kind
string
取值为add
, remove
, `cleardata
ht.Data
当kind
为add
或remove
时,data
属性为添加或删除的数据,当kind
为clear
时,data
属性为null
数据容器更改回调函数,重新统计告警数量
AlarmStateStatistics#handleDataPropertyChange(e)
e
object
数据更改事件,包含如下属性:property
string
发生变化的属性oldValue
object
旧值newValue
object
新值data
ht.Data
发生属性变化的数据数据属性更改回调函数,重新统计告警数量
AlarmStateStatistics#fireAlarmStateChange()
重新统计告警数量,派发alarmState
更改事件
AlarmStateStatistics#getNewAlarmCount([severity])
severity
ht.AlarmSeverity
告警级别,可选number
返回指定告警级别的统计新发告警数量,如果不提供severity
参数,则返回所有级别的新发告警数AlarmStateStatistics#getAcknowledgedAlarmCount([severity])
severity
ht.AlarmSeverity
告警级别,可选number
返回指定告警级别的统计确认告警数量,如果不提供severity
参数,则返回所有级别的确认告警数AlarmStateStatistics#getTotalAlarmCount([severity])
severity
ht.AlarmSeverity
告警级别,可选number
返回指定告警级别的统计新发和确认告警数量,如果不提供severity
参数,则返回所有级别的新发和确认告警数AlarmStateStatistics#getSumInfo(severity)
severity
ht.AlarmSeverity
告警级别object
返回指定告警级别的统计新发、确认以及新发和确认告警数量newCount
number
新发告警数量ackedCount
number
确认告警数量totalCount
number
新发和确认告警数量AlarmStateStatistics#increase(data)
data
ht.Data
数据增加指定数据的告警
AlarmStateStatistics#decrease(data)
data
ht.Data
数据减少指定数据的告警
AlarmStateStatistics#reset()
重新统计告警数量
AlarmStateStatistics#getFilterFunc()
function
返回过滤函数data
ht.Data
数据boolean
返回true
则不统计此数据的告警信息,否则参与统计AlarmStateStatistics#setFilterFunc(value)
value
function
过滤函数data
ht.Data
数据boolean
返回true
则不统计此数据的告警信息,否则参与统计设置过滤函数,过滤不参与统计的数据
下面的例子演示了用矢量实现告警统计面板:
默认树上节点的图标填充色是数据的最高新发或确认告警级别的颜色,如果有传播告警,树节点图标会加上颜色为传播告警级别颜色的边框:
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]
});