Ejemplo n.º 1
0
    def _check_tag(self, target_tag):

        if self.misp == None:
            self._connect()

        if self._registered_tags == None:
            self._get_tags()

        for tag_info in self._registered_tags:
            if tag_info.get('name', '') == target_tag:
                return True

        self.debug_print('new tag: {}'.format(target_tag))

        cnt = 0
        while True:
            try:
                if self.misp == None:
                    self._connect()

                tmp = MISPTag()
                tmp.from_dict(name=target_tag)
                self.misp.add_tag(tmp)
                self._get_tags()
                return True

            except:
                print(traceback.format_exc())

                if cnt < int(self.misp_param.get('max_retry_count', '0')):
                    print('add new tag retry: {}'.format(cnt))
                    cnt = cnt + 1
                    time.sleep(10)
                else:
                    return False
Ejemplo n.º 2
0
 def add_tag(self, tag_name: str, hex_color: str = None) -> None:
     """Helper method for adding a tag to the enriched attribute."""
     tag = MISPTag()
     tag_properties = {"name": tag_name}
     if hex_color:
         tag_properties["colour"] = hex_color
     tag.from_dict(**tag_properties)
     self.enriched_attribute.add_tag(tag)
Ejemplo n.º 3
0
 def test_event_tag(self):
     self.init_event()
     self.mispevent.add_tag('bar')
     self.mispevent.add_tag(name='baz')
     new_tag = MISPTag()
     new_tag.from_dict(name='foo')
     self.mispevent.add_tag(new_tag)
     with open('tests/mispevent_testfiles/event_tags.json', 'r') as f:
         ref_json = json.load(f)
     self.assertEqual(self.mispevent.to_json(), json.dumps(ref_json, sort_keys=True, indent=2))
Ejemplo n.º 4
0
 def test_event_tag(self):
     self.init_event()
     self.mispevent.add_tag('bar')
     self.mispevent.add_tag(name='baz')
     new_tag = MISPTag()
     new_tag.from_dict(name='foo')
     self.mispevent.add_tag(new_tag)
     with open('tests/mispevent_testfiles/event_tags.json', 'r') as f:
         ref_json = json.load(f)
     self.assertEqual(self.mispevent.to_json(), json.dumps(ref_json, sort_keys=True, indent=2))