def test_getFeatureWideSinksFromLadCfg(self):
     self.assertEqual(
         LadUtil.getFeatureWideSinksFromLadCfg(self.valid_config,
                                               'syslogEvents'), ['sink2'])
     self.assertEqual(
         LadUtil.getFeatureWideSinksFromLadCfg(self.valid_config,
                                               'performanceCounters'),
         ['sink1'])
Beispiel #2
0
    def _update_metric_collection_settings(self, ladCfg):
        """
        Update mdsd_config_xml_tree for Azure Portal metric collection. The mdsdCfg performanceCounters element contains
        an array of metric definitions; this method passes each definition to its provider's AddMetric method, which is
        responsible for configuring the provider to deliver the metric to mdsd and for updating the mdsd config as
        required to expect the metric to arrive. This method also builds the necessary aggregation queries (from the
        metrics.metricAggregation array) that grind the ingested data and push it to the WADmetric table.
        :param ladCfg: ladCfg object from extension config
        :return: None
        """
        metrics = LadUtil.getPerformanceCounterCfgFromLadCfg(ladCfg)
        if not metrics:
            return

        counter_to_table = {}
        local_tables = set()

        # Add each metric
        for metric in metrics:
            if metric['type'] == 'builtin':
                local_table_name = BuiltIn.AddMetric(metric)
                if local_table_name:
                    local_tables.add(local_table_name)
                    counter_to_table[
                        metric['counterSpecifier']] = local_table_name

        # Finalize; update the mdsd config to be prepared to receive the metrics
        BuiltIn.UpdateXML(self._mdsd_config_xml_tree)

        # Aggregation is done by <LADQuery> within a <DerivedEvent>. If there are no alternate sinks, the DerivedQuery
        # can send output directly to the WAD metrics table. If there *are* alternate sinks, have the LADQuery send
        # output to a new local table, then arrange for additional derived queries to pull from that.
        intervals = LadUtil.getAggregationPeriodsFromLadCfg(ladCfg)
        sinks = LadUtil.getFeatureWideSinksFromLadCfg(ladCfg,
                                                      'performanceCounters')
        for table_name in local_tables:
            for aggregation_interval in intervals:
                if sinks:
                    local_table_name = ProvUtil.MakeUniqueEventName(
                        'aggregationLocal')
                    self._add_derived_event(aggregation_interval,
                                            table_name,
                                            local_table_name,
                                            'Local',
                                            add_lad_query=True)
                    self._handle_alternate_sinks(aggregation_interval, sinks,
                                                 local_table_name)
                else:
                    self._add_derived_event(
                        aggregation_interval,
                        table_name,
                        LadConfigAll._wad_table_name(aggregation_interval),
                        'Central',
                        add_lad_query=True)
def create_core_components_configs():
    """
    Entry point to creating all configs of LAD's core components (mdsd, omsagent, rsyslog/syslog-ng, ...).
    This function shouldn't be called on Install/Enable. Only Daemon op needs to call this.
    :rtype: LadConfigAll
    :return: A valid LadConfigAll object if config is valid. None otherwise.
    """
    deployment_id = get_deployment_id_from_hosting_env_cfg(
        waagent.LibDir, hutil.log, hutil.error)

    # Define wrappers around a couple misc_helpers. These can easily be mocked out in tests. PEP-8 says use
    # def, don't assign a lambda to a variable. *shrug*
    def encrypt_string(cert, secret):
        return encrypt_secret_with_cert(RunGetOutput, hutil.error, cert,
                                        secret)

    configurator = lad_cfg.LadConfigAll(g_ext_settings, g_ext_dir,
                                        waagent.LibDir, deployment_id,
                                        read_uuid, encrypt_string, hutil.log,
                                        hutil.error)
    try:
        config_valid, config_invalid_reason = configurator.generate_all_configs(
        )
    except Exception as e:
        config_invalid_reason =\
            'Exception while generating configs: {0}. Traceback: {1}'.format(e, traceback.format_exc())
        hutil.error(config_invalid_reason)
        config_valid = False

    if not config_valid:
        g_lad_log_helper.log_and_report_failed_config_generation(
            g_ext_op_type, config_invalid_reason,
            g_ext_settings.redacted_handler_settings())
        return None

    global enable_metrics_ext
    ladconfig = configurator._ladCfg()
    sinks = LadUtil.getFeatureWideSinksFromLadCfg(ladconfig,
                                                  'performanceCounters')
    for name in sinks:
        sink = configurator._sink_configs.get_sink_by_name(name)
        if sink is not None:
            if sink['name'] == 'AzMonSink':
                enable_metrics_ext = True

    return configurator
    def _update_metric_collection_settings(self, ladCfg):
        """
        Update mdsd_config_xml_tree for Azure Portal metric collection. The mdsdCfg performanceCounters element contains
        an array of metric definitions; this method passes each definition to its provider's AddMetric method, which is
        responsible for configuring the provider to deliver the metric to mdsd and for updating the mdsd config as
        required to expect the metric to arrive. This method also builds the necessary aggregation queries (from the
        metrics.metricAggregation array) that grind the ingested data and push it to the WADmetric table.
        :param ladCfg: ladCfg object from extension config
        :return: None
        """
        metrics = LadUtil.getPerformanceCounterCfgFromLadCfg(ladCfg)
        if not metrics:
            return

        counter_to_table = {}
        local_tables = set()

        # Add each metric
        for metric in metrics:
            if metric['type'] == 'builtin':
                local_table_name = BuiltIn.AddMetric(metric)
                if local_table_name:
                    local_tables.add(local_table_name)
                    counter_to_table[metric['counterSpecifier']] = local_table_name

        # Finalize; update the mdsd config to be prepared to receive the metrics
        BuiltIn.UpdateXML(self._mdsd_config_xml_tree)

        # Aggregation is done by <LADQuery> within a <DerivedEvent>. If there are no alternate sinks, the DerivedQuery
        # can send output directly to the WAD metrics table. If there *are* alternate sinks, have the LADQuery send
        # output to a new local table, then arrange for additional derived queries to pull from that.
        intervals = LadUtil.getAggregationPeriodsFromLadCfg(ladCfg)
        sinks = LadUtil.getFeatureWideSinksFromLadCfg(ladCfg, 'performanceCounters')
        for table_name in local_tables:
            for aggregation_interval in intervals:
                if sinks:
                    local_table_name = ProvUtil.MakeUniqueEventName('aggregationLocal')
                    self._add_derived_event(aggregation_interval, table_name,
                                            local_table_name,
                                            'Local', add_lad_query=True)
                    self._handle_alternate_sinks(aggregation_interval, sinks, local_table_name)
                else:
                    self._add_derived_event(aggregation_interval, table_name,
                                            LadConfigAll._wad_table_name(aggregation_interval),
                                            'Central', add_lad_query=True)
    def _update_metric_collection_settings(self, ladCfg, namespaces):
        """
        Update mdsd_config_xml_tree for Azure Portal metric collection. This method builds the necessary aggregation queries
        that grind the ingested data and push it to the WADmetric table.
        :param ladCfg: ladCfg object from extension config
        :param namespaces: list of telegraf plugins sources obtained after parsing lad metrics config
        :return: None
        """

        # Aggregation is done by <LADQuery> within a <DerivedEvent>. If there are no alternate sinks, the DerivedQuery
        # can send output directly to the WAD metrics table. If there *are* alternate sinks, have the LADQuery send
        # output to a new local table, then arrange for additional derived queries to pull from that.

        intervals = LadUtil.getAggregationPeriodsFromLadCfg(ladCfg)
        sinks = LadUtil.getFeatureWideSinksFromLadCfg(ladCfg,
                                                      'performanceCounters')
        for plugin in namespaces:
            lad_specific_storage_plugin = "storage-" + plugin
            for aggregation_interval in intervals:
                if sinks:
                    local_table_name = ProvUtil.MakeUniqueEventName(
                        'aggregationLocal')
                    self._add_derived_event(aggregation_interval,
                                            lad_specific_storage_plugin,
                                            local_table_name,
                                            'Local',
                                            add_lad_query=True)
                    self._handle_alternate_sinks(aggregation_interval, sinks,
                                                 local_table_name)
                else:
                    self._add_derived_event(
                        aggregation_interval,
                        lad_specific_storage_plugin,
                        LadConfigAll._wad_table_name(aggregation_interval),
                        'Central',
                        add_lad_query=True)
 def test_getFeatureWideSinksFromLadCfg(self):
     self.assertEqual(LadUtil.getFeatureWideSinksFromLadCfg(self.valid_config, 'syslogEvents'), ['sink2'])
     self.assertEqual(LadUtil.getFeatureWideSinksFromLadCfg(self.valid_config, 'performanceCounters'), ['sink1'])