系统下电消息通知
订阅消息接口
接口功能
根据第三方系统 ID、第三方系统消息接收接口凭证 openID、第三方系统消息接收接口 URL 和订阅操作描述,订阅系统下电消息通知。
URI路径
/rest/openapi/notification/common/systemStatus
访问方法
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字符,字符集合不限制。 |
返回结果
字段名 |
类型 |
说明 |
---|---|---|
code |
int |
操作返回码。可以是如下值之一:
|
data |
String |
此处为 null。 |
description |
String |
接口调用结果的描述信息。 |
注意事项
订阅成功后,在 eSight 正常下电情况下,eSight 尽可能努力发送下电消息。eSight 断电等异常下电情况则不保证发送该消息。
调用示例
数据段 |
值 |
---|---|
请求 URL |
PUT https://eSightIP: port/rest/openapi/notification/common/systemStatus HTTP/1.1 |
请求头 |
openid: 775c47f9-9a1b-43f9-a24b-2c3db1a55622; |
请求实体 |
systemID=example%40system&openID=1b7a6992-5d5f-4091-a49f-ec2e09640a05&url=https%3A%2F%2FdemoIP%3AdemoPort%2Fnotification&dataType=JSON&desc=eSight+DesignIn+Demo |
响应实体 |
{"code":0,"data":null,"description":"Operation success."} |
使用示例
package com.huawei.nms.openapi.demo.notification; 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 PutSystemStatusTest { 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/systemStatus"; 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","NMSinfo1")); bodys.add(new BasicNameValuePair("openID","127.0.0.1")); bodys.add(new BasicNameValuePair("url","http://127.0.0.2:8080/device")); bodys.add(new BasicNameValuePair("dataType","JSON")); bodys.add(new BasicNameValuePair("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); } }
执行结果如下:
{ "code": 0, "data": null, "description": "Operation success." }
退订消息接口
接口功能
根据第三方系统 ID退订操作描述,退订系统下电消息通知。
URI路径
/rest/openapi/notification/common/systemStatus
访问方法
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/systemStatus?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.notification; 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 DeleteSystemStatusTest { 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/systemStatus"; 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","NMSinfo1")); parameters.add(new BasicNameValuePair("desc","")); //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." }
发送消息通知
消息数据
eSight具有关闭功能时的超时保护机制,全组件安装时,可能因该保护机制而无法及时发送系统下电消息。第三方系统可以通过系统保活消息和上电消息来判断 eSight 的在线状态。
字段名 |
类型 |
说明 |
---|---|---|
resourceURI |
String |
资源类型 URI,设备变更消息通知为 /rest/openapi/notification/common/systemStatus。 |
msgType |
Int |
消息类型。固定为 97:系统下电。 |
data |
List |
以 JSON 数组形式描述的数据对象。 说明:
如果消息接收地址为 HTTP 协议,则 data 的值为加密字符串,需要第三方系统根据配置文件中的 KEY 和 IV 值解密,之后再解析数据对象。解密方法见“解密示例”。 |
extendedData |
String |
以 JSON 形式描述的附加数据对象,此处为空对象 “{}”。 |
description |
String |
消息通知描述。 |
timestamp |
String |
消息发出的时间戳,eSight 服务器协调时间格式。 |
data 数据结构:
字段名 |
类型 |
说明 |
---|---|---|
systemID |
String |
eSight 系统唯一标识。 说明:
eSight 系统唯一标识可以在配置文件中配置,也可以在前台本地系统信息页面上配置,见前期准备章节。 |
systemName |
String |
eSight 系统名称。 说明:
eSight 系统名称可以在配置文件中配置,也可以在前台本地系统信息页面上配置,见前期准备章节。 |
version |
String |
eSight 版本号。 说明:
eSight 版本可以在配置文件中配置,见前期准备章节 |
vendor |
String |
eSight 供应商,固定为 Huawei。 |
systemEscapedTime |
String |
系统历时。格式为:d Day hh Hour mm Min ss Sec xxx MilliSec。 |
解密示例
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 11:11:27", "extendedData":{}, "resourceURI":"/rest/openapi/notification/common/systemStatus", "description":"System shutdown.", "data": [ { "systemEscapedTime":"0 Day 00 Hour 02 Min 35 Sec 675 MilliSec ", "vendor":"Huawei", "systemName":"HuaweiPlatform", "systemID":"HuaweiPlatform", "version":"V300R003C00" } ], "msgType":97 }