# Path: canaryd/log.py
# STDOUT_LOG_LEVELS = (logging.DEBUG, logging.INFO)
# STDERR_LOG_LEVELS = (logging.WARNING, logging.ERROR, logging.CRITICAL)
# class LogFilter(logging.Filter):
# class LogFormatter(logging.Formatter):
#     def __init__(self, *levels):
#     def filter(self, record):
#     def format(self, record):
# def setup_logging(verbose, debug, default_level=logging.CRITICAL):
# def setup_logging_from_settings(settings):
# def print_exception(debug_only=False):
# 
# Path: canaryd/subprocess.py
# def ensure_command_tuple(command):
# def decode_output(output):
# def get_command_output(command, *args, **kwargs):


import re
from collections import defaultdict
from os import listdir, path, sep as os_sep
from canaryd.log import logger
from canaryd.subprocess import CalledProcessError, get_command_output
            pid = int(pid)

            # Work out the host:port bit
            host, port = local_address.rsplit(':', 1)
            port = int(port)

            ip_type = 'ipv6' if proto == 'tcp6' else 'ipv4'

            host_port_tuple = (ip_type, host, port)
            PID_TO_PORTS[pid].add(host_port_tuple)
        except ValueError:
            logger.warning('Dodgy netstat line ignored: "{0}"'.format(line))


def get_pid_to_listens(timeout):
    if not HAS_PROCFS:
        return PID_TO_PORTS

    # Loop through the results and cleanup any PIDs that don't exist
    for pid in list(PID_TO_PORTS.keys()):
        if not path.exists('/proc/{0}'.format(pid)):
            PID_TO_PORTS.pop(pid)

    try:
        _get_lsof_pid_to_listens(timeout=timeout)
    except (CalledProcessError, OSError):
        logger.warning('Missing lsof, defaulting to netstat')

        try:
            _get_netstat_pid_to_listens(timeout=timeout)

# Path: canaryd/log.py
# STDOUT_LOG_LEVELS = (logging.DEBUG, logging.INFO)
# STDERR_LOG_LEVELS = (logging.WARNING, logging.ERROR, logging.CRITICAL)
# class LogFilter(logging.Filter):
# class LogFormatter(logging.Formatter):
#     def __init__(self, *levels):
#     def filter(self, record):
#     def format(self, record):
# def setup_logging(verbose, debug, default_level=logging.CRITICAL):
# def setup_logging_from_settings(settings):
# def print_exception(debug_only=False):
# 
# Path: canaryd/subprocess.py
# def ensure_command_tuple(command):
# def decode_output(output):
# def get_command_output(command, *args, **kwargs):


# Path: canaryd/plugins/services_util.py
import re
from collections import defaultdict
from os import listdir, path, sep as os_sep
from canaryd.log import logger
from canaryd.subprocess import CalledProcessError, get_command_output

            pid = int(pid)

            # Work out the host:port bit
            host, port = local_address.rsplit(':', 1)
            port = int(port)

            ip_type = 'ipv6' if proto == 'tcp6' else 'ipv4'

            host_port_tuple = (ip_type, host, port)
            PID_TO_PORTS[pid].add(host_port_tuple)
        except ValueError:
            logger.warning('Dodgy netstat line ignored: "{0}"'.format(line))


def get_pid_to_listens(timeout):
    if not HAS_PROCFS:
        return PID_TO_PORTS

    # Loop through the results and cleanup any PIDs that don't exist
    for pid in list(PID_TO_PORTS.keys()):
        if not path.exists('/proc/{0}'.format(pid)):
            PID_TO_PORTS.pop(pid)

    try:
        _get_lsof_pid_to_listens(timeout=timeout)
    except (CalledProcessError, OSError):
        logger.warning('Missing lsof, defaulting to netstat')

        try:
            _get_netstat_pid_to_listens(timeout=timeout)

        except (CalledProcessError, OSError):