<commit_before>import sys
import os
import cPickle
import json

import mozdef_client as mozdef

def mozdef_proc(escdir, mozdef_compliance_url, mozdef_vuln_url):
    escfiles = os.listdir(escdir)

    escfiles = sorted(escfiles, key=lambda x: x.split('-')[1])

    for i in escfiles:
        p = os.path.join(escdir, i)
        fd = open(p, 'r')
        events = cPickle.load(fd)
        fd.close()

        if 'vulns' in i:
            summary = 'vmintgr-vulnerability'
            tags = ['vmintgr', 'vulnerability']
            msg = mozdef.MozDefMsg(mozdef_vuln_url, summary, tags)
            msg.fire_and_forget_mode = False
            for j in events:
                d = json.loads(j)
                msg.send_event(summary, tags, details=d)
        elif 'compliance' in i:
            msg = mozdef.MozDefMsg(mozdef_compliance_url)
            msg.fire_and_forget_mode = False
            for j in events:
                d = json.loads(j)
                msg.send_compliance(d['target'], d['policy'],
                    d['check'], d['compliance'], d['link'])

        os.remove(p)<commit_msg>send custom vulnerability events with mozdef_client<commit_after>import sys
import os
import cPickle
import json

import mozdef_client as mozdef

def mozdef_proc(escdir, mozdef_compliance_url, mozdef_vuln_url):
    escfiles = os.listdir(escdir)

    escfiles = sorted(escfiles, key=lambda x: x.split('-')[1])

    for i in escfiles:
        p = os.path.join(escdir, i)
        fd = open(p, 'r')
        events = cPickle.load(fd)
        fd.close()

        if 'vulns' in i:
            msg = mozdef.MozDefMsg(mozdef_vuln_url)
            msg.fire_and_forget_mode = False
            for j in events:
                d = json.loads(j)
                msg.send_vulnerability(d)
        elif 'compliance' in i:
            msg = mozdef.MozDefMsg(mozdef_compliance_url)
            msg.fire_and_forget_mode = False
            for j in events:
                d = json.loads(j)
                msg.send_compliance(d['target'], d['policy'],
                    d['check'], d['compliance'], d['link'])

        os.remove(p)
{'fraction_non_alphanumeric': 0.1089622641509434, 'fraction_numerical': 0.0009433962264150943, 'mean_word_length': 2.0474137931034484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7211477', 'n_tokens_mistral': 749, 'n_tokens_neox': 714, 'n_words': 155}