コード例 #1
0
    def delete(self):
        if getattr(self, "api", None) is None:
            self.api = shark_api.SharkAPI()

        self.api.delete_job(self.job_id)
        main.db.session.delete(self)
        main.db.session.commit()
コード例 #2
0
    def __init__(self, name, job_filter, interface, limit, user):
        self.api = shark_api.SharkAPI()
        self.job_name = name
        self.job_filter = job_filter
        self.job_interface = interface
        self.job_limit = limit
        self.job_snapshot_size = 65535  # in bytes, number of packets in the capture
        self.job_status = {}            # stores state, size, start time and end time
        self.user = user
        self.user_notified = False      # used to notify user once when the job is done

        # send post request to api, on return populate id && status
        payload = {
            "name": self.job_name,
            "bpf_filter": self.job_filter,
            "interface_name": self.job_interface,
            "start_immediately": False,
            "snap_length": self.job_snapshot_size,
            "packet_retention": {"size_limit": self.job_limit},
            "stop_rule": {}
        }

        response = self.api.create_job(payload)
        if response.status_code == 201:
            resp = json.loads(response.text)
            self.job_id = resp.get('id')
        else:
            self.error = response
コード例 #3
0
    def get_status(self):
        if getattr(self, "api", None) is None:
            self.api = shark_api.SharkAPI()

        job = self.api.get_job(self.job_id)
        if isinstance(job, requests.Response):
            return job

        return job.get('status')
コード例 #4
0
    def start(self):
        if getattr(self, "api", None) is None:
            self.api = shark_api.SharkAPI()

        self.api.start_job(self.job_id)
コード例 #5
0
    def download(self):
        if getattr(self, "api", None) is None:
            self.api = shark_api.SharkAPI()

        return self.api.download_job(self.job_id)