This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/views/entityExplorer/entityList/entityListMixin.js

268 lines
7.9 KiB
JavaScript
Raw Normal View History

2021-12-16 18:22:47 +08:00
import _ from 'lodash'
2021-12-31 10:40:37 +08:00
import { get } from '@/utils/http'
import { api } from '@/utils/api'
import * as echarts from 'echarts'
import { entityListLineOption } from '@/components/charts/chart-options'
import {riskLevelMapping, unitTypes} from '@/utils/constants'
2021-12-16 18:22:47 +08:00
export default {
props: {
2021-12-31 10:40:37 +08:00
entity: Object,
timeFilter: {},
listMode: ''
2021-12-16 18:22:47 +08:00
},
data () {
return {
2021-12-31 10:40:37 +08:00
entityData: {},
chartOption: null
2021-12-16 18:22:47 +08:00
}
},
computed: {
iconClass () {
let className
switch (this.entityData.entityType) {
case ('ip'): {
className = 'cn-icon cn-icon-ip'
break
}
case ('domain'): {
className = 'cn-icon cn-icon-domain'
break
}
case ('app'): {
className = 'cn-icon cn-icon-app'
break
}
default: break
}
return className
2021-12-31 10:40:37 +08:00
},
entityName () {
let name
switch (this.entityData.entityType) {
case ('ip'): {
2022-01-03 22:46:22 +08:00
name = this.entity.ipAddr
2021-12-31 10:40:37 +08:00
break
}
case ('domain'): {
name = this.entity.domainName
break
}
case ('app'): {
name = this.entity.appName
break
}
default: break
}
return name
},
queryUrl () {
let url
switch (this.entityData.entityType) {
case ('ip'): {
url = api.ipBytes
break
}
case ('domain'): {
url = api.domainBytes
break
}
case ('app'): {
url = api.appBytes
break
}
default: break
}
return url
},
appRisk () {
return function (level) {
const m = riskLevelMapping.find(mapping => {
return mapping.value == level
})
return (m && m.name) || level
}
},
2021-12-31 10:40:37 +08:00
queryParams () {
let params
const now = window.$dayJs.tz().valueOf()
2021-12-31 10:40:37 +08:00
switch (this.entityData.entityType) {
case ('ip'): {
params = {
startTime: this.timeFilter.startTime ? parseInt(this.timeFilter.startTime / 1000) : Math.floor(now / 1000 - 3600),
endTime: this.timeFilter.endTime ? parseInt(this.timeFilter.endTime / 1000) : Math.floor(now / 1000),
ip: this.entityData.ipAddr
2021-12-31 10:40:37 +08:00
}
break
}
case ('domain'): {
params = {
startTime: this.timeFilter.startTime ? parseInt(this.timeFilter.startTime / 1000) : Math.floor(now / 1000 - 3600),
endTime: this.timeFilter.endTime ? parseInt(this.timeFilter.endTime / 1000) : Math.floor(now / 1000),
2021-12-31 10:40:37 +08:00
domain: this.entityData.domainName
}
break
}
case ('app'): {
params = {
startTime: this.timeFilter.startTime ? parseInt(this.timeFilter.startTime / 1000) : Math.floor(now / 1000 - 3600),
endTime: this.timeFilter.endTime ? parseInt(this.timeFilter.endTime / 1000) : Math.floor(now / 1000),
2021-12-31 10:40:37 +08:00
appName: this.entityData.appName
}
break
}
default: break
}
return params
2021-12-16 18:22:47 +08:00
}
},
methods: {
showDetail () {
const { href } = this.$router.resolve({
path: '/entityDetail',
query: {
entityType: this.entityData.entityType,
name: this.entityData.ipAddr || this.entityData.domainName || this.entityData.appName
}
})
window.open(href, '_blank')
2021-12-16 18:22:47 +08:00
},
queryTraffic () {
const queryParams = {
startTime: parseInt(this.timeFilter.startTime / 1000),
endTime: parseInt(this.timeFilter.endTime / 1000),
entityType: this.entityData.entityType,
name: this.entityName
}
get(api.entityTraffic, queryParams).then(response => {
2021-12-31 10:40:37 +08:00
if (response.code === 200) {
response.data.result.forEach(t => {
2022-01-06 16:56:41 +08:00
if (t.legend === 'bytesSentRate') {
this.entityData.bytesSentRate = t.aggregation.last
2021-12-31 10:40:37 +08:00
}
2022-01-06 16:56:41 +08:00
if (t.legend === 'bytesReceivedRate') {
this.entityData.bytesReceivedRate = t.aggregation.last
2021-12-31 10:40:37 +08:00
}
})
}
})
2021-12-16 18:22:47 +08:00
},
querySecurity () {
const queryParams = {
startTime: parseInt(this.timeFilter.startTime / 1000),
endTime: parseInt(this.timeFilter.endTime / 1000),
entityType: this.entityData.entityType,
name: this.entityName
}
get(api.entitySecurityNum, queryParams).then(response => {
2021-12-31 10:40:37 +08:00
if (response.code === 200) {
this.entityData.securityCount = response.data.result[0].count
}
})
2021-12-16 18:22:47 +08:00
},
queryAlert () {
const queryParams = {
startTime: parseInt(this.timeFilter.startTime / 1000),
endTime: parseInt(this.timeFilter.endTime / 1000),
entityType: this.entityData.entityType,
name: this.entityName
}
get(api.entityAlertNum, queryParams).then(response => {
2021-12-31 10:40:37 +08:00
if (response.code === 200) {
2022-01-04 14:54:26 +08:00
this.entityData.alertCount = response.data.result[0].value
2021-12-31 10:40:37 +08:00
}
})
},
2021-12-16 18:22:47 +08:00
2021-12-31 10:40:37 +08:00
queryTrafficLine () {
let chartOption
this.chartOption = this.$_.cloneDeep(entityListLineOption)
get(this.queryUrl, this.queryParams).then(response => {
if (response.code === 200) {
const seriesTemplate = this.chartOption.series[0]
const series = response.data.result.map((r, i) => {
if (r.legend === 'bytes_sent_rate') {
2021-12-31 10:40:37 +08:00
return {
...seriesTemplate,
name: this.$t('entities.sentThroughput'), // 'bytes_sent_rate',//legendMapping[`ip_${r.legend}`],
data: r.values.map(v => [Number(v[0]) * 1000, Number(v[1]), unitTypes.byte]),
2021-12-31 10:40:37 +08:00
itemStyle: {
normal: {
color: '#69b072',
lineStyle: {
width: 1.5
}
}
},
smooth: true,
areaStyle: {
opacity: 0.8,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: '#f0fff8'
},
{
offset: 1,
color: '#f0fff8'
}
])
}
}
} else if (r.legend === 'bytes_received_rate') {
2021-12-31 10:40:37 +08:00
return {
...seriesTemplate,
name: this.$t('entities.receivedThroughput'), // legendMapping[`ip_${r.legend}`],
data: r.values.map(v => [Number(v[0]) * 1000, Number(v[1]), unitTypes.byte]),
2021-12-31 10:40:37 +08:00
itemStyle: {
normal: {
color: '#7899c6',
lineStyle: {
width: 1.5
}
}
},
smooth: true,
areaStyle: {
opacity: 0.8,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: '#f0f4ff'
},
{
offset: 1,
color: '#f0f4ff'
}
])
}
}
}
return {}
2021-12-31 10:40:37 +08:00
})
chartOption = {
...this.chartOption,
series
}
}
}).finally(() => {
this.$nextTick(() => {
if (chartOption) {
const myChart = echarts.init(document.getElementById(`entityListChart${this.entityName}`))
myChart.setOption(chartOption)
}
2021-12-31 10:40:37 +08:00
})
})
2021-12-16 18:22:47 +08:00
}
},
mounted () {
this.entityData = _.cloneDeep(this.entity)
setTimeout(() => { this.queryTraffic() })
setTimeout(() => { this.querySecurity() })
setTimeout(() => { this.queryAlert() })
2021-12-31 10:40:37 +08:00
if (this.listMode === 'block') {
setTimeout(() => { this.queryTrafficLine() })
}
2021-12-16 18:22:47 +08:00
}
}