-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide support for Azure Firewall (#2545)
Co-authored-by: Tom Kerkhove <kerkhove.tom@gmail.com>
- Loading branch information
1 parent
84c99e4
commit 880d10e
Showing
19 changed files
with
355 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Promitor.Agents.ResourceDiscovery/Graph/ResourceTypes/AzureFirewallDiscoveryQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using GuardNet; | ||
using Newtonsoft.Json.Linq; | ||
using Promitor.Core.Contracts; | ||
using Promitor.Core.Contracts.ResourceTypes; | ||
|
||
namespace Promitor.Agents.ResourceDiscovery.Graph.ResourceTypes | ||
{ | ||
public class AzureFirewallDiscoveryQuery : ResourceDiscoveryQuery | ||
{ | ||
public override string[] ResourceTypes => new[] { "microsoft.network/azurefirewalls" }; | ||
public override string[] ProjectedFieldNames => new[] { "subscriptionId", "resourceGroup", "name" }; | ||
|
||
public override AzureResourceDefinition ParseResults(JToken resultRowEntry) | ||
{ | ||
Guard.NotNull(resultRowEntry, nameof(resultRowEntry)); | ||
|
||
var azureFirewallName = resultRowEntry[2]?.ToString(); | ||
|
||
var resource = new AzureFirewallResourceDefinition(resultRowEntry[0]?.ToString(), resultRowEntry[1]?.ToString(), azureFirewallName); | ||
return resource; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...Agents.Scraper/Validation/MetricDefinitions/ResourceTypes/AzureFirewallMetricValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using GuardNet; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
using Promitor.Agents.Scraper.Validation.MetricDefinitions.Interfaces; | ||
using Promitor.Core.Contracts.ResourceTypes; | ||
|
||
namespace Promitor.Agents.Scraper.Validation.MetricDefinitions.ResourceTypes | ||
{ | ||
internal class AzureFirewallMetricValidator : IMetricValidator | ||
{ | ||
public IEnumerable<string> Validate(MetricDefinition metricDefinition) | ||
{ | ||
Guard.NotNull(metricDefinition, nameof(metricDefinition)); | ||
|
||
foreach (var resourceDefinition in metricDefinition.Resources.Cast<AzureFirewallResourceDefinition>()) | ||
{ | ||
if (string.IsNullOrWhiteSpace(resourceDefinition.AzureFirewallName)) | ||
{ | ||
yield return "No firewall name is configured"; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Promitor.Core.Contracts/ResourceTypes/AzureFirewallResourceDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Promitor.Core.Contracts.ResourceTypes | ||
{ | ||
public class AzureFirewallResourceDefinition : AzureResourceDefinition | ||
{ | ||
public AzureFirewallResourceDefinition(string subscriptionId, string resourceGroupName, string azureFirewallName) | ||
: base(ResourceType.AzureFirewall, subscriptionId, resourceGroupName, azureFirewallName) | ||
{ | ||
AzureFirewallName = azureFirewallName; | ||
} | ||
|
||
public string AzureFirewallName { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...re.Scraping/Configuration/Serialization/v1/Model/ResourceTypes/AzureFirewallResourceV1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes | ||
{ | ||
/// <summary> | ||
/// Contains the configuration required to scrape an Azure firewall. | ||
/// </summary> | ||
public class AzureFirewallResourceV1 : AzureResourceDefinitionV1 | ||
{ | ||
/// <summary> | ||
/// The name of the Azure firewall to get metrics for. | ||
/// </summary> | ||
public string AzureFirewallName { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...mitor.Core.Scraping/Configuration/Serialization/v1/Providers/AzureFirewallDeserializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; | ||
|
||
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Providers | ||
{ | ||
public class AzureFirewallDeserializer : ResourceDeserializer<AzureFirewallResourceV1> | ||
{ | ||
public AzureFirewallDeserializer(ILogger<AzureFirewallDeserializer> logger) : base(logger) | ||
{ | ||
Map(resource => resource.AzureFirewallName) | ||
.IsRequired(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Promitor.Core.Scraping/ResourceTypes/AzureFirewallScraper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Promitor.Core.Contracts; | ||
using Promitor.Core.Contracts.ResourceTypes; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
|
||
namespace Promitor.Core.Scraping.ResourceTypes | ||
{ | ||
internal class AzureFirewallScraper : AzureMonitorScraper<AzureFirewallResourceDefinition> | ||
{ | ||
private const string ResourceUriTemplate = "subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/azureFirewalls/{2}"; | ||
|
||
public AzureFirewallScraper(ScraperConfiguration scraperConfiguration) | ||
: base(scraperConfiguration) | ||
{ | ||
} | ||
|
||
protected override string BuildResourceUri(string subscriptionId, ScrapeDefinition<IAzureResourceDefinition> scrapeDefinition, AzureFirewallResourceDefinition resource) | ||
{ | ||
return string.Format(ResourceUriTemplate, subscriptionId, scrapeDefinition.ResourceGroupName, resource.AzureFirewallName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Promitor.Tests.Unit/Serialization/v1/Providers/AzureFirewallDeserializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
| ||
using System.ComponentModel; | ||
using Promitor.Core.Scraping.Configuration.Serialization; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Providers; | ||
using Xunit; | ||
|
||
namespace Promitor.Tests.Unit.Serialization.v1.Providers | ||
{ | ||
[Category("Unit")] | ||
public class AzureFirewallDeserializerTests : ResourceDeserializerTest<AzureFirewallDeserializer> | ||
{ | ||
private readonly AzureFirewallDeserializer _deserializer; | ||
|
||
public AzureFirewallDeserializerTests() | ||
{ | ||
_deserializer = new AzureFirewallDeserializer(Logger); | ||
} | ||
|
||
[Fact] | ||
public void Deserialize_AzureFirewallNameSupplied_SetsAzureFirewallName() | ||
{ | ||
YamlAssert.PropertySet<AzureFirewallResourceV1, AzureResourceDefinitionV1, string>( | ||
_deserializer, | ||
"azureFirewallName: promitor-firewall-name", | ||
"promitor-firewall-name", | ||
r => r.AzureFirewallName); | ||
} | ||
|
||
[Fact] | ||
public void Deserialize_AzureFirewallNameNotSupplied_Null() | ||
{ | ||
YamlAssert.PropertyNull<AzureFirewallResourceV1, AzureResourceDefinitionV1>( | ||
_deserializer, | ||
"resourceGroupName: promitor-group", | ||
r => r.AzureFirewallName); | ||
} | ||
|
||
protected override IDeserializer<AzureResourceDefinitionV1> CreateDeserializer() | ||
{ | ||
return new AzureFirewallDeserializer(Logger); | ||
} | ||
} | ||
} |
Oops, something went wrong.