コード例 #1
0
ファイル: agents.py プロジェクト: ttysteale/vFense
def get_agent_info(agent_id, keys_to_pluck=None):
    """Retrieve agent information.
    Args:
        agent_id (str): 36 character uuid of the agent you are updating.

    Kwargs:
        keys_to_pluck (list, optional): List of specific keys that
        you are retrieving from the database.

    Basic Usage::
        >>> from vFense.core.agent.agents import get_agent_info
        >>> agent_id = '52faa1db-290a-47a7-a4cf-e4ad70e25c38'
        >>> keys_to_pluck = ['production_level', 'needs_reboot']
        >>> get_agent_info(agent_id, keys_to_pluck)
        {
            u'agent_id': u'52faa1db-290a-47a7-a4cf-e4ad70e25c38',
            u'production_level': u'Development'
        }
    """

    return fetch_agent_info(agent_id, keys_to_pluck)
コード例 #2
0
ファイル: agents.py プロジェクト: vFense/vFense
def get_agent_info(agent_id, keys_to_pluck=None):
    """Retrieve agent information.
    Args:
        agent_id (str): 36 character uuid of the agent you are updating.

    Kwargs:
        keys_to_pluck (list, optional): List of specific keys that
        you are retrieving from the database.

    Basic Usage::
        >>> from vFense.core.agent.agents import get_agent_info
        >>> agent_id = '52faa1db-290a-47a7-a4cf-e4ad70e25c38'
        >>> keys_to_pluck = ['production_level', 'needs_reboot']
        >>> get_agent_info(agent_id, keys_to_pluck)
        {
            u'agent_id': u'52faa1db-290a-47a7-a4cf-e4ad70e25c38',
            u'production_level': u'Development'
        }
    """

    return fetch_agent_info(agent_id, keys_to_pluck)
コード例 #3
0
ファイル: agents.py プロジェクト: ttysteale/vFense
def update_agent(agent_id, system_info, hardware, rebooted, username=None, customer_name=None, uri=None, method=None):
    """Update various aspects of agent
    Args:
        agent_id (str): 36 character uuid of the agent you are updating
        system_info (dict): Dictionary with system related info
        hardware (dict):  List of dictionaries that rpresent the hardware
        rebooted (str): yes or no

    Kwargs:
        user_name (str): The name of the user who called this function.
        customer_name (str): The name of the customer.
        uri (str): The uri that was used to call this function.
        method (str): The HTTP methos that was used to call this function.
    """
    results = {ApiResultKeys.USERNAME: username, ApiResultKeys.URI: uri, ApiResultKeys.HTTP_METHOD: method}
    agent_data = {}
    try:
        now = time()
        agent_orig_info = fetch_agent_info(agent_id)
        if agent_orig_info:
            agent_data[AgentKey.Hardware] = hardware

            for key, value in system_info.items():
                agent_data[key] = value

            agent_data[AgentKey.LastAgentUpdate] = DbTime.epoch_time_to_db_time(now)
            agent_data[AgentKey.HostName] = agent_orig_info.get(AgentKey.HostName, None)
            agent_data[AgentKey.DisplayName] = agent_orig_info.get(AgentKey.DisplayName, None)

            if rebooted == CommonKeys.YES:
                agent_data[AgentKey.NeedsReboot] = CommonKeys.NO

            status_code, count, error, generated_ids = update_agent_data(agent_id, agent_data)

            if status_code == DbCodes.Replaced and count > 0:
                Hardware().add(agent_id, hardware)
                msg = "agent %s updated successfully." % (agent_id)

                results[ApiResultKeys.GENERIC_STATUS_CODE] = GenericCodes.ObjectUpdated
                results[ApiResultKeys.VFENSE_STATUS_CODE] = AgentResultCodes.ResultsUpdated
                results[ApiResultKeys.MESSAGE] = msg
                results[ApiResultKeys.DATA] = [agent_data]
                results[ApiResultKeys.UPDATED_IDS] = [agent_id]

            elif status_code == DbCodes.Unchanged:
                Hardware().add(agent_id, hardware)
                msg = "agent %s unchanged, data is the same." % (agent_id)

                results[ApiResultKeys.GENERIC_STATUS_CODE] = GenericCodes.ObjectUnchanged
                results[ApiResultKeys.VFENSE_STATUS_CODE] = AgentResultCodes.ResultsUpdated
                results[ApiResultKeys.MESSAGE] = msg
                results[ApiResultKeys.DATA] = [agent_data]
                results[ApiResultKeys.UNCHANGED_IDS] = [agent_id]

            elif status_code == DbCodes.Skipped:
                msg = "agent %s does not exist." % (agent_id)

                results[ApiResultKeys.GENERIC_STATUS_CODE] = GenericFailureCodes.InvalidId
                results[ApiResultKeys.VFENSE_STATUS_CODE] = AgentFailureCodes.AgentsDoesNotExist
                results[ApiResultKeys.MESSAGE] = msg
                results[ApiResultKeys.DATA] = [agent_data]

            elif status_code == DbCodes.Errors:
                msg = "operation failed" % (error)

                results[ApiResultKeys.GENERIC_STATUS_CODE] = GenericFailureCodes.FailedToUpdateObject
                results[ApiResultKeys.VFENSE_STATUS_CODE] = AgentFailureResultCodes.ResultsFailedToUpdate
                results[ApiResultKeys.MESSAGE] = msg

        else:
            msg = "agent %s does not exist." % (agent_id)

            results[ApiResultKeys.GENERIC_STATUS_CODE] = GenericFailureCodes.InvalidId
            results[ApiResultKeys.VFENSE_STATUS_CODE] = AgentFailureCodes.AgentsDoesNotExist
            results[ApiResultKeys.MESSAGE] = msg
            results[ApiResultKeys.DATA] = [agent_data]

    except Exception as e:
        logger.exception(e)
        msg = "operation failed" % (error)

        results[ApiResultKeys.GENERIC_STATUS_CODE] = GenericFailureCodes.FailedToUpdateObject
        results[ApiResultKeys.VFENSE_STATUS_CODE] = AgentFailureResultCodes.ResultsFailedToUpdate
        results[ApiResultKeys.MESSAGE] = msg

    return results
コード例 #4
0
ファイル: agents.py プロジェクト: vFense/vFense
def update_agent(agent_id,
                 system_info,
                 hardware,
                 rebooted,
                 username=None,
                 customer_name=None,
                 uri=None,
                 method=None):
    """Update various aspects of agent
    Args:
        agent_id (str): 36 character uuid of the agent you are updating
        system_info (dict): Dictionary with system related info
        hardware (dict):  List of dictionaries that rpresent the hardware
        rebooted (str): yes or no

    Kwargs:
        user_name (str): The name of the user who called this function.
        customer_name (str): The name of the customer.
        uri (str): The uri that was used to call this function.
        method (str): The HTTP methos that was used to call this function.
    """
    results = {
        ApiResultKeys.USERNAME: username,
        ApiResultKeys.URI: uri,
        ApiResultKeys.HTTP_METHOD: method
    }
    agent_data = {}
    try:
        now = time()
        agent_orig_info = fetch_agent_info(agent_id)
        if agent_orig_info:
            agent_data[AgentKey.Hardware] = hardware

            for key, value in system_info.items():
                agent_data[key] = value

            agent_data[AgentKey.LastAgentUpdate] = (
                DbTime.epoch_time_to_db_time(now))
            agent_data[AgentKey.HostName] = (agent_orig_info.get(
                AgentKey.HostName, None))
            agent_data[AgentKey.DisplayName] = (agent_orig_info.get(
                AgentKey.DisplayName, None))

            if rebooted == CommonKeys.YES:
                agent_data[AgentKey.NeedsReboot] = CommonKeys.NO

            status_code, count, error, generated_ids = (update_agent_data(
                agent_id, agent_data))

            if status_code == DbCodes.Replaced and count > 0:
                Hardware().add(agent_id, hardware)
                msg = 'agent %s updated successfully.' % (agent_id)

                results[ApiResultKeys.GENERIC_STATUS_CODE] = \
                    GenericCodes.ObjectUpdated
                results[ApiResultKeys.VFENSE_STATUS_CODE] = \
                    AgentResultCodes.ResultsUpdated
                results[ApiResultKeys.MESSAGE] = msg
                results[ApiResultKeys.DATA] = [agent_data]
                results[ApiResultKeys.UPDATED_IDS] = [agent_id]

            elif status_code == DbCodes.Unchanged:
                Hardware().add(agent_id, hardware)
                msg = 'agent %s unchanged, data is the same.' % (agent_id)

                results[ApiResultKeys.GENERIC_STATUS_CODE] = \
                    GenericCodes.ObjectUnchanged
                results[ApiResultKeys.VFENSE_STATUS_CODE] = \
                    AgentResultCodes.ResultsUpdated
                results[ApiResultKeys.MESSAGE] = msg
                results[ApiResultKeys.DATA] = [agent_data]
                results[ApiResultKeys.UNCHANGED_IDS] = [agent_id]

            elif status_code == DbCodes.Skipped:
                msg = 'agent %s does not exist.' % (agent_id)

                results[ApiResultKeys.GENERIC_STATUS_CODE] = \
                    GenericFailureCodes.InvalidId
                results[ApiResultKeys.VFENSE_STATUS_CODE] = \
                    AgentFailureCodes.AgentsDoesNotExist
                results[ApiResultKeys.MESSAGE] = msg
                results[ApiResultKeys.DATA] = [agent_data]

            elif status_code == DbCodes.Errors:
                msg = 'operation failed' % (error)

                results[ApiResultKeys.GENERIC_STATUS_CODE] = \
                    GenericFailureCodes.FailedToUpdateObject
                results[ApiResultKeys.VFENSE_STATUS_CODE] = \
                    AgentFailureResultCodes.ResultsFailedToUpdate
                results[ApiResultKeys.MESSAGE] = msg

        else:
            msg = 'agent %s does not exist.' % (agent_id)

            results[ApiResultKeys.GENERIC_STATUS_CODE] = \
                    GenericFailureCodes.InvalidId
            results[ApiResultKeys.VFENSE_STATUS_CODE] = \
                    AgentFailureCodes.AgentsDoesNotExist
            results[ApiResultKeys.MESSAGE] = msg
            results[ApiResultKeys.DATA] = [agent_data]

    except Exception as e:
        logger.exception(e)
        msg = 'operation failed' % (error)

        results[ApiResultKeys.GENERIC_STATUS_CODE] = \
            GenericFailureCodes.FailedToUpdateObject
        results[ApiResultKeys.VFENSE_STATUS_CODE] = \
            AgentFailureResultCodes.ResultsFailedToUpdate
        results[ApiResultKeys.MESSAGE] = msg

    return results