Example #1
0
def add_hids_agent(agent_id,
                   sensor_id,
                   agent_name,
                   agent_ip,
                   agent_status,
                   host_id=None):
    """ Add a new HIDS agent

    Raises:
        APICannotResolveSensorID
        APIInvalidHIDSAgentID
        APICannotAddHIDSAgent
    """

    if sensor_id is None:
        api_log.error("[add_hids_agent]: Sensor ID could not be empty")
        raise APICannotResolveSensorID(sensor_id)

    if agent_id is None:
        api_log.error("[add_hids_agent]: Agent ID could not be empty")
        raise APIInvalidHIDSAgentID(agent_id)

    try:
        db.session.begin()

        sensor_id_bin = get_bytes_from_uuid(sensor_id)

        if host_id:
            hex_id_bin = get_bytes_from_uuid(host_id)
        else:
            hex_id_bin = None

        status_integer = Hids_Agents.get_status_integer_from_string(
            agent_status)

        hids_agent = Hids_Agents()
        hids_agent.agent_id = agent_id
        hids_agent.sensor_id = sensor_id_bin
        hids_agent.agent_name = agent_name
        hids_agent.agent_ip = agent_ip
        hids_agent.agent_status = status_integer
        hids_agent.host_id = hex_id_bin

        db.session.merge(hids_agent)
        db.session.commit()
    except Exception as msg:
        db.session.rollback()
        api_log.error("[add_hids_agent]: %s" % str(msg))
        raise APICannotAddHIDSAgent(agent_id, sensor_id)
Example #2
0
def add_hids_agent(agent_id, sensor_id, agent_name, agent_ip, agent_status, host_id=None):
    """ Add a new HIDS agent

    Raises:
        APICannotResolveSensorID
        APIInvalidHIDSAgentID
        APICannotAddHIDSAgent
    """

    if sensor_id is None:
        api_log.error("[add_hids_agent]: Sensor ID could not be empty")
        raise APICannotResolveSensorID(sensor_id)

    if agent_id is None:
        api_log.error("[add_hids_agent]: Agent ID could not be empty")
        raise APIInvalidHIDSAgentID(agent_id)

    try:
        db.session.begin()

        sensor_id_bin = get_bytes_from_uuid(sensor_id)

        if host_id:
            hex_id_bin = get_bytes_from_uuid(host_id)
        else:
            hex_id_bin = None

        status_integer = Hids_Agents.get_status_integer_from_string(agent_status)

        hids_agent = Hids_Agents()
        hids_agent.agent_id = agent_id
        hids_agent.sensor_id = sensor_id_bin
        hids_agent.agent_name = agent_name
        hids_agent.agent_ip = agent_ip
        hids_agent.agent_status = status_integer
        hids_agent.host_id = hex_id_bin

        db.session.merge(hids_agent)
        db.session.commit()
    except Exception as msg:
        db.session.rollback()
        api_log.error("[add_hids_agent]: %s" % str(msg))
        raise APICannotAddHIDSAgent(agent_id, sensor_id)