How to use the amplify.agent.common.context.context.log.info function in amplify

To help you get started, we’ve selected a few amplify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nginxinc / nginx-amplify-agent / amplify / agent / common / util / configreader.py View on Github external
print("\033[31mAPI key is not specified in %s\033[0m\n" % config_filename)
            print("Write your API key in [credentials][api_key]")
            return 1

        # test logger: get log filename first
        try:
            log_filename = context.default_log.handlers[0].baseFilename
            log_folder = '/'.join(log_filename.split('/')[:-1])
        except:
            print("\033[31mCould not setup log file based on config in %s\033[0m\n" % config_filename)
            print("Please check the file name in [handler_agent-default][args]")
            return 1

        # test logger: the ability to write logs
        try:
            context.log.info('performing configtest check...')
        except:
            current_user = pwd.getpwuid(os.getuid())[0]
            print("\033[31mCould not write to %s\033[0m\n" % log_filename)
            print("Either wrong permissions, or the log directory doesn't exist\n")
            print("The following may help:")
            print("  1. sudo mkdir %s" % log_folder)
            print("  2. sudo touch %s" % log_filename)
            print("  3. sudo chown %s %s" % (current_user, log_filename))
            return 1

        # try to connect to the cloud
        tries = 0
        while tries <= 3:
            tries += 1

            try:
github nginxinc / nginx-amplify-agent / amplify / agent / objects / system / object.py View on Github external
def start(self):
        if not context.cloud_restart and not self.running:
            # fire agent started event (if not in a container)
            if not self.in_container:
                self.eventd.event(
                    level=INFO,
                    message='agent started, version: %s, pid: %s' % (context.version, context.pid),
                    ctime=context.start_time-1  # Make sure that the start event is the first event reported.
                )
            # log agent started event
            context.log.info(
                'agent started, version=%s pid=%s uuid=%s %s=%s' %
                (context.version, context.pid, self.uuid, self.hosttype, getattr(self, self.hosttype))
            )

        super(SystemObject, self).start()
github nginxinc / nginx-amplify-agent / amplify / agent / common / util / configreader.py View on Github external
if wait_for_cloud and tries == 3:
                    print("\033[31mGiving up after three attempts...\033[0m\n")
                    return 1
                elif wait_for_cloud is False:
                    return 1
                else:
                    time.sleep(60)
            else:
                break
    except:
        print("\033[31mSomething failed:\033[0m\n")
        print(traceback.format_exc())
        return 1

    context.log.info('config file is ok!')
    print("\033[32mConfig file %s is OK\033[0m" % config_filename)
    return 0
github nginxinc / nginx-amplify-agent / amplify / agent / supervisor.py View on Github external
name = ''.join([char.lower() for char in name if char.isalpha()])
            context.capabilities[name] = status

        # update special object configs and filters
        changed_object_managers = set()
        matched_object_configs = set()
        for obj in cloud_response.objects:
            object_manager = self.object_managers.get(obj.type)
            if object_manager is None:
                continue

            if obj.id in object_manager.object_configs:
                matched_object_configs.add(obj.id)

            if object_manager.object_configs.get(obj.id, {}) != obj.config:
                context.log.info(
                    'object config has changed. now "%s" %s is running with: %s' %
                    (obj.type, obj.id, pprint.pformat(obj.config))
                )
                object_manager.object_configs[obj.id] = obj.config
                changed_object_managers.add(obj.type)
                matched_object_configs.add(obj.id)

        # purge obsoleted object configs
        for object_type, object_manager in self.object_managers.iteritems():
            for obj_id in object_manager.object_configs.keys():
                if obj_id not in matched_object_configs:
                    context.log.debug(
                        'object config has changed. now "%s" %s is running with default settings' %
                        (object_type, obj_id)
                    )
                    del object_manager.object_configs[obj_id]
github nginxinc / nginx-amplify-agent / amplify / agent / pipelines / syslog.py View on Github external
def __iter__(self):
        if not self.listener and self.listener_setup_attempts < 3:
            try:
                self._setup_listener(**self.kwargs)
                context.log.info(
                    'successfully started listener during "SyslogTail.__iter__()" after %s failed attempt(s)' % (
                        self.listener_setup_attempts
                    )
                )
                self.listener_setup_attempts = 0  # reset attempt counter
            except AmplifyAddresssAlreadyInUse as e:
                if self.listener_setup_attempts < 3:
                    context.log.warning(
                        'failed to start listener during "SyslogTail.__iter__()" due to "%s", '
                        'will try again (attempts: %s)' % (
                            e.__class__.__name__,
                            self.listener_setup_attempts
                        )
                    )
                    context.log.debug('additional info:', exc_info=True)
                else:
github nginxinc / nginx-amplify-agent / amplify / agent / common / util / ssl.py View on Github external
def ssl_analysis(filename):
    """
    Get information about SSL certificates found by NginxConfigParser.

    :param filename: String Path/filename
    :return: Dict Information dict about ssl certificate
    """
    results = dict()

    start_time = time.time()
    context.log.info('ssl certificate found %s' % filename)

    # Check if we can open certificate file
    try:
        cert_handler = open(filename, 'r')
        cert_handler.close()
    except IOError:
        context.log.info('could not read %s (maybe permissions?)' % filename)
        return None

    try:
        # Modified date/time
        results['modified'] = int(os.path.getmtime(filename))

        # Certificate dates
        results['dates'] = certificate_dates(filename)
github nginxinc / nginx-amplify-agent / amplify / ext / mysql / managers.py View on Github external
)
            context.log.debug('additional info:', exc_info=True)

            # If there is a root_object defined, log an event to send to the
            # cloud.
            if context.objects.root_object:
                context.objects.root_object.eventd.event(
                    level=INFO,
                    message='no mysqld processes found'
                )

            # break processing returning a fault-tolerant empty list
            return []

        if not any('mysqld' in line for line in ps):
            context.log.info('no mysqld processes found')

            # break processing returning a fault-tolerant empty list
            return []

        # collect all info about processes
        masters = {}
        try:
            for line in ps:
                parsed = ps_parser(line)

                # if not parsed - go to the next line
                if parsed is None:
                    continue

                pid, ppid, cmd = parsed  # unpack values
github nginxinc / nginx-amplify-agent / amplify / agent / common / util / host.py View on Github external
instance_id = AmazonEC2.instance_id()
        if instance_id:
            result = instance_id

    # fall back on socket.gethostname()
    if result is None:
        try:
            socket_hostname = socket.gethostname()
        except socket.error:
            socket_hostname = None
        if socket_hostname and is_valid_hostname(socket_hostname):
            result = socket_hostname

    if result is None:
        result = "%s-%s" % (os_name(), uuid())
        context.log.info('Unable to determine hostname, auto-generated one: "%s"' % result)

    return result