<commit_before># -*- coding: utf-8 -*-

import json

from pymisp import MISPEvent, MISPObject

try:
    from onyphe import Onyphe
except ImportError:
    print("pyonyphe module not installed.")

misperrors = {'error': 'Error'}

mispattributes = {'input': ['ip-src', 'ip-dst', 'hostname', 'domain'],
                  'output': ['hostname', 'domain', 'ip-src', 'ip-dst', 'url'],
                  'format': 'misp_standard'}
# possible module-types: 'expansion', 'hover' or both
moduleinfo = {'version': '2', 'author': '<NAME> @sebdraven',
              'description': 'Query on Onyphe',
              'module-type': ['expansion', 'hover']}

# config fields that your code expects from the site admin
moduleconfig = ['apikey']


class OnypheClient:

    def __init__(self, api_key, attribute):
        self.onyphe_client = Onyphe(api_key=api_key)
        self.attribute = attribute
        self.misp_event = MISPEvent()
        self.misp_event.add_attribute(**attribute)

    def get_results(self):
        event = json.loads(self.misp_event.to_json())
        results = {key: event[key] for key in ('Attribute', 'Object') if key in event}
        return results

    def get_query_onyphe(self):
        if self.attribute['type'] == 'ip-src' and self.attribute['type'] =='ip-dst':
            self.__summary_ip()

    def __summary_ip(self):
        results = self.onyphe_client.summary_ip(self.attribute['value'])
        if 'results' in results:
            for r in results['results']:
                domain = r['domain']
                if type(domain) == list:
                    for d in domain:
                        self.__get_object_domain_ip(d, 'domain')
                elif type(domain) == str:
                    self.__get_object_domain_ip(domain, 'domain')
<commit_msg>add logs<commit_after># -*- coding: utf-8 -*-

import json

from pymisp import MISPEvent, MISPObject

try:
    from onyphe import Onyphe
except ImportError:
    print("pyonyphe module not installed.")

misperrors = {'error': 'Error'}

mispattributes = {'input': ['ip-src', 'ip-dst', 'hostname', 'domain'],
                  'output': ['hostname', 'domain', 'ip-src', 'ip-dst', 'url'],
                  'format': 'misp_standard'}
# possible module-types: 'expansion', 'hover' or both
moduleinfo = {'version': '2', 'author': '<NAME> @sebdraven',
              'description': 'Query on Onyphe',
              'module-type': ['expansion', 'hover']}

# config fields that your code expects from the site admin
moduleconfig = ['apikey']


class OnypheClient:

    def __init__(self, api_key, attribute):
        self.onyphe_client = Onyphe(api_key=api_key)
        self.attribute = attribute
        self.misp_event = MISPEvent()
        self.misp_event.add_attribute(**attribute)

    def get_results(self):
        event = json.loads(self.misp_event.to_json())
        results = {key: event[key] for key in ('Attribute', 'Object') if key in event}
        return results

    def get_query_onyphe(self):
        if self.attribute['type'] == 'ip-src' and self.attribute['type'] =='ip-dst':
            self.__summary_ip()

    def __summary_ip(self):
        results = self.onyphe_client.summary_ip(self.attribute['value'])
        if 'results' in results:
            for r in results['results']:
                domain = r['domain']
                print(domain)
                if type(domain) == list:
                    for d in domain:
                        self.__get_object_domain_ip(d, 'domain')
                elif type(domain) == str:
                    self.__get_object_domain_ip(domain, 'domain')

{'fraction_non_alphanumeric': 0.13892747985551543, 'fraction_numerical': 0.0011114198388441233, 'mean_word_length': 2.525954946131244, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2387775', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1069, 'n_words': 276}