result = misp.search(last='{}d'.format(args.days), metadata=True) tools.checkDateConsistancy(args.begindate, args.enddate, tools.getLastdate(args.days)) if args.begindate is None: args.begindate = tools.getLastdate(args.days) else: args.begindate = tools.setBegindate(tools.toDatetime(args.begindate), tools.getLastdate(args.days)) if args.enddate is None: args.enddate = datetime.now() else: args.enddate = tools.setEnddate(tools.toDatetime(args.enddate)) if 'response' in result: events = tools.selectInRange(tools.eventsListBuildFromArray(result), begin=args.begindate, end=args.enddate) tags = tools.tagsListBuild(events) result = tools.getNbOccurenceTags(tags) else: result = 'There is no event during the studied period' text = 'Studied pediod: from ' if args.begindate is None: text = text + '1970-01-01' else: text = text + str(args.begindate.date()) text = text + ' to ' if args.enddate is None: text = text + str(datetime.now().date()) else: text = text + str(args.enddate.date())
misp = PyMISP(misp_url, misp_key, misp_verifycert) result = misp.search(date_from=args.begindate, date_to=args.enddate, metadata=False) # Getting data if 'response' in result: events = tools.eventsListBuildFromArray(result) NbTags = [] dates = [] enddate = date_tools.toDatetime(args.enddate) begindate = date_tools.toDatetime(args.begindate) for i in range(round(date_tools.days_between(enddate, begindate)/args.days)): begindate = date_tools.getNDaysBefore(enddate, args.days) eventstemp = tools.selectInRange(events, begindate, enddate) if eventstemp is not None: for event in eventstemp.iterrows(): if 'Tag' in event[1]: dates.append(enddate) if isinstance(event[1]['Tag'], list): NbTags.append(len(event[1]['Tag'])) else: NbTags.append(0) enddate = begindate # Prepare plot NbTagsPlot = {} datesPlot = {}
args.begindate = tools.getLastdate(args.days) else: args.begindate = tools.setBegindate(tools.toDatetime(args.begindate), tools.getLastdate(args.days)) if args.enddate is None: args.enddate = datetime.now() else: args.enddate = tools.setEnddate(tools.toDatetime(args.enddate)) Events = tools.eventsListBuildFromArray('data') TotalEvents = tools.getNbitems(Events) Tags = tools.tagsListBuild(Events) result = tools.getNbOccurenceTags(Tags) TotalTags = tools.getNbitems(Tags) Events = tools.selectInRange(Events, begin=args.begindate, end=args.enddate) TotalPeriodEvents = tools.getNbitems(Events) Tags = tools.tagsListBuild(Events) result = tools.getNbOccurenceTags(Tags) TotalPeriodTags = tools.getNbitems(Tags) text = 'Studied pediod: from ' if args.begindate is None: text = text + '1970-01-01' else: text = text + str(args.begindate.date()) text = text + ' to ' if args.enddate is None: text = text + str(datetime.now().date()) else: text = text + str(args.enddate.date())