MCPcopy Create free account
hub / github.com/PKU-ASAL/Simulated-Data / caculate_anomaly_score

Method caculate_anomaly_score

src/Sysdig/real-time/ProvGraph.py:417–497  ·  view source on GitHub ↗
(self,pnode,anomaly_cutoff)

Source from the content-addressed store, hash-verified

415 # cnt += 1
416 return g
417 def caculate_anomaly_score(self,pnode,anomaly_cutoff):
418 need_to_caculate = defaultdict(list)
419 # nodes = self.G.nodes()
420 # have better way to find neighbor?
421 undirected_G = self.G.to_undirected(as_view=True)
422 print(len(pnode))
423 for node in pnode:
424 neibor = list(undirected_G[node])
425 # print(node)
426 if len(neibor) == 0:
427 continue
428 # tmp_dict = set()
429 for nei in neibor:
430
431 if self.GetNodeName(nei) is not None and self.GetNodeName(nei) != 'unknown' and self.GetNodeType(nei) != APTLOG_NODE_TYPE.PROCESS:
432 need_to_caculate[node].append((nei,self.GetNodeName(nei)))
433 # tmp_dict.add(self.GetNodeAttr(nei))
434 # except Exception as e:
435 # print(nei,self.GetNodeAttr(nei))
436 print('need_to_caculate',len(need_to_caculate))
437
438 if len(need_to_caculate) == 0:
439 return -1
440 node_feature = defaultdict(list)
441
442 for node in need_to_caculate.keys():
443 flag = False
444 cmdline = self.GetNodeName(node)
445 split_path = sanitize_string(cmdline)
446 if len(split_path) == 0:
447 continue
448 new_name = '/'.join(split_path)
449 self.nodes[node]['newname'] = new_name
450 tmp = []
451 for l,i in enumerate(split_path):
452 tmp += [self.c2v.wv[i]]
453 r = np.mean(tmp,axis=0) * self.mean_tfidf
454
455 node_feature[node] += [r.tolist()]
456 tmp_dict = set()
457 process_objects = set(need_to_caculate[node])
458 for id,object_name in process_objects:
459 split_path = sanitize_string(object_name)
460 if len(split_path) == 0:
461 continue
462 flag = True
463 new_name = '/'.join(split_path)
464 self.nodes[id]['newname'] = new_name
465
466 tmp = []
467 for l,i in enumerate(split_path):
468 tmp += [self.w2v.wv[i]]
469 r = np.mean(tmp,axis=0)
470 try:
471 t = self.tfidf[new_name.lower()]
472 except:
473 t = self.mean_tfidf
474 r = r * t

Callers 1

updateMethod · 0.95

Calls 4

GetNodeNameMethod · 0.95
GetNodeTypeMethod · 0.95
sanitize_stringFunction · 0.50
VAEInferMethod · 0.45

Tested by

no test coverage detected