示例#1
0
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
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)