告警变更消息通知
订阅消息接口
接口功能
根据第三方系统 ID、第三方系统消息接收接口凭证 openID、第三方系统消息接收接口 URL 和订阅操作描述,订阅告警变更消息通知。告警变更消息包括新增告警、新增事件、告警确认/反确认、告警级别变更、告警清除。
URI路径
/rest/openapi/notification/common/alarm
访问方法
PUT
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
请求头参数列表 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
systemID |
必选 |
请求实体参数列表 |
String |
第三方系统标识。 说明:
可为IP地址,1~64个字符,字符集合为英文半角:0-9a-zA-Z@_-(),.^$~`! |
openID |
必选 |
请求实体参数列表 |
String |
网管主动连接第三方系统的认证凭证,由第三方系统分配和利用此字符串认证。 说明:
1~1024个字符,字符集同 systemID。 |
url |
必选 |
请求实体参数列表 |
String |
网管以 POST 方式向该 URL发送通知消息。 说明:
例如 http://10.10.10.1:8080/device。需要通知消息订阅者确保URL的正确性,IP地址为OpenAPI白名单列表中地址。长度1~1024,字符串符合HTTP URL编码规范。 |
dataType |
可选 |
请求实体参数列表 |
String |
通知报文的 data 字段类型。 说明:
目前仅支持“JSON”,缺省为“JSON”。 |
desc |
可选 |
请求实体参数列表 |
String |
三方系统描述。 说明:
缺省为null 不设置。如设置长度限制0~1024字符,字符集合不限制。 |
filterInfos |
可选 |
请求实体参数列表 |
String |
三方系统订阅时传递的需要上报告警的过滤条件。 说明:
|
FilterInfo需要上报告警的过滤条件包含以下字段,条件与条件之间是与的关系:
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
alarmType |
可选 |
请求实体参数列表 |
String |
上报的告警类型。 说明:
1-事件,2-告警(包括所有告警),当选择多个告警类型时则以逗号分隔。例:“1,2”表示上报告警类型为事件和告警。为null时事件和告警都上报。 |
alarmLevel |
可选 |
请求实体参数列表 |
String |
上报的告警级别。 说明:
对应告警的perceivedSeverity,1-紧急,2-重要,3-次要,4-提示,当选择多个级别时则以逗号分隔。例:“1,2”表示上报告警级别为紧急和重要。为null时所有告警级别的告警都上报。 |
alarmSource |
可选 |
请求实体参数列表 |
AlarmSourceInfo |
告警源相关信息对象。 说明:
缺省为null不设置。为null时所有告警源的告警都上报。 |
AlarmSourceInfo告警源相关信息对象包含以下字段,条件与条件之间是与的关系:
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
AlarmSourceTypes |
可选 |
请求实体参数列表 |
List<String> |
上报的告警源类型。 说明:
对应告警的neType,例: ["{RedHat}RedHatLinux","OMS","NE10TE"],表示上报以上三种网元类型。 |
alarmSourceInstance |
可选 |
请求实体参数列表 |
List<AlarmSourceInstance> |
上报的告警源和定位信息对象。 说明:
缺省为null不设置。 |
modns |
可选 |
请求实体参数列表 |
List<String> |
上报的告警管理对象标识。 |
AlarmSourceInstance告警源加定位信息对象:
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
alarmSourceDn |
可选 |
请求实体参数列表 |
String |
告警源DN。 说明:
对应告警的neDN,例: NE=34606011。 |
positions |
可选 |
请求实体参数列表 |
List<String> |
上报的告警源定位信息。 说明:
对应告警的objectInstance,告警源定位信息支持通配的方式(默认前后通配)。例: ["id-host:HOSTID", "(id-vm:*(az:az1.dc1)"] |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
String |
此处为 null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
无。
调用示例
数据段 |
值 |
---|---|
请求 URL |
PUT https://eSightIP: port/rest/openapi/notification/common/alarm HTTP/1.1 |
请求头 |
openid: 775c47f9-9a1b-43f9-a24b-2c3db1a55622; |
请求实体 |
systemID=example%40system&openID=1b7a6992-5d5f-4091-a49f-ec2e09640a05&url=http%3A%2F%2FdemoIP%3AdemoPort%2Fnotification&dataType=JSON&desc=eSight+DesignIn+Demo |
响应实体 |
{"code":0,"data":null,"description":"Operation success."} |
使用示例
package com.huawei.nms.openapi.demo.integrated; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.sm.Login; public class SubscribeTrandtion { public static void main(String[] args) throws Exception { Login.login(); put(); } public static void put() throws Exception { //set the URL and method final String openidURL = "/rest/openapi/notification/common/alarm"; final String method = "PUT"; List<BasicNameValuePair> headers = new ArrayList<BasicNameValuePair>(); headers.add(new BasicNameValuePair("openid", GlobalVar.globalOpenid)); //set parameters final List<BasicNameValuePair> bodys = new ArrayList<BasicNameValuePair>(); bodys.add(new BasicNameValuePair("systemID", "tradition")); bodys.add(new BasicNameValuePair("openID", "aa")); bodys.add(new BasicNameValuePair("url", "http://1.2.3.4:8080/alarm")); bodys.add(new BasicNameValuePair("dataType", "JSON")); bodys.add(new BasicNameValuePair("desc", "desc")); //send the request final HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, bodys); //get the result final String ret = NewHttpsAccess.getResult(response); System.out.println(ret); } public static void delete() throws Exception { //set the URL and method final String openidURL = "/rest/openapi/notification/common/alarm"; final String method = "DELETE"; List<BasicNameValuePair> headers = new ArrayList<BasicNameValuePair>(); headers.add(new BasicNameValuePair("openid", GlobalVar.globalOpenid)); //set parameters final List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>(); parameters.add(new BasicNameValuePair("systemID", "tradition")); //send the request final HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, parameters); //get the result final String ret = NewHttpsAccess.getResult(response); System.out.println(ret); }
执行结果如下:
{ "code": 0, "data": null, "description": "Operation success." }
退订消息接口
接口功能
根据第三方系统 ID退订操作描述,退订告警变更消息通知。
URI路径
/rest/openapi/notification/common/alarm
访问方法
DELETE
参数说明
参数名 |
必选/可选 |
参数位置 |
参数类型 |
参数说明 |
---|---|---|---|---|
openid |
必选 |
消息头参数列表 |
String |
会话标识,用于Open API的鉴权。 说明:
该参数由第三方调用安全管理的登录接口获取openid。 |
systemID |
必选 |
URL 参数列表 |
String |
第三方系统标识。 说明:
可为IP地址,1~64个字符,字符集合为英文半角:0-9a-zA-Z@_-(),.^$~`! |
desc |
可选 |
URL 参数列表 |
String |
三方系统描述。 说明:
缺省为null 不设置。如设置长度限制0~1024字符,字符集合不限制。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
String |
此处为 null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
MIME type 为 application/x-www-form-urlencoded 的请求中,空格将会编码为加号,加号则编码为%2B。
调用示例
数据段 |
值 |
---|---|
请求 URL |
DELETE https://eSightIP:port/rest/openapi/notification/common/alarm?systemID=example%40system&desc=eSight+DesignIn+Demo+Unsubscription. HTTP/1.1 |
请求头 |
openid: 775c47f9-9a1b-43f9-a24b-2c3db1a55622; |
请求实体 |
N/A |
响应实体 |
{"code":0,"data":null,"description":"Operation success."} |
使用示例
package com.huawei.nms.openapi.demo.integrated; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.message.BasicNameValuePair; import com.huawei.nms.openapi.demo.global.GlobalVar; import com.huawei.nms.openapi.demo.global.NewHttpsAccess; import com.huawei.nms.openapi.demo.sm.Login; public class SubscribeTrandtion { public static void main(String[] args) throws Exception { Login.login(); delete(); } public static void delete() throws Exception { //set the URL and method final String openidURL = "/rest/openapi/notification/common/alarm"; final String method = "DELETE"; List<BasicNameValuePair> headers = new ArrayList<BasicNameValuePair>(); headers.add(new BasicNameValuePair("openid", GlobalVar.globalOpenid)); //set parameters final List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>(); parameters.add(new BasicNameValuePair("systemID", "tradition")); //send the request final HttpResponse response = NewHttpsAccess.access(GlobalVar.GLOBAL_IP, GlobalVar.GLOBAL_PORT, openidURL, method, headers, parameters); //get the result final String ret = NewHttpsAccess.getResult(response); System.out.println(ret); } }
执行结果如下:
{ "code": 0, "data": null, "description": "Operation success." }
发送消息通知
消息数据
字段名 |
类型 |
说明 |
---|---|---|
resourceURI |
String |
资源类型 URI,告警变更消息通知为 /rest/openapi/notification/common/alarm。 |
msgType |
Int |
消息类型。可能的取值为:
|
data |
List |
以 JSON 数组形式描述的数据对象。 说明:
如果消息接收地址为 HTTP 协议,则 data 的值为加密字符串,需要第三方系统根据配置文件中的 KEY 和 IV 值解密,之后再解析数据对象。解密方法见“解密示例”。 |
extendedData |
String |
以 JSON 形式描述的附加数据对象,此处为空对象 “{}”。 |
description |
String |
消息通知描述。 |
timestamp |
String |
消息发出的时间戳,eSight 服务器协调时间格式。 |
data 包含以下字段:
字段名 |
类型 |
说明 |
---|---|---|
optType |
Int |
告警事件操作类型。可以是如下值之一:
|
systemID |
String |
eSight 自己的系统 ID,通过配置文件可以修改。见前期准备章节。 |
ackTime |
Long |
确认时间。 |
ackUser |
String |
确认用户。 |
acked |
Boolean |
是否已确认。 |
additionalInformation |
String |
附加信息。 |
additionalText |
String |
附加文本。 |
alarmId |
Int |
告警标识。 |
alarmName |
String |
告警名称。 |
alarmSN |
Int |
告警流水号。 说明:
告警清除和告警产生的告警流水号必须相同。上层系统清除告警时,需根据告警流水号进行唯一匹配并清除告警。 |
arrivedTime |
Long |
告警到达网管时间,为UTC时间。 |
clearUser |
String |
告警清除用户。 |
cleared |
Boolean |
是否已清除。 |
clearedTime |
Long |
告警清除时间,为UTC时间,可能为null。 |
clearedType |
Int |
清除类别。可以是如下值之一:
|
commentTime |
Long |
备注时间。 |
commentUser |
String |
备注用户。 |
comments |
String |
备注。 |
devCsn |
Long |
设备流水号。 |
eventTime |
Long |
告警产生时间的UTC毫秒数。 说明:
该字段为第一条告警产生时间,不会随新的同类告警而更新,在清除/确认时不会更新该字段。 |
eventType |
Int |
告警事件类型。可以是如下值之一:
|
moDN |
String |
管理对象。 |
moName |
String |
管理对象名称。 |
neDN |
String |
告警源标识。 |
neName |
String |
网元名称。 |
neType |
String |
设备类型。 |
objectInstance |
String |
定位信息。 |
perceivedSeverity |
Int |
告警级别。可以是如下值之一:
|
probableCause |
Int |
告警可能原因,可能为null。 |
proposedRepairActions |
String |
修复建议。 |
alarmEvent |
String |
告警事件标识。可以是如下值之一:
|
moType |
String |
管理对象类型,对应原始告警的objectClass字段 |
字段细则
不同的告警通知中,data 字段填充内容不同。以下数据中打钩的为该类告警事件具备的数据,没打钩的字段使用默认值且无须读取。通过上文中 optType 决定是哪种告警事件:
字段名 |
新增标准告警 |
新增安全告警 |
新增事件 |
告警确认 |
告警级别变更 |
告警清除 |
告警清除 (无原告警) |
---|---|---|---|---|---|---|---|
ackTime |
X |
X |
X |
√ |
X |
X |
X |
ackUser |
X |
X |
X |
√ |
X |
X |
X |
acked |
X |
X |
X |
√ |
X |
√ |
√ |
additionalInformation |
√ |
√ |
√ |
X |
X |
√ |
√ |
additionalText |
√ |
√ |
√ |
X |
X |
X |
X |
alarmId |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
alarmName |
√ |
√ |
√ |
X |
X |
√ |
√ |
alarmSN |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
arrivedTime |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
clearUser |
X |
X |
X |
X |
X |
√ |
√ |
cleared |
X |
X |
X |
X |
X |
√ |
√ |
clearedTime |
X |
X |
X |
X |
X |
√ |
√ |
clearedType |
√ |
√ |
X |
X |
X |
√ |
√ |
commentTime |
X |
X |
X |
X |
X |
X |
X |
commentUser |
X |
X |
X |
X |
X |
X |
X |
comments |
X |
X |
X |
X |
X |
√ |
√ |
devCsn |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
eventTime |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
eventType |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
moDN |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
moName |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
neDN |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
neName |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
neType |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
objectInstance |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
perceivedSeverity |
√ |
√ |
X |
√ |
√ |
√ |
X |
probableCause |
√ |
√ |
X |
√ |
√ |
√ |
X |
proposedRepairActions |
√ |
X |
X |
X |
X |
X |
X |
alarmEvent |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
解密示例
private static String decrypt(String data){ String result = ""; // 注:以下两个密钥串参考etc/oms.ros/ros.web.notification.xml自行添加,需要明文。 String decryptedKey = "E5DF96DE53ED56CBAE25368624DC25Ef"; String decryptedIv = "E2CDBCA5693654EF2E6F38693653564E"; // 获取结果,KEY和IV值 final byte[] key = strToBytes( decryptedKey.toUpperCase() ); final byte[] iv = strToBytes( decryptedIv.toUpperCase() ); try { // 获取key生成器 KeyGenerator kgen = KeyGenerator.getInstance("AES", "SunJCE"); SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG", "SUN"); secureRandom.setSeed( key ); // 初始化 kgen.init( 128, secureRandom ); // 算法参数 AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv); // 生成加密key SecretKey secretKey = kgen.generateKey(); // 加密器 Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE"); // 初始化加密器 cipher.init( Cipher.DECRYPT_MODE, secretKey, paramSpec); // 获取解密结果 byte[] res = cipher.doFinal(strToBytes(data)); try { result = new String( res,"UTF-8" ); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch( final GeneralSecurityException e ) { e.printStackTrace(); result = null; } return result; }
public static byte[] strToBytes(final String str) { // 参数校验 if (null == str || str.isEmpty() || !str.matches("[0-9a-zA-Z]{1,}")) { return null; } // 转换成大写 final String upperCaseString = str.toUpperCase(Locale.US); // 字符串长度 final int strLen = upperCaseString.length(); // 被加密数组 final byte[] bytes = new byte[16]; // 循环计算加密值 for (int i = 0; i < (strLen / 2); i++) { // 高低位 int high = charToHex(upperCaseString.charAt(i * 2)); int low = charToHex(upperCaseString.charAt(i * 2 + 1)); // 获得结果 bytes[i] = (byte) ((high << 4) | low); } return bytes; }
/** * char 转换成16进制,输入保证只有[0-9A-Z] * * @param ch字符 * @return 返回代表的数值 */ private static int charToHex(final char ch) { if (Character.isUpperCase(ch)) { // 大写字符 return ch - 'A' + 10; } else { // 数字 return ch - '0'; } }
通知示例
新增告警:
{ "timestamp":"2014-12-19 17:31:24", "extendedData":{}, "resourceURI":"/rest/openapi/notification/common/alarm", "description":"Alarm related notification.", "data": [ { "proposedRepairActions":"null", "additionalText":"null", "eventType":-1, "neDN":"NE=34603111", "moName":"E200E-F-64", "perceivedSeverity":2, "moDN":"NE=34603111", "clearUser":"", "commentUser":"", "neName":"E200E-F-64", "alarmName":"BGP状态下降", "alarmId":1100840, "ackUser":"", "optType":1, "cleared":false, "commentTime":0, "alarmSN":146, "probableCause":51569, "neType":"{Huawei}Eudemon200E-X5", "objectInstance":"null", "systemID":"HuaweiPlatform", "additionalInformation":"null", "acked":false, "eventTime":1418981484000, "clearedType":0, "arrivedTime":1418981484465, "clearedTime":0, "ackTime":0, "comments":"", "devCsn":0, "alarmEvent":"Alarms" } ], "msgType":1 }
确认告警:
{ "timestamp":"2014-12-19 17:33:14", "extendedData":{}, "resourceURI":"/rest/openapi/notification/common/alarm", "description":"Alarm related notification.", "data": [ { "proposedRepairActions":"", "additionalText":"", "eventType":-1, "neDN":"NE=34603111", "moName":"E200E-F-64", "perceivedSeverity":2, "moDN":"NE=34603111", "clearUser":"", "commentUser":"", "neName":"E200E-F-64", "alarmName":"", "alarmId":1100840, "ackUser":"admin", "optType":3, "cleared":false, "commentTime":0, "alarmSN":146, "probableCause":51569, "neType":"{Huawei}Eudemon200E-X5", "objectInstance":"null", "systemID":"HuaweiPlatform", "additionalInformation":"", "acked":true, "eventTime":1418981593000, "clearedType":0, "arrivedTime":1418981484465, "clearedTime":0, "ackTime":1418981593000, "comments":"", "devCsn":0, "alarmEvent":"Alarms" } ], "msgType":3 }
清除告警:
{ "timestamp":"2014-12-19 16:25:11", "extendedData":{}, "resourceURI":"/rest/openapi/notification/common/alarm", "description":"Alarm related notification.", "data": [ { "proposedRepairActions":"", "additionalText":"", "eventType":-1, "neDN":"NE=34603109", "moName":"E200E-F-64", "perceivedSeverity":5, "moDN":"NE=34603109", "clearUser":"System User", "commentUser":"", "neName":"E200E-F-64", "alarmName":"光纤连接错误告警", "alarmId":2100095, "ackUser":"", "optType":2, "cleared":true, "commentTime":0, "alarmSN":122, "probableCause":50225, "neType":"{Huawei}Eudemon200E-X5", "objectInstance":"", "systemID":"HuaweiPlatform", "additionalInformation":"null", "acked":true, "eventTime":1418977509000, "clearedType":1, "arrivedTime":1418977313529, "clearedTime":1418977509000, "ackTime":0, "comments":"", "devCsn":0, "alarmEvent":"Alarms" } ], "msgType":2 }