Browse Source

告警信息查询

dev
wenlele 1 year ago
parent
commit
6bf2894305
  1. 75
      api/app/lib/controllers/analysis/network.js
  2. 12
      api/app/lib/routes/analysis/network.js
  3. 19
      web-network/client/src/sections/network/actions/network.js
  4. 151
      web-network/client/src/sections/network/components/device-tree/equipment-option.js
  5. 3
      web-network/client/src/sections/network/components/device-tree/index.js
  6. 78
      web-network/client/src/sections/network/containers/device-monitor.js

75
api/app/lib/controllers/analysis/network.js

@ -349,6 +349,80 @@ async function getDevicesLlinkStatus (ctx, next) {
}
};
async function findAlarmsDevice(ctx, next) {
let error = { name: 'FindError', message: '告警信息获取失败' };
let rslt = null;
const { deviceId } = ctx.params;
if (deviceId) {
try {
const { limit } = ctx.query;
const client = ctx.app.fs.esclient[ALARM];//准备查询
let params = {
index: client.config.index,
type: client.config.type,
size: limit || 5,
body: {
"query": {
"bool": {
"must": [
{
"match": {
"source_id": deviceId
}
},
{
"terms": {
"state": []
}
}
]
}
},
"sort": [
{
"start_time": {
"order": "desc"
}
}
]
}
}
let newState = [AlarmState.Creation, AlarmState.CountUpgrade, AlarmState.LevelUpgrade];
let historyState = [AlarmState.AutoElimination, AlarmState.ManElimination];
params.body.query.bool.must[1].terms.state = newState;
let newAlarms = await client.search(params);//查询
params.body.query.bool.must[1].terms.state = historyState;
params.size = 9999;
let historyAlarm = await client.search(params);
const timer = ctx.app.fs.timer;
function filterAlarmMsg(oriMsg) {
let msg = [];
for (let s of oriMsg) {
msg.push({
alarmContent: s._source.alarm_content,
alarmCount: s._source.alarm_count,
startTime: timer.toCSTString(s._source.start_time),
endTime: timer.toCSTString(s._source.end_time),
})
}
return msg;
}
rslt = { new: filterAlarmMsg(newAlarms.hits.hits), history: filterAlarmMsg(historyAlarm.hits.hits) }
error = null;
} catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
}
}
if (error) {
ctx.status = 400;
ctx.body = error;
} else {
ctx.status = 200;
ctx.body = rslt;
}
}
module.exports = {
@ -361,4 +435,5 @@ module.exports = {
findAlarmsDevices,
findDevicesCardStatus,
getDevicesLlinkStatus,
findAlarmsDevice
}

12
api/app/lib/routes/analysis/network.js

@ -13,7 +13,7 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/metrics/things/:iotaThingId/devices/link_status'] = { content: '获取设备在线状态/以结构物id集体获取', visible: true };
router.get('/metrics/things/:iotaThingId/devices/link_status', network.iotaLinkStatus)
app.fs.api.logAttr['GET/meta/things/:iotaThingId/devices'] = { content: '原始数据查询失败', visible: false };
router.get('/meta/things/:iotaThingId/devices', network.findDeviceMetaDeployed)
@ -27,13 +27,9 @@ module.exports = function (app, router, opts) {
router.post('/devices/cardStatus', network.findDevicesCardStatus);
app.fs.api.logAttr['GET/metrics/devices/:deviceId/link_status'] = { content: '获取设备在线状态/以设备id单个获取', visible: false };
router.get('/metrics/devices/:deviceId/link_status', network.getDevicesLlinkStatus);
// app.fs.api.logAttr['GET/systemAvailability'] = { content: '获取系统可用性', visible: true };
// router.get('/systemAvailability', operationData.getSystemAvailability)
router.get('/metrics/devices/:deviceId/link_status', network.getDevicesLlinkStatus);
// app.fs.api.logAttr['GET/problemType'] = { content: '获取故障类型', visible: true };
// router.get('/problemType', operationData.getProblemType)
app.fs.api.logAttr['GET/device/:deviceId/alarms'] = { content: '获取设备告警信息', visible: true };
router.get('/device/:deviceId/alarms', network.findAlarmsDevice);
// app.fs.api.logAttr['GET/operationsPersonnel'] = { content: '获取运维人员', visible: true };
// router.get('/operationsPersonnel', operationData.getOperationsPersonnel)
}

19
web-network/client/src/sections/network/actions/network.js

@ -119,18 +119,23 @@ export function getDevicesLlinkStatus (id) {
})
}
export function findAlarmsDevice (id) {
export function findAlarmsDevice (deviceIds, query) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_FIND_ALARMS_DEVICE',
url: `${ApiTable.getDevicesLlinkStatus.replace('{deviceId}', id)}`,
msg: { error: '获取设备告警信息失败' },
reducer: { name: '' }
})
query: query,
actionType: 'GET_FIND_ALARM_DEVICES',
url: `device/${deviceIds}/alarms`,
msg: {
error: '获取设备告警信息失败'
},
reducer: {
name: ''
}
});
}
export default {
getOrganizationsStruc,
getThingsDeploy,

151
web-network/client/src/sections/network/components/device-tree/equipment-option.js

@ -12,85 +12,82 @@ import { Request } from '@peace/utils'
const TabPane = Tabs.TabPane;
export default ({...props}) => {
const { isEdit, devices, info, parentNode, dimensions, height, deviceMetas, dispatch } = props;
const [linkState, setLinkState] = useSafeState(null);
const [alarmMsg, setAlarmMsg] = useSafeState({ new: [],history: [] });
const [currentDeviceId, setCurrentDeviceId] = useSafeState(null);
const [activeKey, setActiveKey] = useSafeState('1');
const callback = (key) => {
setActiveKey(key)
}
useEffect(() => {
if(info){
if(info?.linkState){
setLinkState(info.linkState)
}
if(info?.device?.id && info.device.id != currentDeviceId){
setCurrentDeviceId(info.device.id);
setActiveKey('1');
let url = ApiTable.getDevicesLlinkStatus.replace('{deviceId}', info.device.id);
export default ({ ...props }) => {
const { isEdit, devices, info, parentNode, dimensions, height, deviceMetas, dispatch, actions } = props;
const { analysis } = actions
const [linkState, setLinkState] = useSafeState(null);
const [alarmMsg, setAlarmMsg] = useSafeState({ new: [], history: [] });
const [currentDeviceId, setCurrentDeviceId] = useSafeState(null);
const [activeKey, setActiveKey] = useSafeState('1');
const callback = (key) => {
setActiveKey(key)
}
useEffect(() => {
if (info) {
if (info?.linkState) {
setLinkState(info.linkState)
}
if (info?.device?.id && info.device.id != currentDeviceId) {
setCurrentDeviceId(info.device.id);
setActiveKey('1');
dispatch(analysis.getDevicesLlinkStatus(info?.device?.id)).then(res => {
if (res.success) {
setLinkState(res.payload?.data?.status)
}
})
Request.get(url)
.then(res => {
setLinkState(res.status)
}, error => {
message.warning('设备在线状态获取失败');
});
dispatch(analysis.findAlarmsDevice(info?.device?.id, { limit: 5 })).then(res => {
if (res.success) {
setAlarmMsg({ new: res.payload?.data?.new || [], history: res.payload?.data?.history || [] })
}
url = ApiTable.getDeviceAlarms.replace('{deviceId}', info.device.id);
Request.get(url, { limit: 5 })
.then(res => {
setAlarmMsg({ new: res.new || [],history: res.history || []})
}
, error => {
message.warning('设备告警信息获取失败');
});
}
}
})
}
}, [info]);
let tab = "属性";
if (info && info?.type == "equipment") {
tab = "属性"
} else if (info && info?.type == "dimension") {
tab = "采集策略"
}
return (
<Tabs defaultActiveKey="1" activeKey={activeKey} onChange={callback} style={{ paddingRight: 16 }}>
<TabPane tab={tab} key="1">
{info && parentNode ?
info.type == "equipment" ?
<Option
isEdit={isEdit}
devices={devices}
info={info}
parentNode={parentNode}
deviceMetas={deviceMetas}
dimensions={dimensions}
height={height}
dispatch={dispatch}
/>
: < DimensionOption
isEdit={isEdit}
info={info}
height={height}
/>
: null
}
</TabPane>
{
parentNode && info && info.meta && info.meta.filteredResource && (JSON.parse(info.meta.filteredResource.properties).deviceType != 'dau.node') ?
<TabPane tab="状态" key="2">
<State
linkState={linkState}
alarmMsg={alarmMsg}
/>
</TabPane> : null
}
</Tabs>
)
}
}, [info]);
let tab = "属性";
if (info && info?.type == "equipment") {
tab = "属性"
} else if (info && info?.type == "dimension") {
tab = "采集策略"
}
return (
<Tabs defaultActiveKey="1" activeKey={activeKey} onChange={callback} style={{ paddingRight: 16 }}>
<TabPane tab={tab} key="1">
{info && parentNode ?
info.type == "equipment" ?
<Option
isEdit={isEdit}
devices={devices}
info={info}
parentNode={parentNode}
deviceMetas={deviceMetas}
dimensions={dimensions}
height={height}
dispatch={dispatch}
/>
: < DimensionOption
isEdit={isEdit}
info={info}
height={height}
/>
: null
}
</TabPane>
{
parentNode && info && info.meta && info.meta.filteredResource && (JSON.parse(info.meta.filteredResource.properties).deviceType != 'dau.node') ?
<TabPane tab="状态" key="2">
<State
linkState={linkState}
alarmMsg={alarmMsg}
/>
</TabPane> : null
}
</Tabs>
)
}

3
web-network/client/src/sections/network/components/device-tree/index.js

@ -17,7 +17,7 @@ const { ModifyEquipmentNetworking } = AuthorizationCode;
export default function ({ ...props }) {
const {
dispatch, clientHeight, deviceMetasWithFollow, deviceList, dimensionlist, struct,
dispatch,actions, clientHeight, deviceMetasWithFollow, deviceList, dimensionlist, struct,
} = props;
const [g6TreeDirection, setG6TreeDirection] = useSafeState('TB');
const [devices, setDevices] = useSafeState(null);
@ -305,6 +305,7 @@ export default function ({ ...props }) {
dimensions={dimensionlist}
height={containerHeight}
dispatch={dispatch}
actions={actions}
/>
</Drawer>
</div>

78
web-network/client/src/sections/network/containers/device-monitor.js

@ -14,7 +14,7 @@ import { DeviceTypes } from '../constant';
import qs from "qs";
import '../style.less';
import TableShow from './tableShow'
import TableShow from './tableShow'
function DeviceMonitor ({ ...props }) {
const {
dispatch, actions, user, clientWidth, clientHeight, loading,
@ -30,13 +30,19 @@ function DeviceMonitor ({ ...props }) {
let strucParam = JSON.parse((qs.parse(props.location?.search.slice(1)) || {})?.strucData)
console.log(1111, strucParam)
useEffect(() => {
if (strucParam?.thingId) {
dispatch(analysis.getThingsDeploy(strucParam?.thingId))
dispatch(analysis.getThingsDeploy(strucParam?.thingId)).then(res => {
console.log(3213, res);
if (res.success) {
const instances = res?.payload?.data?.instances;
if (instances) {
const deviceIds = Object.keys(instances).filter((k) => instances[k]?.type == 's.d');
dispatch(analysis.getDevicesAlarms(deviceIds, { limit: 5 }));
}
}
})
dispatch(analysis.getDeviceMetaDeployed(strucParam?.thingId))
}
}, []);
@ -107,59 +113,6 @@ function DeviceMonitor ({ ...props }) {
return result;
}, [devices, deviceListAlarms]);
// 筛选过滤数据
const filterDataSource = () => {
const {
name, deviceType, productType, productName, location, status,
} = params;
return dataSource.filter((s) => (name ? s.name ? (s.name.indexOf(name) != -1 || PinyinHelper.isPinyinMatched(s.name, name)) : false : true)
&& (location ? s.location ? (s.location.indexOf(location) != -1 || PinyinHelper.isPinyinMatched(s.location, location)) : false : true)
&& (deviceType ? s.deviceTypeId == deviceType : true)
&& (productType ? s.productType == productType : true)
&& (status ? s.status == status : true)
&& (productName ? s.productName ? (s.productName.indexOf(productName) != -1 || PinyinHelper.isPinyinMatched(s.productName, productName)) : false : true));
};
// const deviceTypeIds = Func.uniqueArr(dataSource, 'deviceTypeId');
// const productTypeIds = Func.uniqueArr(dataSource, 'productType');
const columns = [{
title: '名称',
dataIndex: 'name',
ellipsis: true,
}, {
title: '设备类型',
dataIndex: 'deviceType',
// valueEnum: Func.transValueEnum(deviceTypeIds, 'deviceTypeId', 'deviceType'),
// fieldProps: Func.getSelectCommonProps(),
}, {
title: '产品名称',
dataIndex: 'productName',
ellipsis: true,
}, {
title: '产品型号',
dataIndex: 'productType',
// valueEnum: Func.transValueEnum(productTypeIds, 'productType', 'productType'),
// fieldProps: Func.getSelectCommonProps(),
}, {
title: '测点',
dataIndex: 'location',
}, {
title: '状态',
dataIndex: 'status',
filters: true,
onFilter: true,
valueEnum: {
normal: { text: '正常', status: 'Success' },
alarm: { text: '异常', status: 'Error' },
},
// fieldProps: Func.getSelectCommonProps(),
}];
const renderTitle = () => (
<div className="device-monitor">
设备总数:
@ -177,10 +130,9 @@ function DeviceMonitor ({ ...props }) {
;
</div>
);
const data = filterDataSource();
return (
// <div>div</div>
// <LayoutContent>
<Spin spinning={false}>
<ProCard title={renderTitle()} extra={renderExtra()} headerBordered>
{
@ -193,18 +145,18 @@ function DeviceMonitor ({ ...props }) {
deviceList={devices}
dimensionlist={dimensions}
dispatch={dispatch}
actions={actions}
struct={strucParam}
clientHeight={clientHeight}
clientWidth={clientWidth}
/>
) : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
: (
<TableShow thingId={strucParam.thingId} project={strucParam.projectId}/>
<TableShow thingId={strucParam.thingId} project={strucParam.projectId} />
)
}
</ProCard>
</Spin>
// </LayoutContent>
);
}

Loading…
Cancel
Save