Browse Source

告警信息查询

dev
wenlele 1 year ago
parent
commit
6bf2894305
  1. 75
      api/app/lib/controllers/analysis/network.js
  2. 10
      api/app/lib/routes/analysis/network.js
  3. 19
      web-network/client/src/sections/network/actions/network.js
  4. 145
      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 = { module.exports = {
@ -361,4 +435,5 @@ module.exports = {
findAlarmsDevices, findAlarmsDevices,
findDevicesCardStatus, findDevicesCardStatus,
getDevicesLlinkStatus, getDevicesLlinkStatus,
findAlarmsDevice
} }

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

@ -27,13 +27,9 @@ module.exports = function (app, router, opts) {
router.post('/devices/cardStatus', network.findDevicesCardStatus); router.post('/devices/cardStatus', network.findDevicesCardStatus);
app.fs.api.logAttr['GET/metrics/devices/:deviceId/link_status'] = { content: '获取设备在线状态/以设备id单个获取', visible: false }; app.fs.api.logAttr['GET/metrics/devices/:deviceId/link_status'] = { content: '获取设备在线状态/以设备id单个获取', visible: false };
router.get('/metrics/devices/:deviceId/link_status', network.getDevicesLlinkStatus); router.get('/metrics/devices/:deviceId/link_status', network.getDevicesLlinkStatus);
// app.fs.api.logAttr['GET/systemAvailability'] = { content: '获取系统可用性', visible: true };
// router.get('/systemAvailability', operationData.getSystemAvailability)
// app.fs.api.logAttr['GET/problemType'] = { content: '获取故障类型', visible: true }; app.fs.api.logAttr['GET/device/:deviceId/alarms'] = { content: '获取设备告警信息', visible: true };
// router.get('/problemType', operationData.getProblemType) 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({ return dispatch => basicAction({
type: 'get', type: 'get',
dispatch: dispatch, dispatch: dispatch,
actionType: 'GET_FIND_ALARMS_DEVICE', query: query,
url: `${ApiTable.getDevicesLlinkStatus.replace('{deviceId}', id)}`, actionType: 'GET_FIND_ALARM_DEVICES',
msg: { error: '获取设备告警信息失败' }, url: `device/${deviceIds}/alarms`,
reducer: { name: '' } msg: {
}) error: '获取设备告警信息失败'
},
reducer: {
name: ''
}
});
} }
export default { export default {
getOrganizationsStruc, getOrganizationsStruc,
getThingsDeploy, getThingsDeploy,

145
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; const TabPane = Tabs.TabPane;
export default ({...props}) => { export default ({ ...props }) => {
const { isEdit, devices, info, parentNode, dimensions, height, deviceMetas, dispatch } = props; const { isEdit, devices, info, parentNode, dimensions, height, deviceMetas, dispatch, actions } = props;
const [linkState, setLinkState] = useSafeState(null); const { analysis } = actions
const [alarmMsg, setAlarmMsg] = useSafeState({ new: [],history: [] });
const [currentDeviceId, setCurrentDeviceId] = useSafeState(null); const [linkState, setLinkState] = useSafeState(null);
const [activeKey, setActiveKey] = useSafeState('1'); const [alarmMsg, setAlarmMsg] = useSafeState({ new: [], history: [] });
const callback = (key) => { const [currentDeviceId, setCurrentDeviceId] = useSafeState(null);
setActiveKey(key) const [activeKey, setActiveKey] = useSafeState('1');
} const callback = (key) => {
useEffect(() => { setActiveKey(key)
if(info){ }
if(info?.linkState){ useEffect(() => {
setLinkState(info.linkState) if (info) {
} if (info?.linkState) {
if(info?.device?.id && info.device.id != currentDeviceId){ setLinkState(info.linkState)
setCurrentDeviceId(info.device.id); }
setActiveKey('1'); if (info?.device?.id && info.device.id != currentDeviceId) {
let url = ApiTable.getDevicesLlinkStatus.replace('{deviceId}', info.device.id); 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('设备在线状态获取失败');
});
url = ApiTable.getDeviceAlarms.replace('{deviceId}', info.device.id); dispatch(analysis.findAlarmsDevice(info?.device?.id, { limit: 5 })).then(res => {
if (res.success) {
setAlarmMsg({ new: res.payload?.data?.new || [], history: res.payload?.data?.history || [] })
}
Request.get(url, { limit: 5 }) })
.then(res => { }
setAlarmMsg({ new: res.new || [],history: res.history || []})
}
, error => {
message.warning('设备告警信息获取失败');
});
}
} }
}, [info]); }, [info]);
let tab = "属性"; let tab = "属性";
if (info && info?.type == "equipment") { if (info && info?.type == "equipment") {
tab = "属性" tab = "属性"
} else if (info && info?.type == "dimension") { } else if (info && info?.type == "dimension") {
tab = "采集策略" tab = "采集策略"
} }
return ( return (
<Tabs defaultActiveKey="1" activeKey={activeKey} onChange={callback} style={{ paddingRight: 16 }}> <Tabs defaultActiveKey="1" activeKey={activeKey} onChange={callback} style={{ paddingRight: 16 }}>
<TabPane tab={tab} key="1"> <TabPane tab={tab} key="1">
{info && parentNode ? {info && parentNode ?
info.type == "equipment" ? info.type == "equipment" ?
<Option <Option
isEdit={isEdit} isEdit={isEdit}
devices={devices} devices={devices}
info={info} info={info}
parentNode={parentNode} parentNode={parentNode}
deviceMetas={deviceMetas} deviceMetas={deviceMetas}
dimensions={dimensions} dimensions={dimensions}
height={height} height={height}
dispatch={dispatch} dispatch={dispatch}
/> />
: < DimensionOption : < DimensionOption
isEdit={isEdit} isEdit={isEdit}
info={info} info={info}
height={height} height={height}
/> />
: null : 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> </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 }) { export default function ({ ...props }) {
const { const {
dispatch, clientHeight, deviceMetasWithFollow, deviceList, dimensionlist, struct, dispatch,actions, clientHeight, deviceMetasWithFollow, deviceList, dimensionlist, struct,
} = props; } = props;
const [g6TreeDirection, setG6TreeDirection] = useSafeState('TB'); const [g6TreeDirection, setG6TreeDirection] = useSafeState('TB');
const [devices, setDevices] = useSafeState(null); const [devices, setDevices] = useSafeState(null);
@ -305,6 +305,7 @@ export default function ({ ...props }) {
dimensions={dimensionlist} dimensions={dimensionlist}
height={containerHeight} height={containerHeight}
dispatch={dispatch} dispatch={dispatch}
actions={actions}
/> />
</Drawer> </Drawer>
</div> </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 qs from "qs";
import '../style.less'; import '../style.less';
import TableShow from './tableShow' import TableShow from './tableShow'
function DeviceMonitor ({ ...props }) { function DeviceMonitor ({ ...props }) {
const { const {
dispatch, actions, user, clientWidth, clientHeight, loading, 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) let strucParam = JSON.parse((qs.parse(props.location?.search.slice(1)) || {})?.strucData)
console.log(1111, strucParam)
useEffect(() => { useEffect(() => {
if (strucParam?.thingId) { 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)) dispatch(analysis.getDeviceMetaDeployed(strucParam?.thingId))
} }
}, []); }, []);
@ -107,59 +113,6 @@ function DeviceMonitor ({ ...props }) {
return result; return result;
}, [devices, deviceListAlarms]); }, [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 = () => ( const renderTitle = () => (
<div className="device-monitor"> <div className="device-monitor">
设备总数: 设备总数:
@ -177,10 +130,9 @@ function DeviceMonitor ({ ...props }) {
; ;
</div> </div>
); );
const data = filterDataSource();
return ( return (
// <div>div</div>
// <LayoutContent>
<Spin spinning={false}> <Spin spinning={false}>
<ProCard title={renderTitle()} extra={renderExtra()} headerBordered> <ProCard title={renderTitle()} extra={renderExtra()} headerBordered>
{ {
@ -193,18 +145,18 @@ function DeviceMonitor ({ ...props }) {
deviceList={devices} deviceList={devices}
dimensionlist={dimensions} dimensionlist={dimensions}
dispatch={dispatch} dispatch={dispatch}
actions={actions}
struct={strucParam} struct={strucParam}
clientHeight={clientHeight} clientHeight={clientHeight}
clientWidth={clientWidth} clientWidth={clientWidth}
/> />
) : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /> ) : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
: ( : (
<TableShow thingId={strucParam.thingId} project={strucParam.projectId}/> <TableShow thingId={strucParam.thingId} project={strucParam.projectId} />
) )
} }
</ProCard> </ProCard>
</Spin> </Spin>
// </LayoutContent>
); );
} }

Loading…
Cancel
Save