Esempio n. 1
0
    def start(self):
        """ Starts the monitor activity
        """
        rt = True
        self.remove_monitor_data()

        # Load all system from current_local
        logger.info("Checking for pending updates")
        result, systems = get_systems()
        if not result:
            logger.error("Can't retrieve the system info: %s" % str(systems))
            return False

        pending_updates = False
        for (system_id, system_ip) in systems:
            (success, info) = apimethod_get_update_info(system_id)
            if success:
                try:
                    sys_pending_updates = info['pending_updates']
                    pending_updates = pending_updates or sys_pending_updates
                    logger.info("Pending Updates for system %s (%s): %s" %
                                (system_id, system_ip, sys_pending_updates))
                    monitor_data = {"pending_updates": sys_pending_updates}
                    self.save_data(system_id, ComponentTypes.SYSTEM,
                                   self.get_json_message(monitor_data))
                except Exception as e:
                    logger.error("[MonitorPendingUpdates] Error: %s" % str(e))
                    rt = False
                    break
            else:
                logger.error("MonitorPendingUpdates: %s" % info)
                rt = False
                break

        if pending_updates:
            success, local_ip = get_system_ip_from_local()
            if not success:
                logger.error(
                    "[MonitorPendingUpdates] Unable to get local IP: %s" %
                    local_ip)
                return False

            success, is_pro = get_is_professional(local_ip)
            if success and is_pro:
                success, is_trial = system_is_trial('local')
                if success and is_trial:
                    logger.info(
                        "[MonitorPendingUpdates] Trial version. Skipping download of release info file"
                    )
                    return rt

            success, msg = ansible_download_release_info(local_ip)
            if not success:
                logger.error(
                    "[MonitorPendingUpdates] Unable to retrieve release info file: %s"
                    % msg)
                return False

        return rt
Esempio n. 2
0
    def start(self):
        """ Starts the monitor activity
        """
        rt = True
        self.remove_monitor_data()

        # Load all system from current_local
        logger.info("Checking for pending updates")
        result, systems = get_systems()
        if not result:
            logger.error("Can't retrieve the system info: %s" % str(systems))
            return False

        pending_updates = False
        for (system_id, system_ip) in systems:
            (success, info) = apimethod_get_update_info(system_id)
            if success:
                try:
                    sys_pending_updates = info['pending_updates']
                    pending_updates = pending_updates or sys_pending_updates
                    logger.info("Pending Updates for system %s (%s): %s" % (system_id, system_ip, sys_pending_updates))
                    monitor_data = {"pending_updates": sys_pending_updates}
                    self.save_data(system_id, ComponentTypes.SYSTEM, self.get_json_message(monitor_data))
                except Exception as e:
                    logger.error("[MonitorPendingUpdates] Error: %s" % str(e))
                    rt = False
                    break
            else:
                logger.error("MonitorPendingUpdates: %s" % info)
                rt = False
                break

        if pending_updates:
            success, local_ip = get_system_ip_from_local()
            if not success:
                logger.error("[MonitorPendingUpdates] Unable to get local IP: %s" % local_ip)
                return False

            success, is_pro = get_is_professional(local_ip)
            if success and is_pro:
                success, is_trial = system_is_trial('local')
                if success and is_trial:
                    logger.info("[MonitorPendingUpdates] Trial version. Skipping download of release info file")
                    return rt

            success, msg = ansible_download_release_info(local_ip)
            if not success:
                logger.error("[MonitorPendingUpdates] Unable to retrieve release info file: %s" % msg)
                return False

        return rt
Esempio n. 3
0
def check_plugin_integrity(system_id="local"):
    """
        Check if installed agent plugins and agent rsyslog files have been modified or removed locally
    """
    success, system_ip = get_system_ip_from_system_id(system_id)
    if not success:
        api_log.error(str(system_ip))
        return False, "Error retrieving the system ip for the system id %s -> %s" % (system_ip, str(system_ip))

    success, is_pro = get_is_professional(system_ip)
    if not (success and is_pro):
        return (True, "Skipping plugin integrity check in non professional system")

    success, data = ansible_check_plugin_integrity(system_ip)
    if not success:
        return False, data

    return True, data
Esempio n. 4
0
def check_plugin_integrity(system_id="local"):
    """
        Check if installed agent plugins and agent rsyslog files have been modified or removed locally
    """
    success, system_ip = get_system_ip_from_system_id(system_id)
    if not success:
        api_log.error(str(system_ip))
        return False, "Error retrieving the system ip for the system id %s -> %s" % (system_ip, str(system_ip))

    success, is_pro = get_is_professional(system_ip)
    if not (success and is_pro):
        return (True, "Skipping plugin integrity check in non professional system")

    success, data = ansible_check_plugin_integrity(system_ip)
    if not success:
        return False, data

    return True, data
Esempio n. 5
0
def apimethod_get_pending_packges(system_id, no_cache=False):
    """Retrieves the available updates for the given system_id
       and the release_info file
    Args:
      system_id(str): The system id of which we want to know
                      if it has available updates
    Returns:
      (success,data): success=True when the operation when ok,
                      otherwise success=False.
                      On success data will contain a json object
                      with the updates information.
    """
    success, data = apimethod_get_update_info(system_id, no_cache=no_cache)
    if not success:
        return success, data

    available_updates = data['available_updates']

    if available_updates:

        # Check for release info file
        success, local_ip = get_system_ip_from_local()
        if not success:
            error_msg = "[apimethod_get_pending_packges] " + \
                        "Unable to get local IP: %s" % local_ip
            api_log.error(error_msg)
            return False, available_updates

        success, is_pro = get_is_professional(local_ip)
        if success and is_pro:
            success, is_trial = system_is_trial(system_id='local')
            if success and is_trial:
                info_msg = "[apimethod_get_pending_packges] " + \
                           "Trial version. Skipping download release info file"
                api_log.info(info_msg)
                return True, available_updates

        success, msg = ansible_download_release_info(local_ip)
        if not success:
            error_msg = "[apimethod_get_pending_packges] " + \
                        "Unable to retrieve release info file: %s" % msg
            api_log.error(error_msg)

    return True, available_updates
Esempio n. 6
0
def apimethod_get_pending_packges(system_id, no_cache=False):
    """Retrieves the available updates for the given system_id
       and the release_info file
    Args:
      system_id(str): The system id of which we want to know
                      if it has available updates
    Returns:
      (success,data): success=True when the operation when ok,
                      otherwise success=False.
                      On success data will contain a json object
                      with the updates information.
    """
    success, data = apimethod_get_update_info(system_id, no_cache=no_cache)
    if not success:
        return success, data

    available_updates = data['available_updates']

    if available_updates:

        # Check for release info file
        success, local_ip = get_system_ip_from_local()
        if not success:
            error_msg = "[apimethod_get_pending_packges] " + \
                        "Unable to get local IP: %s" % local_ip
            api_log.error(error_msg)
            return False, available_updates

        success, is_pro = get_is_professional(local_ip)
        if success and is_pro:
            success, is_trial = system_is_trial(system_id='local')
            if success and is_trial:
                info_msg = "[apimethod_get_pending_packges] " + \
                           "Trial version. Skipping download release info file"
                api_log.info(info_msg)
                return True, available_updates

        success, msg = ansible_download_release_info(local_ip)
        if not success:
            error_msg = "[apimethod_get_pending_packges] " + \
                        "Unable to retrieve release info file: %s" % msg
            api_log.error(error_msg)

    return True, available_updates
Esempio n. 7
0
    def start(self):
        """ Starts the monitor activity
        """
        #Remove the previous monitor data.
        self.remove_monitor_data()

        success, local_ip = get_system_ip_from_local(local_loopback=False)
        if not success:
            logger.error("Cannot retrieve local system IP: %s" % str(local_ip))
            return False

        # Check if this is professional or not.
        success, is_pro = get_is_professional(local_ip)
        if not (success and is_pro):
            return True

        # Iterate over the sensors.
        result, systems = get_systems(system_type="Sensor")

        if not result:
            logger.error("Can't retrieve the system info: %s" % str(systems))
            return False

        for (system_id, system_ip) in systems:
            (success, info) = check_plugin_integrity(system_id)

            if success:
                try:
                    #Create the JSON data to store the monitor info
                    monitor_data = info

                    #Save the data to the monitor_data table
                    self.save_data(system_id, ComponentTypes.SENSOR,
                                   self.get_json_message(monitor_data))
                except Exception as e:
                    logger.error("[MonitorPluginIntegrity] Error: %s" % str(e))
            else:
                logger.error(
                    "Can't obtain integrity plugin information from system '%s'",
                    system_id)

        return True
Esempio n. 8
0
    def start(self):
        """ Starts the monitor activity
        """
        #Remove the previous monitor data.
        self.remove_monitor_data()

        success, local_ip = get_system_ip_from_local(local_loopback=False)
        if not success:
            logger.error("Cannot retrieve local system IP: %s" % str(local_ip))
            return False

        # Check if this is professional or not.
        success, is_pro = get_is_professional(local_ip)
        if not (success and is_pro):
            return True

        # Iterate over the sensors.
        result, systems = get_systems(system_type="Sensor")

        if not result:
            logger.error("Can't retrieve the system info: %s" % str(systems))
            return False

        for (system_id, system_ip) in systems:
            (success, info) = check_plugin_integrity(system_id)

            if success:
                try:
                    #Create the JSON data to store the monitor info
                    monitor_data = info

                    #Save the data to the monitor_data table
                    self.save_data(system_id, ComponentTypes.SENSOR, self.get_json_message(monitor_data))
                except Exception as e:
                    logger.error("[MonitorPluginIntegrity] Error: %s" % str(e))
            else:
                logger.error("Can't obtain integrity plugin information from system '%s'", system_id)

        return True