def update_hids_agent_status(agent_id, sensor_id, agent_status): """ Update status of HIDS agent Raises: APICannotResolveSensorID APIInvalidHIDSAgentID APICannotUpdateHIDSAgent """ if sensor_id is None: api_log.error("[update_hids_agent_status]: Sensor ID could not be empty") raise APICannotResolveSensorID(sensor_id) if agent_id is None: api_log.error("[update_hids_agent_status]: Agent ID could not be empty") raise APIInvalidHIDSAgentID(agent_id) try: sensor_id_bin = get_bytes_from_uuid(sensor_id) status_integer = Hids_Agents.get_status_integer_from_string(agent_status) db.session.query(Hids_Agents).filter( and_(Hids_Agents.agent_id == agent_id, Hids_Agents.sensor_id == sensor_id_bin)).update({"agent_status": status_integer}) except Exception as msg: api_log.error("[update_hids_agent_status]: %s" % str(msg)) raise APICannotUpdateHIDSAgent(agent_id, sensor_id)
def update_hids_agent_status(agent_id, sensor_id, agent_status): """ Update status of HIDS agent Raises: APICannotResolveSensorID APIInvalidHIDSAgentID APICannotUpdateHIDSAgent """ if sensor_id is None: api_log.error( "[update_hids_agent_status]: Sensor ID could not be empty") raise APICannotResolveSensorID(sensor_id) if agent_id is None: api_log.error( "[update_hids_agent_status]: Agent ID could not be empty") raise APIInvalidHIDSAgentID(agent_id) try: sensor_id_bin = get_bytes_from_uuid(sensor_id) status_integer = Hids_Agents.get_status_integer_from_string( agent_status) db.session.begin() db.session.query(Hids_Agents).filter( and_(Hids_Agents.agent_id == agent_id, Hids_Agents.sensor_id == sensor_id_bin)).update( {"agent_status": status_integer}) db.session.commit() except Exception as msg: db.session.rollback() api_log.error("[update_hids_agent_status]: %s" % str(msg)) raise APICannotUpdateHIDSAgent(agent_id, sensor_id)
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)
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)