fixed infra and discovery

This commit is contained in:
snoop 2018-04-18 20:15:56 +09:00
parent c57f1193f3
commit f2a16ac753
2 changed files with 58 additions and 65 deletions

View File

@ -233,10 +233,10 @@ export class SettingComponent implements OnInit, AfterContentInit {
console.log(discoveryZone); console.log(discoveryZone);
// console.log('start discovery - ' + this.probe.probeKey); // console.log('start discovery - ' + this.probe.probeKey);
// this.discoverstore.dispatch(new DiscoverStore.DiscoverZone( this.discoverstore.dispatch(new DiscoverStore.DiscoverZone(
// { probeID: this.probe.probeKey, discoveryZone: discoveryZone })); { probeID: this.probe.probeKey, discoveryZone: discoveryZone }));
// this.started = true; this.started = true;
} }
checkDiscoveryResult(node) { checkDiscoveryResult(node) {

View File

@ -178,20 +178,32 @@ export class MapComponent implements OnInit, AfterContentInit {
const itl: TreeNode[] = []; const itl: TreeNode[] = [];
const root: TreeNode = {
label: 'Infra',
expandedIcon: 'fa-folder-open',
collapsedIcon: 'fa-folder',
expanded: true,
children: [],
};
const probeMap: Map<number, InfraHost[]> = new Map(); const probeMap: Map<number, InfraHost[]> = new Map();
const hostMap: Map<number, InfraService[]> = new Map(); const hostMap: Map<number, InfraService[]> = new Map();
this.loading = true; this.loading = true;
this.sortInfraToMap(probeMap, hostMap, filterStr);
this.targetTreeMap.clear();
const infraTree: TreeNode = this.generateInfraTree(probeMap, hostMap);
for (const infra of this.totalList) {
this.getSensorByInfra(infra);
}
this.loading = false;
itl.push(infraTree);
return itl;
}
generateInfraTree(probeMap: Map<number, InfraHost[]>, hostMap: Map<number, InfraService[]>): TreeNode {
const infraTree = { const infraTree = {
label: 'Infra', label: 'Infra',
expandedIcon: 'fa-folder-open', expandedIcon: 'fa-folder-open',
@ -200,52 +212,6 @@ export class MapComponent implements OnInit, AfterContentInit {
children: [], children: [],
}; };
for (const infra of this.totalList) {
const infraType = infra.infraType.name;
if (infraType === 'HOST') {
const infraHost: InfraHost = infra;
if (filterStr && String(infraHost.ip).indexOf(filterStr) < 0) {
continue;
}
if (probeMap.has(infraHost.probe.id) === false) {
probeMap.set(infraHost.probe.id, []);
}
const ihl: InfraHost[] = probeMap.get(infraHost.probe.id);
ihl.push(infraHost);
probeMap.set(infraHost.probe.id, ihl);
} else if (infraType === 'OS_SERVICE') {
const infraService: InfraService = infra;
if (filterStr && this.checkFilterString(infraService, filterStr)) {
continue;
}
if (hostMap.has(infraService.host.ip) === false) {
hostMap.set(infraService.host.ip, []);
}
const isl = hostMap.get(infraService.host.ip);
isl.push(infraService);
}
}
// 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) => { probeMap.forEach((ifhl: InfraHost[], key: number) => {
const tp = { const tp = {
@ -303,17 +269,44 @@ export class MapComponent implements OnInit, AfterContentInit {
infraTree.children.push(tp); infraTree.children.push(tp);
}); });
return infraTree;
}
sortInfraToMap(probeMap: Map<number, InfraHost[]>, hostMap: Map<number, InfraService[]>, filterStr: string) {
for (const infra of this.totalList) { for (const infra of this.totalList) {
this.getSensorByInfra(infra); const infraType = infra.infraType.name;
if (infraType === 'HOST') {
const infraHost: InfraHost = infra;
if (filterStr && String(infraHost.ip).indexOf(filterStr) < 0) {
continue;
}
if (probeMap.has(infraHost.probe.id) === false) {
probeMap.set(infraHost.probe.id, []);
}
const ihl: InfraHost[] = probeMap.get(infraHost.probe.id);
ihl.push(infraHost);
probeMap.set(infraHost.probe.id, ihl);
} else if (infraType === 'OS_SERVICE') {
const infraService: InfraService = infra;
if (filterStr && this.checkFilterString(infraService, filterStr)) {
continue;
}
if (hostMap.has(infraService.host.ip) === false) {
hostMap.set(infraService.host.ip, []);
}
const isl = hostMap.get(infraService.host.ip);
isl.push(infraService);
}
} }
this.loading = false;
itl.push(infraTree);
return itl;
} }
getSensorByInfra(infra: Infra) { getSensorByInfra(infra: Infra) {