Beispiel #1
0
        public async Task IcmClientTestAsync()
        {
            Debugger.Launch();

            LoadApplicationKey().ThrowIfFailure();

            var config = new App.Monitor.Configuration();

            var clock = new MemoryClock();

            clock.Increment();

            var keyVault = new KeyVaultClient(
                config.KeyVaultUrl,
                config.KeyVaultCredentials.TenantId,
                config.KeyVaultCredentials.AppId,
                config.KeyVaultCredentials.AppKey,
                clock,
                cacheTimeToLive: TimeSpan.FromSeconds(1));

            keyVault.IcmCallsCounter.Value.Should().Be(0);

            // Simulate that the certificate has been acquired before.
            _ = await keyVault.GetCertificateAsync(config.IcmCertificateName);

            keyVault.IcmCallsCounter.Value.Should().Be(1);

            var icmClient = new IcmClient(keyVault, config.IcmUrl, config.IcmConnectorId, config.IcmCertificateName, clock);

            var incident = new IcmIncident(
                stamp: "Test",
                environment: "PROD",
                machines: new [] { "MachineA", "MachineB" },
                correlationIds: new[] { "GuidA", "GuidB" },
                severity: 4,
                description: "This incident was created for testing the cache monitor",
                title: "Cache Monitor Test Incident",
                incidentTime: DateTime.Now,
                cacheTimeToLive: null);

            await icmClient.EmitIncidentAsync(incident);

            // Should have used cached cert.
            keyVault.IcmCallsCounter.Value.Should().Be(1);

            // Simulate that the certificate will be acquired in the future.
            clock.AddSeconds(2);
            _ = await keyVault.GetCertificateAsync(config.IcmCertificateName);

            keyVault.IcmCallsCounter.Value.Should().Be(2);
        }
        protected Task EmitIcmAsync(
            int severity,
            string title,
            string stamp,
            IEnumerable <string>?machines,
            IEnumerable <string>?correlationIds,
            string?description       = null,
            DateTime?eventTimeUtc    = null,
            TimeSpan?cacheTimeToLive = null)
        {
            var incident = new IcmIncident(stamp, _configuration.Environment.ToString(), machines, correlationIds, severity, description ?? title, title, eventTimeUtc, cacheTimeToLive);

            return(_configuration.IcmClient.EmitIncidentAsync(incident));
        }
Beispiel #3
0
        protected Task EmitIcmAsync(
            int severity,
            string title,
            IEnumerable <string>?machines,
            IEnumerable <string>?correlationIds,
            string?description       = null,
            DateTime?eventTimeUtc    = null,
            TimeSpan?cacheTimeToLive = null)
        {
            // Do not create Sev3 or higher incidents for non-production environments
            if (!_configuration.Environment.IsProduction())
            {
                severity = Math.Max(severity, 4);
            }

            title = string.Concat($"[{_configuration.Environment}/{_configuration.Stamp}] ", title);

            var incident = new IcmIncident(_configuration.Stamp, _configuration.Environment.ToString(), machines, correlationIds, severity, description ?? title, title, eventTimeUtc, cacheTimeToLive);

            return(_configuration.IcmClient.EmitIncidentAsync(incident));
        }