diff --git a/src/packages/infra/component/map/map.component.ts b/src/packages/infra/component/map/map.component.ts index 6755204..68619c9 100644 --- a/src/packages/infra/component/map/map.component.ts +++ b/src/packages/infra/component/map/map.component.ts @@ -17,6 +17,12 @@ import { Infra, InfraHost, InfraOSApplication, InfraService } from '../../model' import { Domain } from 'packages/domain/model'; import { AuthSelector } from 'packages/member/store'; +import { sensorListSelector } from 'packages/sensor/store'; + +import * as SensorListStore from 'packages/sensor/store/list'; +import { Sensor } from 'packages/sensor/model'; + +import * as _ from 'lodash'; interface HostData { id: string; @@ -34,6 +40,7 @@ export class MapComponent implements OnInit, AfterContentInit { infraTree: TreeNode[] = []; infras$ = this.listStore.pipe(select(ListSelector.select('page'))); + sensors$ = this.sensorListStore.pipe(select(sensorListSelector.select('page'))); display = false; loading = false; @@ -41,10 +48,15 @@ export class MapComponent implements OnInit, AfterContentInit { totalList: Infra[]; hostDataList: HostData[] = new Array(); + sensorMap: Map> = new Map(); + + targetTreeMap: Map = new Map(); + DEFAULT_EXPANDED: Boolean = true; constructor(private router: Router, private listStore: Store, + private sensorListStore: Store ) {} ngAfterContentInit() { @@ -79,10 +91,88 @@ export class MapComponent implements OnInit, AfterContentInit { (error: RPCClientError) => { console.log(error.response.message); }); + + this.sensors$.subscribe( + (page: Page) => { + if (page !== null) { + const sensorList = page.content; + console.log(sensorList); + this.addTreeForSensor(sensorList); + } + }, + (error: RPCClientError) => { + console.log(error.response.message); + } + ); } ngOnInit() {} + searchObj(treeList: any[], target: Target, searchList: any[]) { + + if (treeList === undefined || treeList === null) { + return; + } + + for (const t of treeList) { + if (t.obj !== undefined && t.obj == null) { + if (t.obj.target.id === target.id) { + searchList.push(t); + } else { + this.searchObj(t.children, target, searchList); + } + } + } + + } + + addTreeForSensor(sensorList: Array) { + + if (sensorList === undefined || sensorList === null || sensorList.length <= 0) { + return; + } + + // const tInfraTree = _.clone(this.infraTree); + + // const it = tInfraTree[0]; + // const it = this.infraTree[0]; + // // for (const it of this.infraTree) { + // if (it.children === null || it.children === undefined) { + // it.children = []; + // } + + // for (const itt of this.infraTree) { + + // } + + + // } + + for (const sensor of sensorList) { + const st = { + label: 'Sensors - ' + sensor.crawler.name, + expandedIcon: 'fa-folder-open', + collapsedIcon: 'fa-folder', + obj: sensor, + expanded: true + }; + + // FIXME:: target test id .... + const tt = this.targetTreeMap.get(3); + // const tt = this.targetTreeMap.get(sensor.target.id); + if (tt !== undefined && tt !== null) { + tt.children.push(st); + } + + + // it.children.push(st); + + } + + // this.infraTree = tInfraTree; + + } + generateInfraHostData(filterStr?: string): TreeNode[] { @@ -125,13 +215,7 @@ export class MapComponent implements OnInit, AfterContentInit { const ihl: InfraHost[] = probeMap.get(infraHost.probe.id); ihl.push(infraHost); probeMap.set(infraHost.probe.id, ihl); - // const data: HostData = { - // id: String(infra.id), - // target: infra.target, - // host: infra, - // services: new Array(), - // }; - // this.hostDataList.push(data); + } else if (infraType === 'OS_SERVICE') { const infraService: InfraService = infra; if (filterStr && this.checkFilterString(infraService, filterStr)) { @@ -145,70 +229,66 @@ export class MapComponent implements OnInit, AfterContentInit { const isl = hostMap.get(infraService.host.ip); isl.push(infraService); - // const existHost = this.getExistHost(infraService.host); - // if (existHost !== null) { - // existHost.services.push(infraService); - // } else { - // const host: HostData = { - // id: String(infra.id), - // target: infra.target, - // host: infraService.host, - // services: new Array() - // }; - // host.services.push(infraService); - // this.hostDataList.push(host); - // } - - - } } - const ProbeTree = { - label: 'Probe', - expandedIcon: 'fa-folder-open', - collapsedIcon: 'fa-folder', - expanded: true, - children: [], - }; + // const ProbeTree = { + // label: 'Probe', + // expandedIcon: 'fa-folder-open', + // collapsedIcon: 'fa-folder', + // expanded: true, + // children: [], + // }; // const probeTreeNodes: TreeNode[] = []; + this.targetTreeMap.clear(); + probeMap.forEach((ifhl: InfraHost[], key: number) => { - const tp: TreeNode = { + const tp = { label: 'Probe - ' + key, expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: this.DEFAULT_EXPANDED.valueOf(), + obj: ifhl, children: [], }; + ifhl.map((ih: InfraHost, idx: number) => { - const th: TreeNode = { + const th = { label: 'Host - ' + ih.ip, expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: this.DEFAULT_EXPANDED.valueOf(), + obj: ih, children: [], }; + this.targetTreeMap.set(ih.target.id, th); + if (hostMap.has(ih.ip)) { const ifsl = hostMap.get(ih.ip); + + for (let i = 0 ; i < ifsl.length; ++i) { - const ts: TreeNode = { + const ts = { label: 'Service - ' + ifsl[i].vendor.name, expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', expanded: this.DEFAULT_EXPANDED.valueOf(), + obj: ifsl[i], children: [], }; + this.targetTreeMap.set(ifsl[i].target.id, ts); + th.children.push(ts); } @@ -219,13 +299,13 @@ export class MapComponent implements OnInit, AfterContentInit { }); - ProbeTree.children.push(tp); + // ProbeTree.children.push(tp); + infraTree.children.push(tp); }); - - - infraTree.children.push(ProbeTree); - + for (const infra of this.totalList) { + this.getSensorByInfra(infra); + } this.loading = false; @@ -236,6 +316,20 @@ export class MapComponent implements OnInit, AfterContentInit { } + getSensorByInfra(infra: Infra) { + + const pageParams: PageParams = { + pageNo: '0', + countPerPage: '10', + sortCol: 'id', + sortDirection: 'descending' + }; + + this.sensorListStore.dispatch(new SensorListStore.ReadAllByInfra({id: String(infra.id), pageParams: pageParams})); + + } + + checkFilterString(infraService: InfraService, filterStr: string) { const upperCased = filterStr.toUpperCase().toUpperCase(); if (infraService.vendor.name.toUpperCase().indexOf(upperCased) < 0 &&