接口路径:ip:port/wapi/v1/authenticate
public String getNvisualToken(String username, String password){
//获取token
String token = "";
Map<String, String> map = new HashMap<String, String>();
map.put("username",username);
map.put("password",password);
String jsonString = JSON.toJSONString(map);
try {
String responseToken = HttpUtil.postJSON(nvisualApiConfig.getNvisualUrl()+"/wapi/v1/authenticate",jsonString);
Map responseTokenMap = JSONObject.parseObject(responseToken,Map.class);
if("200".equals(responseTokenMap.get("code").toString())){
Map<String, Object> data = (Map<String, Object>)responseTokenMap.get("data");
token = (String) data.get("access_token");
}
} catch (Exception e) {
token = "";
}
return token;
}
public static String postJSON(String url,String paramjson){
HttpPost post = new HttpPost(url);
HttpClient httpClient = HttpClientBuilder.create().build();
try {
StringEntity stringEntity = new StringEntity(paramjson, ContentType.APPLICATION_JSON);
post.setEntity(stringEntity);
HttpResponse response = httpClient.execute(post);
if(response.getStatusLine().getStatusCode()==200){
//获取响应的内容对象
HttpEntity httpEntity = response.getEntity();
//转换结果位字符串
return EntityUtils.toString(httpEntity);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static String postJSON(String url,String paramjson,String token){
HttpPost post = new HttpPost(url);
HttpClient httpClient = HttpClientBuilder.create().build();
try {
StringEntity stringEntity = new StringEntity(paramjson, ContentType.APPLICATION_JSON);
post.setEntity(stringEntity);
post.addHeader("Authorization", token);
// 传输的类型
post.addHeader("Content-Type", "application/json");
HttpResponse response = httpClient.execute(post);
if(response.getStatusLine().getStatusCode()==200){
//获取响应的内容对象
HttpEntity httpEntity = response.getEntity();
//转换结果位字符串
return EntityUtils.toString(httpEntity);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
接口路径:ip:port/wapi/v1/node_properties/get_node_id_by_name_and_value
//入参body
Map<String, Object> npvNameAndValueMap = new HashMap<>();
npvNameAndValueMap.put("name","告警源");//字段名
npvNameAndValueMap.put("value",resource);//字段值
List<Long> nvisualObjectIdByNameAndValue = getNvisualObjectIdByNameAndValue(npvNameAndValueMap, token);
public List<Long> getNvisualObjectIdByNameAndValue(Map<String, Object> map,String token){
String jsonString = JSON.toJSONString(map);
String json = HttpUtil.postJSON(nvisualApiConfig.getNvisualUrl() + "/wapi/v1/node_properties/get_node_id_by_name_and_value", jsonString, "Bearer "+token);
List<Long> list = JSONArray.parseArray(json, Long.class);
return list;
}
api文档
接口描述:通过传入字段名称和字段值,获取nVisual告警对象id。
URL地址:http://ip:port /wapi/v1/node_properties/get_node_id_by_name_and_value
访问方法::Post
请求参数:
Body参数
参数名 | 示例值 | 必填 | 说明 |
---|---|---|---|
name | 告警源 | 是 | 字段名称 |
value | 127.0.0.1-1-1 | 是 | 字段值 |
响应示例:
//返回值可能为多个
[24000000001243]
接口路径:ip:port/wapi/v1/notice
api文档
接口描述:通过传入消息标题、内容、用户id、消息状态、消息优先级、消息备注,增加消息告警。
URL地址:http://ip:port /wapi/v1/notice
访问方法::Post
请求参数:
Body参数
参数名 | 类型 | 示例值 | 必填 | 说明 |
---|---|---|---|---|
title | String | 端口告警 | 是 | 通知标题 |
content | String | 端口光功率告警 | 是 | 通知内容,optCableEvent不为空时content可为空,系统自动生成消息内容。 |
userId | Long | 94000000000058 | 否 | 处理人用户id与用户名选其一 |
username | String | fe | 否 | 处理人用户名与用户id选其一 |
messageStatus | Boolean | false | 否 | 消息是否恢复,发生告警消息时为false,未恢复,告警消失时为true,告警恢复。不填时默认为false,发生告警消息。 |
priority | String | 严重 | 是 | 消息优先级有:灾难、严重、一般严重、告警、信息、未分类等六个等级。如果填入的值不在六个等级之中,查询归类时归类为“未分类”。 |
notes | String | 告警测试 | 否 | 消息备注 |
objectId | Long | 23416004312147 | optCableEvent参数二选一 | 若已知nVisual告警对象ID时,直接传入id,如果不知id时,通过传入optCableEvent参数即可,nVisual自行查询 |
optCableEvent | Object | { "port":"1.1.1.3-1-1", "eventType":"OTHER", "eventSign":50} | objectId参数二选一 | port:ip-插槽名称-端口名称eventType:事件类型,可为空eventSign:告警距离,为空时认定为端口告警,不为空时线缆告警。 |
响应示例:
{
"code": 200,
"data": {
"id": 53000000000391,
"title": "123",
"content": "456",
"userId": 94000000000058,
"messageStatus": true,
"createTime": "2023-02-09T08:50:36.440+0000",
"lastOprTime": "2023-02-09T08:50:36.440+0000",
"jumpUrl": null,
"noticePop": false,
"priority": “高”,
"notes": “工单测试”
},
"message": "success"
}
接口路径:ip:port/wapi/v1/notice/id/{noticeId}
api文档
接口描述:传入消息id,修改消息状态。
URL地址:http://ip:port /wapi/v1/notice/id/{noticeId}
访问方法::Put
请求参数:
Path参数
参数名 | 类型 | 示例值 | 必填 | 说明 |
---|---|---|---|---|
noticeId | Long | 53000000000391 | 是 | 消息id |
Body参数
参数名 | 类型 | 示例值 | 必填 | 说明 |
---|---|---|---|---|
messageStatus | Boolean | true | 否 | 消息状态 |
响应示例:
{
"code": 200,
"data": null,
"message": "success"
}
接口路径:ip:port/wapi/v1/notice/delete
api文档
接口描述:传入消息id,批量删除消息。
URL地址:http://ip:port /wapi/v1/notice/delete
访问方法::Post
请求参数:
Body参数
参数名 | 类型 | 示例值 | 必填 | 说明 |
---|---|---|---|---|
ids | Long[] | [5300000000001] | 是 | 消息id |
响应示例:
{
"code": 200
}