コード例 #1
0
ファイル: setup.py プロジェクト: UWICompSociety/infoset
def insert_agent_host():
    """Insert first agent and host in the database.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    idx_agent = 1
    idx_host = 1
    agent_name = '_infoset'
    config = jm_configuration.ConfigAgent(agent_name)

    # Add agent
    if db_agent.idx_exists(idx_agent) is False:
        # Generate a UID and add a record in the database
        uid = agent.get_uid(config)

    # Add host
    if db_host.idx_exists(idx_host) is False:
        record = Host(
            description=jm_general.encode('Infoset Server'),
            hostname=jm_general.encode(socket.getfqdn()))
        database = db.Database()
        database.add(record, 1106)

    # Add to Agent / Host table
    if db_hostagent.host_agent_exists(idx_host, idx_agent) is False:
        record = HostAgent(idx_host=idx_host, idx_agent=idx_agent)
        database = db.Database()
        database.add(record, 1107)
コード例 #2
0
ファイル: cache.py プロジェクト: Pr0x1m4/infoset
    def _insert_host(self):
        """Insert new agent into database.

        Args:
            None

        Returns:
            None

        """
        # Initialize key variables
        uid = self.ingest.uid()
        hostname = self.ingest.hostname()

        # Update Host table
        if dhost.hostname_exists(hostname) is False:
            # Add to Host table
            record = Host(hostname=jm_general.encode(hostname))
            database = db.Database()
            database.add(record, 1080)

        # Get idx of host
        host_info = dhost.GetHost(hostname)
        idx_host = host_info.idx()

        # Get idx of agent
        uid_info = agent.GetUID(uid)
        idx_agent = uid_info.idx()

        # Update HostAgent table
        if hagent.host_agent_exists(idx_host, idx_agent) is False:
            # Add to HostAgent table
            record = HostAgent(idx_host=idx_host, idx_agent=idx_agent)
            database = db.Database()
            database.add(record, 1038)
コード例 #3
0
ファイル: validate.py プロジェクト: UWICompSociety/infoset
def _check_duplicates(information):
    """Check whether reported data reported is already in the database.

    Args:
        None

    Returns:
        valid: True if valid

    """
    # Initialize key variables
    valid = True

    # Check that we are evaluating a dict
    if isinstance(information, dict) is False:
        log_message = ('Ingest data is not a dictionary')
        log.log2warn(1116, log_message)
        valid = False
        return valid

    # Check that we have the correct keys in the dict
    if _check_primary_keys_exist(information) is False:
        valid = False
        return valid

    # Get values
    timestamp = int(information['timestamp'])
    uid = information['uid']
    hostname = information['hostname']

    # Check if there is a duplicate entry for this UID
    if db_agent.uid_exists(uid) is not False:
        idx_agent = db_agent.GetUID(uid).idx()

        # Check if host exists
        if db_host.hostname_exists(hostname) is True:
            idx_host = db_host.GetHost(hostname).idx()

            # Check for host / agent entry existence
            if db_hostagent.host_agent_exists(
                    idx_host, idx_agent) is True:
                # Check if this host / agent has been updated before
                last_timesamp = db_hostagent.GetHostAgent(
                    idx_host, idx_agent).last_timestamp()

                # Validate
                if timestamp <= last_timesamp:
                    log_message = (
                        'Data for UID %s, hostname %s at timestamp %s '
                        'is already found in database.'
                        '') % (uid, hostname, timestamp)
                    log.log2warn(1113, log_message)
                    valid = False

    # Return
    return valid
コード例 #4
0
ファイル: install.py プロジェクト: Pr0x1m4/infoset
def insert_agent_host():
    """Insert first agent and host in the database.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    idx_agent = 1
    idx_host = 1
    agent_name = '_infoset'

    # Add agent
    if db_agent.idx_exists(idx_agent) is False:
        record = Agent(
            id=jm_general.encode('_SYSTEM_RESERVED_'),
            name=jm_general.encode(agent_name))
        database = db.Database()
        database.add(record, 1109)

        # Generate a UID
        uid = agent.get_uid(agent_name)
        database = db.Database()
        session = database.session()
        record = session.query(Agent).filter(Agent.idx == idx_agent).one()
        record.id = jm_general.encode(uid)
        database.commit(session, 1073)

    # Add host
    if db_host.idx_exists(idx_host) is False:
        record = Host(
            description=jm_general.encode('Infoset Server'),
            hostname=jm_general.encode(socket.getfqdn()))
        database = db.Database()
        database.add(record, 1106)

    # Add to Agent / Host table
    if db_hostagent.host_agent_exists(idx_host, idx_agent) is False:
        record = HostAgent(idx_host=idx_host, idx_agent=idx_agent)
        database = db.Database()
        database.add(record, 1107)
コード例 #5
0
ファイル: validate.py プロジェクト: Pr0x1m4/infoset
    def _check_duplicates(self):
        """Method initializing the class.

        Args:
            None

        Returns:
            valid: True if valid

        """
        # Initialize key variables
        valid = True

        # Get values
        timestamp = int(self.information['timestamp'])
        uid = self.information['uid']
        hostname = self.information['hostname']

        # Check if there is a duplicate entry for this UID
        if db_agent.uid_exists(uid) is not False:
            idx_agent = db_agent.GetUID(uid).idx()

            # Check if host exists
            if db_host.hostname_exists(hostname) is True:
                idx_host = db_host.GetHost(hostname).idx()

                # Check for host / agent entry existence
                if db_hostagent.host_agent_exists(
                        idx_host, idx_agent) is True:
                    # Check if this host / agent has been updated before
                    last_timesamp = db_hostagent.GetIDX(
                        idx_host, idx_agent).last_timestamp()

                    # Validate
                    if timestamp <= last_timesamp:
                        valid = False

        # Return
        return valid