Example #1
0
 def __init__(self, username, customer_name, agent_id, os_code, os_string):
     self.username = username
     self.agent_id = agent_id
     self.customer_name = customer_name
     self.os_code = os_code
     self.os_string = os_string
     self.inserted_count = 0
     self.updated_count = 0
     self.modified_time = DbTime.time_now()
Example #2
0
    def __init__(self,
                 username,
                 agent_id,
                 operation_id,
                 success,
                 error=None,
                 status_code=None,
                 uri=None,
                 method=None):
        """
        Args:
            username (str): The name of the user who made this api call
            agent_id (str): 36 character UUID of the agent.
            operation_id (str): 36 character UUID of the operation.
            success (str): true or false.

        Kwargs:
            error (str): The error message, if the operation failed.
            status_code (int): The exact status of this operation.
            uri (str): The uri which was called for the results.
            method (str): The method used to call this api.

        Basic Usage:
            >>> from vFense.operations.results import OperationResults
            >>> username = '******'
            >>> operation_id = '8fed3dc7-33d4-4278-9bd4-398a68bf7f22'
            >>> agent_id = 'db6bf07-c5da-4494-93bb-109db205ca64'
            >>> success = 'true'
            >>> results = OperationResults(
                    username, agent_id, operation_id, success
                )
        """

        self.agent_id = agent_id
        self.operation_id = operation_id
        self.username = username
        self.uri = uri
        self.method = method
        self.agent_data = get_agent_info(self.agent_id)
        self.operation_data = get_agent_operation(self.operation_id)
        self.customer_name = self.agent_data[AgentKey.CustomerName]
        self.date_now = DbTime.time_now()
        self.begining_of_time = DbTime.begining_of_time()
        self.error = error
        self.success = success
        self.status_code = status_code
        self.operation = (AgentOperation(
            self.username,
            self.customer_name,
        ))
Example #3
0
    def __init__(
            self, username, agent_id, operation_id,
            success, error=None, status_code=None,
            uri=None, method=None
        ):
        """
        Args:
            username (str): The name of the user who made this api call
            agent_id (str): 36 character UUID of the agent.
            operation_id (str): 36 character UUID of the operation.
            success (str): true or false.

        Kwargs:
            error (str): The error message, if the operation failed.
            status_code (int): The exact status of this operation.
            uri (str): The uri which was called for the results.
            method (str): The method used to call this api.

        Basic Usage:
            >>> from vFense.operations.results import OperationResults
            >>> username = '******'
            >>> operation_id = '8fed3dc7-33d4-4278-9bd4-398a68bf7f22'
            >>> agent_id = 'db6bf07-c5da-4494-93bb-109db205ca64'
            >>> success = 'true'
            >>> results = OperationResults(
                    username, agent_id, operation_id, success
                )
        """

        self.agent_id = agent_id
        self.operation_id = operation_id
        self.username = username
        self.uri = uri
        self.method = method
        self.agent_data = get_agent_info(self.agent_id)
        self.operation_data = get_agent_operation(self.operation_id)
        self.customer_name = self.agent_data[AgentKey.CustomerName]
        self.date_now = DbTime.time_now()
        self.begining_of_time = DbTime.begining_of_time()
        self.error = error
        self.success = success
        self.status_code = status_code
        self.operation = (
            AgentOperation(
                self.username, self.customer_name,
            )
        )
Example #4
0
    def __init__(self, username, customer_name):
        """
        Args:
            username (str): the name of the user who created the operation.
            customer_name (str): the name of the customer this user is part of.

        Basic Usage:
            >>> from vFense.operations.agent_operations import AgentOperation
            >>> username = '******'
            >>> customer_name = 'default'
            >>> oper = AgentOperation(username, customer_name)
        """
        self.username = username
        self.customer_name = customer_name
        self.now = mktime(datetime.now().timetuple())
        self.db_time = DbTime.time_now()
        self.INIT_COUNT = 0
Example #5
0
def add_or_update_apps_per_agent(agent_id, app_dict_list, now=None,
        delete_afterwards=True, collection=AppCollections.AppsPerAgent):

    """Add or update apps for an agent.

    Args:
        agent_id (str): The 36 character UUID of the agent.
        app_dict_list (list): List of dictionaries.

    Kwargs:
        now (float|int): The time in epoch
            default = None
        collection (str): The name of the collection this is applied too.
            default = apps_per_agent

    Basic Usage:
        >>> from vFense.plugins.patching._db import add_or_update_apps_per_agent
        >>> collection = 'apps_per_agent'
        >>> now = 1399075090.83746
        >>> agent_id = '78211125-3c1e-476a-98b6-ea7f683142b3'
        >>> delete_unused_apps = True
        >>> app_dict_list = [
                {
                    "status": "installed",
                    "install_date": 1397697799,
                    "app_id": "c71c32209119ad585dd77e67c082f57f1d18395763a5fb5728c02631d511df5c",
                    "update": 5014,
                    "dependencies": [],
                    "agent_id": "78211125-3c1e-476a-98b6-ea7f683142b3",
                    "last_modified_time": 1398997520,
                    "id": "000182347981c7b54577817fd93aa6cab39477c6dc59fd2dd8ba32e15914b28f",
                    "customer_name": "default"
                }
            ]
        >>> add_or_update_apps_per_agent(
                app_dict_list, now,
                delete_unused_apps,
                collection
            )

    Returns:
        Tuple
        >>> (insert_count, updated_count, deleted_count)

    """
    updated = 0
    inserted = 0
    deleted = 0

    status_code, count, _, _ = (
        update_apps_per_agent(app_dict_list, collection)
    )

    if isinstance(count, list):
        if len(count) > 1:
            inserted = count[0]
            updated = count[1]

    else:
        if status_code == DbCodes.Replaced:
            updated = count
        elif status_code == DbCodes.Inserted:
            inserted = count

    if delete_afterwards:
        if not now:
            now = DbTime.time_now()
        else:
            if isinstance(now, float) or isinstance(now, int):
                now = DbTime.epoch_time_to_db_time(now)

        status_code, count, _, _ = (
            delete_apps_per_agent_older_than(agent_id, now, collection)
        )

        deleted = count

    return inserted, updated, deleted